#!/bin/bash #\ # \_ _ _ _ _ _ _ _ _ _ _ _ _ # #\ # # \ # disk usage monitoring # \ # script # / # # / # _ _ _ _ _ _ _ _ _ _ _ _ _#/ # / #/ # **** config section **** #do not touch as long as you're not me author="david@socialnerds.org" version="0.1" giturl="git://git.aec.at/mbots.git" configfile="/etc/mbots/mbots.conf" log2stdout="1" logwhat="mbots_diskmon" file="/etc/mbots/diskmon.lst" # **** preflight **** #read configfile if [ -r $configfile ]; then source $configfile else echo "ERROR: configfile not found. terminating." exit 1 fi #load bashlib if [ -d $bashlibpath ]; then source $bashlibpath/main source $bashlibpath/logengine log debug "preflight - logengine loaded" else echo "ERROR: bashlib not found. terminating." exit 1 fi #check environment log info "**** starting disk monitoring bot ****" #first option triggers custom list if [ -z $1 ]; then log debug "preflight - no custom list given. using $file[default]" else file=$1 log debug "preflight - list option given. using $file" fi # read file linecount="1" while read line; do #find first letter to determine if line is empty or a comment fletter=${line:0:1} #check for first letter if [ -z $fletter ]; then #skip line it's empty log debug "skipping line $linecount in $file: it's empty" elif [ $fletter = "#" ]; then #skip line it's a comment log debug "skipping line $linecount in $file: it's a comment" else #read line log debug "reading line $linecount in $file" #getting values disk=$(echo $line | awk '{print $1}') th1=$(echo $line | awk '{print $2}') #if threshold2 not given set th2 eq th1 th2=$(echo $line | awk '{print $3}') if [ -z $th2 ]; then th2=$th1 fi devstring=$(blkid | grep $disk | awk '{print $1}') uuidstring=$(blkid | grep $disk | awk '{print $2}') devname=$(echo ${devstring::$((${#devstring}-1))}) uuid=$(echo ${uuidstring:6:$((${#uuidstring}-7))}) #getting diskusage diskusage=$(df -hP --sync | grep $devname | awk '{print $5}') diskusage=$(echo ${diskusage::$((${#diskusage}-1))}) if [ $diskusage -gt $th2 ]; then #error, reached threshold2 log error "$devname uses $diskusage% of disk space (warn: $th1%, err: $th2%)" elif [ $diskusage -gt $th1 ]; then #warning, reached threshold1 log warning "$devname uses $diskusage% of disk space (warn: $th1%, err: $th2%)" else #info, everything ok log info "$devname is at $diskusage% (warn: $th1%, err: $th2%)" fi fi #linecount +1 let linecount++ #source file to read (diskmon.lst) done < $file #battlestar galactica fun section :-) log debug "adama: what do you hear starbuck?" log debug "kara: nothin' but the rain sir!" log info "**** disk monitoring bot finished ****" # **** end of script ****