2010-07-19 01:33:05 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2010-07-08 23:38:29 +02:00
|
|
|
###################################################
|
|
|
|
## ##
|
|
|
|
## disk_free jabber monitoring bot ##
|
|
|
|
## Author: david@socialnerds.org ##
|
|
|
|
## v0.2 ##
|
|
|
|
## ##
|
|
|
|
###################################################
|
|
|
|
|
2010-07-09 00:03:11 +02:00
|
|
|
## timestamp for logfile
|
|
|
|
timestamp=$(date '+%d %B %Y %H:%M')
|
|
|
|
echo "info: starting df bot $timestamp"
|
2010-07-08 23:38:29 +02:00
|
|
|
|
|
|
|
## 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/df.conf"
|
|
|
|
if [ -f $configfile ]; then
|
|
|
|
source $configfile
|
2010-07-01 18:08:47 +02:00
|
|
|
else
|
2010-07-08 23:38:29 +02:00
|
|
|
echo "error: no config file $configfile"
|
|
|
|
exit 1
|
2010-07-01 18:08:47 +02:00
|
|
|
fi
|
|
|
|
else
|
2010-07-08 23:38:29 +02:00
|
|
|
configfile=$1
|
|
|
|
if [ -f $configfile ]; then
|
|
|
|
source $configfile
|
|
|
|
else
|
|
|
|
echo "error: no config file $configfile"
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-07-01 18:08:47 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-07-08 23:38:29 +02:00
|
|
|
## check sendxmpp config
|
|
|
|
if [ -f ~/.sendxmpprc ]; then
|
|
|
|
echo "info: jabber config found in ~/.sendxmpprc"
|
2010-06-29 23:31:23 +02:00
|
|
|
else
|
2010-07-09 00:30:18 +02:00
|
|
|
|
|
|
|
if [ -z $port ]; then
|
|
|
|
port="5222"
|
|
|
|
else
|
|
|
|
echo "info: using port $port"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$user@$server:$port $pass" > ~/.sendxmpprc
|
2010-07-08 23:49:46 +02:00
|
|
|
chmod 600 ~/.sendxmpprc
|
2010-07-08 23:38:29 +02:00
|
|
|
echo "info: created sendxmpp config in ~/.sendxmpprc"
|
2010-06-29 23:31:23 +02:00
|
|
|
fi
|
|
|
|
|
2010-07-08 23:38:29 +02:00
|
|
|
|
2010-06-29 23:31:23 +02:00
|
|
|
## check disks
|
2010-06-30 23:58:23 +02:00
|
|
|
set -- $disks
|
|
|
|
i="1"
|
2010-06-29 23:31:23 +02:00
|
|
|
|
2010-06-30 23:58:23 +02:00
|
|
|
for var in "$@"
|
|
|
|
do
|
|
|
|
data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}')
|
|
|
|
datathreshold=$(echo $thresholds | awk '{print $'$i'}')
|
2010-06-29 23:31:23 +02:00
|
|
|
|
2010-06-30 23:58:23 +02:00
|
|
|
if [ $data -gt $datathreshold ]; then
|
2010-07-09 00:03:11 +02:00
|
|
|
echo "info: $var reached threshold with $data%, sending notification to $watchdogs"
|
|
|
|
echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs
|
2010-06-30 23:58:23 +02:00
|
|
|
fi
|
|
|
|
let i++
|
|
|
|
done
|
2010-06-29 23:31:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
## exiting
|
2010-07-09 00:03:11 +02:00
|
|
|
echo "info: done"
|
2010-06-29 23:31:23 +02:00
|
|
|
exit 0
|