Vedr.: monitor disk use whith no remote agent ???

Thomas Jens Lauritsen tjl at topdanmark.dk
Thu Jan 22 11:20:15 CET 2004


Dear Yohann,

I use SNMP to get disk space values. I have made a plugin called
check_diskspace.sh.

Here it is....I uses it for win2000 servers, but you should be able to
change it to any snmp system.

I have attached the plugin to this mail ...

#!/bin/sh
#
# check_diskspace.sh via SNMP
#
# Autor         : Thomas Jens Lauritsen <tjl at topdanmark.dk> + Other plugin
Authors
# Date          : 14 Jan 2004
# Version       : 1.0
# Description : Script that checks for free disk space in a server with
SNMP.
# Req.          : The script uses the bc - calulator (Installed on most
*nix's)
# Advice        : Run the script for every 60 min - to keep the load down
on the cpu.
# Nagios        : In the services.cfg. Exampel:
check_diskspace.sh!public!1!2!100!1000!
# Info          : You have to change Oid for your system - see below (num1
and num2).
#
#                                                     crit  warn
# ./check_diskspace.sh <ip-address> <public> <2> <2> <100> <1000>
#
# Verify that there is an input
# ------------------------------
#
if [ -z "$1" ]; then
echo "usage  : check_diskspace.sh <hostname> <snmp-community> <num1> <num2>
<crit-num3> <warn-num4>"
echo "example: check_diskspace.sh 192.168.1.1 public 2 2 100 1000"
echo
exit
fi
#

# Variables
# ---------
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
SERVER=$1                    # Example: 10.0.0.3
SNMPCOMUNITY=$2              # Example: public
NUM1=$3                      # Example: 2 (Drive C Storage Used)
NUM2=$4                      # Example: 2 (Drive C Storage Size/Capacity)
NUM3=$5                      # Example: "100"   (Mb) CRITICAL
NUM4=$6                      # Example: "1000"  (Mb) WARNING

# CHECK HOST
#snmpget -v 1 $SERVER -c public .system.sysUpTime.0

# GET STORAGE SIZE & USED VALUE (CHANGE THE OID's TO FIT YOUR DESTINATION
OS)

# Used disk value
USED=`/usr/bin/snmpget $SERVER $SNMPCOMUNITY
.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.$NUM1
 -t 5| awk '{ print $3  }'`
#echo $USED

# GET STORAGE SIZE AND USED VALUE (CHANGE THE OID's TO FIT YOUR DESTINATION
OS)
# Storage value
SIZE=`/usr/bin/snmpget $SERVER $SNMPCOMUNITY
.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize.$NUM1
 -t 5| awk '{ print $3  }'`
#echo $SIZE

# GET BYTE VALUE FOR DISK SYSTEM (512;1024;2048;4096)
#VALUE=`/usr/local/nagios/libexec/check_snmp -H $SERVER -o
.1.3.6.1.2.1.25.2.3.1.4.$NUM1 |awk '{ print $4  }'`
VALUE=`/usr/bin/snmpget $SERVER $SNMPCOMUNITY
.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageAllocationUnits.$NUM1
 -t 5 |awk '{ print $3  }'`
#/usr/bin/snmpget $SERVER $SNMPCOMUNITY .1.3.6.1.2.1.25.2.3.1.4.$3 |awk '{
print $4  }'>>/usr/local/nagios/libexec/$SERVER.txt
#echo $VALUE

# CALUCULATE FREE DISK SPACE
C=$((SIZE-USED))

#echo $C*$VALUE/1024/1024 | bc
>>/usr/local/nagios/libexec/$SERVER-$NUM1.txt
RESULT=`echo $C*$VALUE/1024/1024 | bc`
#echo $RESULT

if [ "$3" == "2" ] ; then
      DISKVOL=C
#      echo "$DISKVOL"

elif [ "$3" == "3" ] ; then
      DISKVOL=D
#      echo "$DISKVOL"

elif [ "$3" == "4" ] ; then
      DISKVOL=E
#      echo "$DISKVOL"
#      exit
fi

#echo DISK OK - $E MB

# TELL NAGIOS WHAT WE COLLECTED - AND GIVE IT A STATE
if [ "$RESULT" -lt "$NUM3" ] ; then
      $ECHO "DISKSPACE $DISKVOL - CRITICAL $RESULT MB\n"
      exitstatus=$STATE_CRITICAL

elif [ "$RESULT" -lt "$NUM4" ] ; then
      $ECHO "DISKSPACE $DISKVOL - WARNING $RESULT MB\n"
      exitstatus=$STATE_WARNING

elif [ "$RESULT" -gt "$NUM4" ] ; then
     $ECHO "DISKSPACE $DISKVOL - OK $RESULT MB\n"
      exitstatus=$STATE_OK

else
      $ECHO "DISKSPACE - UNKNOWN $RESULT MB\n"
      exitstatus=$STATE_UNKNOWN
fi

exit $exitstatus
# END OF DOC

(See attached file: check_diskspace.sh)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_diskspace.sh
Type: application/octet-stream
Size: 3557 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/users/attachments/20040122/d2a7fea5/attachment.obj>


More information about the Users mailing list