85 lines
1.9 KiB
Bash
85 lines
1.9 KiB
Bash
|
## ## ## ## ## ## ## ## ##
|
||
|
## ##
|
||
|
## jabber ping bot ##
|
||
|
## ##
|
||
|
## v0.1 ##
|
||
|
## ##
|
||
|
## author: david@socialnerds.org ##
|
||
|
## ##
|
||
|
## ## ## ## ## ## ## ## ##
|
||
|
|
||
|
|
||
|
## timestamp for logfile
|
||
|
timestamp=$(date '+%d %B %Y %H:%M')
|
||
|
echo "info: starting jabber ping bot $timestamp"
|
||
|
|
||
|
|
||
|
## check if sendxmpp is installed
|
||
|
if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then
|
||
|
echo "info: sendxmpp found"
|
||
|
else
|
||
|
if [ $(whoami) = "root" ]; then
|
||
|
apt-get install sendxmpp
|
||
|
else
|
||
|
echo "error: permission denied"
|
||
|
echo "info: install sendxmpp or run this scrip as superuser"
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
|
||
|
## set and load configfile
|
||
|
if [ -z $1 ]; then
|
||
|
configfile="/etc/mobots/ping.conf"
|
||
|
if [ -f $configfile ]; then
|
||
|
source $configfile
|
||
|
else
|
||
|
echo "error: no config file $configfile"
|
||
|
exit 1
|
||
|
fi
|
||
|
else
|
||
|
configfile=$1
|
||
|
if [ -f $configfile ]; then
|
||
|
source $configfile
|
||
|
else
|
||
|
echo "error: no config file $configfile"
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
|
||
|
## check sendxmpp config
|
||
|
if [ -f ~/.sendxmpprc ]; then
|
||
|
echo "info: jabber config found in ~/.sendxmpprc"
|
||
|
else
|
||
|
|
||
|
if [ -z $port ]; then
|
||
|
port="5222"
|
||
|
else
|
||
|
echo "info: using port $port"
|
||
|
fi
|
||
|
|
||
|
echo "$user@$server:$port $pass" > ~/.sendxmpprc
|
||
|
chmod 600 ~/.sendxmpprc
|
||
|
echo "info: created sendxmpp config in ~/.sendxmpprc"
|
||
|
fi
|
||
|
|
||
|
## run the actual ping
|
||
|
set -- $dest
|
||
|
|
||
|
for var in "$@"
|
||
|
do
|
||
|
data=$(ping -c 05 $var | grep transmitted | awk '{print $4}')
|
||
|
if [ $data -lt 4 ]; then
|
||
|
echo "alert: $var is unreachable"
|
||
|
echo "alert: $var is unreachable" | sendxmpp -r $res $watchdogs
|
||
|
else
|
||
|
echo "info: $var is reachable"
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
|
||
|
## the end
|
||
|
exit 0
|
||
|
|