Monitoring NTFS diskspace with Nagios
Posted on 17 april 2012 | Category :Nieuws | Geen reacties op Monitoring NTFS diskspace with Nagios
After struggling for a while on how to get alerts from nagios when the diskspace on a Microsoft Windows server runs low, i decided to write a simple shell script.
Requirements:
- A server running linux with Nagios installed (tested on Ubuntu 10.4.3 LTS with Nagios 3.3.1)
- snmputils installed (the script uses snmpwalk and snmpget)
Code:
#!/bin/sh # Syntax: check_snmp_diskspace# Verify parameters if [ -z "$5" ]; then echo "Syntax: check_snmp_diskspace " echo "Example: check_snmp_diskspace 10.0.0.1 public C: 100 1000" exit fi # Variables STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 SERVER=$1 COMUNITY=$2 VOLUME=$3 CRITLEVEL=$4 WARNLEVEL=$5 exitstatus=$STATE_CRITICAL # Get logical diskname name of the volume VOLNUM=`/usr/bin/snmpwalk -c $COMUNITY -v 1 $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageDescr -t 5 | grep $VOLUME | awk '{print $1}' | sed "s/HOST-RESOURCES-MIB::hrStorageDesc..//g" ` # Get the size of the diskspace allready in use USED=`/usr/bin/snmpget -c $COMUNITY -v 1 $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.$VOLNUM | awk '{ print $4 }'` # Get the volume size SIZE=`/usr/bin/snmpget -c $COMUNITY -v 1 $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize.$VOLNUM | awk '{ print $4 }'` # Get byte value of the volume VALUE=`/usr/bin/snmpget -c $COMUNITY -v 1 $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageAllocationUnits.$VOLNUM | awk '{ print $4 }'` # Calculate free disk space C=$((SIZE-USED)) RESULT=`echo $C*$VALUE/1024/1024 | bc` #echo "Disk size: $SIZE" #echo "Disk space used: $USED" #echo "AllocationUnits: $VALUE" #echo "Free disk space: $SIZE - $USED = $RESULT MB" if [ "$RESULT" -le "$CRITLEVEL" ] ; then echo "DISKSPACE CRITICAL - "$VOLUME" $RESULT MB" exitstats=$STATE_CRITICAL elif [ "$RESULT" -le "$WARNLEVEL" ] ; then echo "DISKSPACE WARNING - "$VOLUME" $RESULT MB" exitstatus=$STATE_WARNING elif [ "$RESULT" -ge "$WARNLEVEL" ] ; then echo "DISKSPACE OK - "$VOLUME" $RESULT MB" exitstatus=$STATE_OK else echo "DISKSPACE UNKNOWN - "$VOLUME" $RESULT MB" exitstatus=$STATE_UNKNOWN fi exit $exitstatus
checkcommands.cfg:
define command{ command_name check_ntfs_diskspace command_line /usr/local/nagios/libexec/check_ntfs_diskspace $HOSTADDRESS$ public $ARG1$ $ARG2$ $ARG3$ }
service configuration:
define host{ host_name server1 alias Example server 1 address the.ip.address } define service{ host_name server1 service_description DISKSPACE check_command check_ntfs_diskspace!C:!1000!5000 }
Comments 0