snmp disk plads.

From: Lasse Bo Larsen (none@lbl--unoc.dk.lh.bsd-dk.dk)
Date: Fri 06 Nov 2009 - 00:39:54 CET


Date: Fri, 6 Nov 2009 00:39:54 +0100
Subject: snmp disk plads.
From: Lasse Bo Larsen <none@lbl--unoc.dk.lh.bsd-dk.dk>
To: bsd-dk@bsd-dk.dk

Hej BSD-DK

Jeg er ikke helt sikker på at jeg udregner disk pladsen korrekt her
... den afviger rimelig meget fra df ...

Nogle bud ?

/lbl

[lbl@atom2 ~]$ 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@atom2 ~]$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/mirror/satas1a 496M 265M 191M 58% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/mirror/satas1e 496M 64K 456M 0% /tmp
/dev/mirror/satas1f 443G 112G 296G 27% /usr
/dev/mirror/satas1d 2.9G 1.2G 1.5G 45% /var
[lbl@atom2 ~]$ df
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/mirror/satas1a 507630 271786 195234 58% /
devfs 1 1 0 100% /dev
/dev/mirror/satas1e 507630 64 466956 0% /tmp
/dev/mirror/satas1f 464971160 117498790 310274678 27% /usr
/dev/mirror/satas1d 3017358 1237820 1538150 45% /var
[lbl@atom2 ~]$ ./check_snmp_disk localhost public / 100
DISK OK: mount / free 230 MB.
[lbl@atom2 ~]$ ./check_snmp_disk localhost public /tmp 100
DISK OK: mount /tmp free 495 MB.
[lbl@atom2 ~]$ ./check_snmp_disk localhost public /usr 100
DISK OK: mount /usr free 339328 MB.
[lbl@atom2 ~]$ ./check_snmp_disk localhost public /var 100
DISK OK: mount /var free 1737 MB.
[lbl@atom2 ~]$



This archive was generated by hypermail 2b30 : Mon 30 Nov 2009 - 23:00:01 CET