Hi
I think i need some fresh eyes on this one, im trying to calculate the free disk space via snmp (net-snmp)
But it seems to be way off and im not shure why ...
Any clues ?
/lbl
I think i need some fresh eyes on this one, im trying to calculate the free disk space via snmp (net-snmp)
But it seems to be way off and im not shure why ...
Any clues ?
/lbl
Code:
[lbl@atom1 ~]$ cat check_snmp_disk
#!/usr/local/bin/bash
# This script takes:
# <host> <community> <mountpoint> <megs>
snmpwalk="/usr/local/bin/snmpwalk"
snmpget="/usr/local/bin/snmpget"
calc_free()
# takes <size> <used> <allocation>
{
echo "$1 $2 - $3 * 1024 / 1024 / p" | dc
}
if result=`$snmpwalk -v2c -c $2 -Oq $1 hrStorageDescr | grep "$3$"`
then
index=`echo $result | sed 's/.*hrStorageDescr//' | sed 's/ .*//'`
args=`$snmpget -v2c -c $2 -Oqv $1 hrStorageSize$index hrStorageUsed$index hrStorageAllocationUnits$index | while read oid j ; do printf " $oid" ; done`
free=`calc_free$args`
if [ "$free" -gt "$4" ]
then
echo "DISK OK: mount $3 free $free MB."
exit 0
else
echo "DISK CRITICAL: mount $3 free $free MB."
exit 2
fi
else
echo "DISK CRITICAL: $3 dosent exist or snmp isent responding."
exit 3
fi
[lbl@atom1 ~]$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/mirror/ides1a 496M 236M 221M 52% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/mirror/ides1e 496M 1.4M 455M 0% /tmp
/dev/mirror/ides1f 103G 3.6G 91G 4% /usr
/dev/mirror/ides1d 2.9G 1.8G 860M 68% /var
/dev/raid3/sata0 1.8T 1.6T 61G 96% /storage/download
/dev/raid3/sata1 1.8T 911G 749G 55% /storage/pub
devfs 1.0K 1.0K 0B 100% /var/named/dev
[lbl@atom1 ~]$ df
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/mirror/ides1a 507630 241164 225856 52% /
devfs 1 1 0 100% /dev
/dev/mirror/ides1e 507630 1480 465540 0% /tmp
/dev/mirror/ides1f 108230294 3783806 95788066 4% /usr
/dev/mirror/ides1d 3017358 1895590 880380 68% /var
/dev/raid3/sata0 1892045722 1676425126 64256940 96% /storage/download
/dev/raid3/sata1 1892045722 955594880 785087186 55% /storage/pub
devfs 1 1 0 100% /var/named/dev
[lbl@atom1 ~]$ ./check_snmp_disk localhost public / 100
DISK OK: mount / free 260 MB.
[lbl@atom1 ~]$ ./check_snmp_disk localhost public /tmp 100
DISK OK: mount /tmp free 494 MB.
[lbl@atom1 ~]$ ./check_snmp_disk localhost public /usr 100
DISK OK: mount /usr free 101998 MB.
[lbl@atom1 ~]$ ./check_snmp_disk localhost public /var 100
DISK OK: mount /var free 1095 MB.
[lbl@atom1 ~]$ ./check_snmp_disk localhost public /storage/download 100
DISK OK: mount /storage/download free 210566 MB.
[lbl@atom1 ~]$ ./check_snmp_disk localhost public /storage/pub 100
DISK OK: mount /storage/pub free 914502 MB.
[lbl@atom1 ~]$