121 lines
2.6 KiB
Bash
121 lines
2.6 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
|
||
|
###################################################
|
||
|
## ##
|
||
|
## disk_free monitoring bot ##
|
||
|
## ##
|
||
|
###################################################
|
||
|
|
||
|
|
||
|
# **** in script config section ****
|
||
|
version="0.3_alpha"
|
||
|
author="david@socialnerds.org"
|
||
|
logwhat="df_bot"
|
||
|
|
||
|
# **** configfile section ****
|
||
|
disks="sda1"
|
||
|
thresholds="90"
|
||
|
bashlibpath="/home/david/Documents/code/bashlib"
|
||
|
# logging
|
||
|
loglevel="4"
|
||
|
log2syslog="1"
|
||
|
log2file="0"
|
||
|
#logfile="/var/log/mbots.log"
|
||
|
log2stdout="1"
|
||
|
|
||
|
|
||
|
# **** bash trap initialisation ****
|
||
|
trap bashtrap INT
|
||
|
|
||
|
# **** load bashlib ****
|
||
|
if [ -d $bashlibpath ]; then
|
||
|
source $bashlibpath/main
|
||
|
#source $bashlibpath/update
|
||
|
source $bashlibpath/logengine
|
||
|
log debug "preflight - bashlib loaded"
|
||
|
else
|
||
|
echo "ERROR: bashlib not found"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
exit 0
|
||
|
## timestamp for logfile
|
||
|
#timestamp=$(date '+%d %B %Y %H:%M')
|
||
|
#echo "info: starting df 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/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
|
||
|
#
|
||
|
# 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
|
||
|
|
||
|
|
||
|
## 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 to $watchdogs"
|
||
|
echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs
|
||
|
fi
|
||
|
let i++
|
||
|
done
|
||
|
|
||
|
|
||
|
## exiting
|
||
|
#echo "info: done"
|
||
|
|
||
|
|
||
|
exit 0
|
||
|
# **** end of script ****
|