released v0.2 of df.sh
This commit is contained in:
parent
46e98f68c2
commit
2c6d536c15
66
mobots/df.sh
66
mobots/df.sh
|
@ -1,35 +1,55 @@
|
|||
#########################################
|
||||
## disk_free jabber monitoring bot ##
|
||||
## Author: david@socialnerds.org ##
|
||||
## v0.1 ##
|
||||
#########################################
|
||||
###################################################
|
||||
## ##
|
||||
## disk_free jabber monitoring bot ##
|
||||
## Author: david@socialnerds.org ##
|
||||
## v0.2 ##
|
||||
## ##
|
||||
###################################################
|
||||
|
||||
## configuration section (does a simple check if the configfile exists)
|
||||
configfilepath=$(pwd)
|
||||
logfile="df.log"
|
||||
logfilepath="/var/log/mobots"
|
||||
|
||||
if [ "$(whoami)" = "root" ]; then
|
||||
## check if logfile/path exists
|
||||
if [ -f $logfilepath/$logfile ]; then
|
||||
echo "Starting up df mbot script" >> $logfilepath/$logfile
|
||||
## 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
|
||||
mkdir -p $logfilepath
|
||||
touch $logfilepath/$logfile
|
||||
echo "Starting up df mbot script" >> $logfilepath/$logfile
|
||||
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
|
||||
echo "Starting up df mbot script w/o logfile."
|
||||
configfile=$1
|
||||
if [ -f $configfile ]; then
|
||||
source $configfile
|
||||
else
|
||||
echo "error: no config file $configfile"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ -f $configfilepath/df.conf ]; then
|
||||
source $configfilepath/df.conf
|
||||
## check sendxmpp config
|
||||
if [ -f ~/.sendxmpprc ]; then
|
||||
echo "info: jabber config found in ~/.sendxmpprc"
|
||||
else
|
||||
echo "Exiting because there is no config file."
|
||||
exit 1
|
||||
echo "$user@$server $pass" > ~/.sendxmpprc
|
||||
echo "info: created sendxmpp config in ~/.sendxmpprc"
|
||||
fi
|
||||
|
||||
|
||||
## check disks
|
||||
set -- $disks
|
||||
i="1"
|
||||
|
@ -40,9 +60,9 @@ do
|
|||
datathreshold=$(echo $thresholds | awk '{print $'$i'}')
|
||||
|
||||
if [ $data -gt $datathreshold ]; then
|
||||
echo "$hostname -- $var is running out of space: $data%" | sendxmpp -r dfmobot -u $user -j $server -p $pass $watchdogs
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue