磁盘监控报警-nagios

#!/bin/sh

#define alert devel of nagios
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKOWN=3
above=0

list=`df -h|grep -v "Filesystem"|grep -v "devfs"|awk '{print $6}'`

for disk_name in $list;do
        url=`df -h|grep $disk_name`
        size=`echo $url|awk -F\  '{print "size:" $2}'`;
        used=`echo $url|awk -F\  '{print "used:" $3}'`;
        avail=`echo $url|awk -F\  '{print "avail:" $4}'`;
        capacity=`echo $url|awk -F\  '{print $5}'`;
        mounted=`echo $url|awk -F\  '{print "mounted:" $6}'`;
 
        percent=`echo $capacity |sed 's/%//g'`
           #echo $percent
                #echo -e $size $used $avail "capacity:"$capacity $mounted
         if [ "$percent" -ge 70 ];then
                above=1
                echo "the disk $mounted space used above 70%"
                echo $size $used $avail "capacity:"$capacity $mounted
                exit $STATE_WARNING
         else
                above=0
         fi
done;

if [ "$above" -eq 0 ];then
         echo "the disk used of space normal"
         exit $STATE_OK
else
         echo "the disk used state unkonw"
         exit $STATE_CRITICAL
fi


你可能感兴趣的:(list,url,disk,磁盘)