#!/usr/bin/local_perl # Dont use the embedded apache perl.... # Author : Peter # Date : Apr 11 2006 # check_winmem IP COMMUNITY warnlevel criticallevel sub print_usage { print " ############################## check_winmem ############################### # Version : 1.0 # Date : Apr 11 2006 # Author : Peter Stimpel # Thanks to Benjamin Jakubowski for the idea to walk through snmp # Help : http://www.peters-webcorner.de/nagios/ # Licence : GPL - http://www.fsf.org/licenses/gpl.txt #######################################################################\n"; print "check_winmem IP COMMUNITY warnlevel criticallevel\n"; print"\ncheck_winmem -v for version info\n"; } $PROGNAME = "check_winmem"; if (@ARGV[0] eq "-v") { print_usage(); exit 0; } if ( @ARGV[0] eq "" || @ARGV[1] eq "" || @ARGV[2] eq "" || @ARGV[3] eq "") { print_usage(); exit 0; } $IP=@ARGV[0]; $COMMUNITY=@ARGV[1]; $Service=@ARGV[2]; $LW=@ARGV[4]; $resultat =`snmpwalk -v 1 -c $COMMUNITY $IP hrSWRunPerfMem `; $fullsize1=0; $usedsize1=0; $unitused=""; $unitfull=""; $percuse=0; if ( $resultat ) { $resstring= $resultat; @res=split(/\n/,$resstring); foreach $resu (@res) { $resstr = $resu; if ($resu = ~/hrSWRunPerfMem/) { @outs = split(/ /, $resstr); $usedsize1 = $usedsize1 + $outs[3]; chomp($outs[4]); $unitused=$outs[4]; } } $resultat2 =`snmpwalk -v 1 -c $COMMUNITY $IP hrMemorySize `; $resstr=$resultat2; if ($resu = ~/hrMemorySize/) { @outs = split(/ /, $resstr); $fullsize1 = $outs[3]; chomp($outs[4]); $unitfull=$outs[4]; } if ($fullsize1 > 0 && $usedsize1 > 0) { $percuse = $usedsize1 * 100 / $fullsize1; $percuse = sprintf("%.2f",$percuse); if ($percuse >= @ARGV[3]) { print "CRITICAL MEM: usage $percuse perc - $usedsize1 $ unitused of $fullsize1 $unitfull -w $ARGV[2] -c $ARGV[3]\n"; exit 2; } if ($percuse >= @ARGV[2]) { print "WARN MEM: usage $percuse perc - $usedsize1 $ unitused of $fullsize1 $unitfull -w $ARGV[2] -c $ARGV[3]\n"; exit 1; } print "OK MEM: usage $percuse perc - $usedsize1 $ unitused of $fullsize1 $unitfull -w $ARGV[2] -c $ARGV[3]\n"; exit 0; } print "Critical : Response unknown\n"; exit 2; } else { print "Critical : no response\n"; exit 2; }