1
1
scripts/mobots/df.sh

72 lines
1.7 KiB
Bash
Executable File

###################################################
## ##
## disk_free jabber monitoring bot ##
## Author: david@socialnerds.org ##
## v0.2 ##
## ##
###################################################
## 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
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
echo "$user@$server $pass" > ~/.sendxmpprc
echo "info: created sendxmpp config in ~/.sendxmpprc"
fi
## check disks
set -- $disks
i="1"
for var in "$@"
do
data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}')
datathreshold=$(echo $thresholds | awk '{print $'$i'}')
if [ $data -gt $datathreshold ]; then
echo "info: $var reached threshold with $data, sending notification"
echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfmobot $watchdogs
fi
let i++
done
## exiting
exit 0