added pingbot to mobots
This commit is contained in:
parent
434a585e82
commit
c638cea2d5
|
@ -0,0 +1,12 @@
|
|||
# a whitespace seperated list of ip addresses or fqdnames
|
||||
dest="192.168.1.13 somemachine.example.com"
|
||||
|
||||
# jabber configuration
|
||||
user="jid"
|
||||
server="jabber-server"
|
||||
#port="" ## if you want to use a special port (default: 5222)
|
||||
pass="jabber-password"
|
||||
res="pingbot"
|
||||
watchdogs="someuser@jabber.example.com anotheruser@example.com" ## whitespace seperated list of JIDs
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
## ## ## ## ## ## ## ## ##
|
||||
## ##
|
||||
## 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
|
||||
|
Loading…
Reference in New Issue