Nagios returns service did not exit properly

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
VisRyanWilliams
Posts: 8
Joined: Mon Apr 14, 2014 8:57 am

Nagios returns service did not exit properly

Post by VisRyanWilliams »

I have a Nagios install which is working perfectly. Now I am a bit of a Nagios noob and not very good with my Linux commands but I have attempted to add a plugin to check disk space via snmp. The script I am using is called "win_check_snmp_disk.pl" which I obtained from Nagios Exchange. I have added this script in and created the command definition and service definition but the script returns a Nagios value of "Service check did not exit properly" and I am banning my head against a wall on how to solve so any help would be appreciated

Script Details

Code: Select all

#!/usr/bin/perl
# Enhanced by: Anatoly Rabkin
# Date: 27/07/2009
# Based on original script:
# Author: Dan Capper
# Date: 13/11/2007
# check_win_snmp_disk.pl [address] [community-name] [logical disk] [warn-level] [critical-level]
# Based on original script:
# Author : jakubowski Benjamin
# Date : 19/12/2005
# check_win_snmp_disk.pl SERVEUR COMMUNITY

# ------------ "Nearest" routines (round to a multiple of any number)
# Copied from Math::Round on cpan.org
# Math::Round was written by Geoffrey Rommel GROMMEL@cpan.org in October 2000.

sub nearest {
 my ($targ, @inputs) = @_;
 my @res = ();
 my $x;

 $targ = abs($targ) if $targ < 0;
 foreach $x (@inputs) {
   if ($x >= 0) {
      push @res, $targ * int(($x + $half * $targ) / $targ);
   } else {
      push @res, $targ * POSIX::ceil(($x - $half * $targ) / $targ);
   }
 }
 return (wantarray) ? @res : $res[0];
}

$STATE_OK = 0;
$STATE_WARNING = 1;
$STATE_CRITICAL = 2;
$STATE_UNKNOWN=3;
#$STATE_UNKNOWN = 255;

# IEC Multipliers
$TEBI = 1099511627776;
$GIBI = 1073741824;
$MEBI = 1048576;
$KIBI = 1024;

$snmpwalk=`which snmpwalk`;
chomp($snmpwalk);
$snmpget=`which snmpget`;
chomp($snmpget);
$snmpstatus=`which snmpstatus`;
chomp($snmpstatus);

#print "SNMPWALK: '$snmpwalk'\n";

if ($#ARGV + 1 < 4) {
        print "Enhanced check_win_snmp_disk.pl by Dan Capper based on original script by jakubowski Benjamin\n";
        print "Reports disk usage of Windows systems via snmp to nagios\n";
        print "\n";
        print "usage:\n";
        print "check_win_snmp_disk.pl <address> <community-name> <warn-level> <critical-level>\n";
        print "Where:\n";
        print "[address]        = ip address or name of server to check\n";
        print "[community-name] = SNMP community name with at least READ ONLY rights to server\n";
        print "[warn-level]     = Percentage full before return warning level to nagios\n";
        print "[critical-level] = Percentage full before return critical level to nagios\n";
        print "For example the command:\n";
        print "./check_win_snmp_disk.pl 10.0.0.10 public 80 90\n";
        print "Will check disk All disks ('C:', 'D:' etc.) on the server at '10.0.0.10' using snmp community name 'public'. Warn at 80% full, Critical at 90% full\n";
        exit $STATE_UNKNOWN;
}

if (@ARGV[0] =~ m/((\d{1,3}\.){3}\d{1,3})|(\w+)/) {
        $SERVER = @ARGV[0];
        $TEST=`$snmpstatus -v 1 $SERVER -c public -t 5 -r 0 2>&1`;
        chomp($TEST);
        #print "Test:\n$TEST\n";
        if ( ( $TEST =~ /Timeout: No Response from/ ) || ( $? > 0 ) ){
                print "SNMP to $SERVER is not available\n";
                print "Check command: '$snmpstatus -v 1 $SERVER -c public -t 5 -r 0'\n";
                print "Result: $TEST\n";
                exit $STATE_UNKNOWN;
        }
        if ( $TEST !~ /windows/i ){
                print "This host is not a WINDOWS machine!!!!\n";
                exit $STATE_UNKNOWN;
        }
} else {
        print "ERROR: address argument not in correct format\n";
        print "Execute with no parameters to see usage information\n";
        exit $STATE_UNKNOWN;
}

if (@ARGV[1] =~ m/\w+/) {
        $COMMUNITYNAME=@ARGV[1];
} else {
        print "ERROR: community-name argument not in correct format\n";
        print "Execute with no parameters to see usage information\n";
        exit $STATE_UNKNOWN;
}

#if (@ARGV[2] =~ m/\d{1,2}/) {
#       $LDISK=@ARGV[2];
#} else {
#       print "ERROR: logical disk argument not in correct format\n";
#       print "Execute with no parameters to see usage information\n";
#       exit $STATE_UNKNOWN;
#}

if (@ARGV[3] =~ m/\d{1,3}/ and @ARGV[3] <= 100) {
        $CRITICAL=@ARGV[3];
} else {
        print "ERROR: critical argument not in correct format\n";
        print "critical level must no more than 100\n";
        print "Execute with no parameters to see usage information\n";
        exit $STATE_UNKNOWN;
}

if (@ARGV[2] =~ m/\d{1,3}/ and @ARGV[2] <= 100 and @ARGV[2] <= $CRITICAL) {
        $WARN=@ARGV[2];
} else {
        print "ERROR: warning-level argument not in correct format\n";
        print "warning-level must no more than 100 and less than critical level\n";
        print "Execute with no parameters to see usage information\n";
        exit $STATE_UNKNOWN;
}

$THRESHOLDS="(WARN: $WARN% / CRIT: $CRITICAL%)";
$OUTPUT="";
$LONGOUTPUT="";
$PCTUSED=0;
$EXIT_CODE=0;
# Used Space
@LDISKS=`$snmpwalk -v 1 -c $COMMUNITYNAME $SERVER hrStorageDescr | grep "Serial Number" | awk '{print \$1}' | awk -F. '{print \$2}'`;
@LDISKS=grep(s/\n//, @LDISKS);

foreach $LDISK (@LDISKS){
        $DISKNAME=`snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageDescr.$LDISK -t 5 | awk -F: '{print \$4}'`;
        $DISKNAME =~ s/ //g;
        $DISKNAME =~ s/\n//g;

        if ($DISKNAME =~ m/\d+/ ) {
                print "ERROR : Unexpected result from snmpget - Wrong Disk name: '$DISKNAME'.\n";
                exit $STATE_UNKNOWN;
        }

        $RAWUSED=`$snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.$LDISK -t 5| awk '{ print \$4 }'`;
        $RAWUSED =~ s/\n//g;
        if ($RAWUSED !~ m/\d+/) {
                print "ERROR : Unexpected result from snmpget\n";
                exit $STATE_UNKNOWN;
        }

        # Size of disk
        $RAWSIZE=`$snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize.$LDISK -t 5| awk '{ print  \$4  }'`;
        $RAWSIZE =~ s/\n//g;
        if ($RAWSIZE !~ m/\d+/) {
                print "ERROR : Unexpected result from snmpget\n";
                exit $STATE_UNKNOWN;
        }

        # GET BYTE VALUE FOR DISK SYSTEM (512;1024;2048;4096)
        $VALUE=`$snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageAllocationUnits.$LDISK -t 5 | awk '{ print \$4 }'`;

        $VALUE =~ s/\n//g;
        if ($VALUE !~ m/\d+/) {
                print "ERROR : Unexpected result from snmpget\n";
                exit $STATE_UNKNOWN;
        }

        # Calculate percentage used

        SWITCH: {
                if ($RAWSIZE > 0)               { $PERCENTUSED = nearest(.1, $RAWUSED/$RAWSIZE * 100); last SWITCH; };
                $PERCENTUSED = 0;
        }

        # Calculate human-readable total space

        SWITCH: {
                if ($RAWSIZE * $VALUE >= $TEBI)         { $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($TEBI)); $TOTALUNITS = "TiB"; last SWITCH; };
                if ($RAWSIZE * $VALUE >= $GIBI)         { $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($GIBI)); $TOTALUNITS = "GiB"; last SWITCH; };
                if ($RAWSIZE * $VALUE >= $MEBI)         { $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($MEBI)); $TOTALUNITS = "MiB"; last SWITCH; };
                if ($RAWSIZE * $VALUE >= $KIBI)         { $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($KIBI)); $TOTALUNITS = "KiB"; last SWITCH; };
                if ($RAWSIZE > 0)                       { $TOTAL = nearest(.1, $RAWTOTAL * $VALUE); $TOTALUNITS = "B"; last SWITCH; };
                $TOTAL = 0;
        }

        # Calculate human-readable used space

        SWITCH: {
                if ($RAWUSED * $VALUE >= $TEBI) { $USED = nearest(.1, $RAWUSED * $VALUE/($TEBI)); $USEDUNITS = "TiB"; last SWITCH; };
                if ($RAWUSED * $VALUE >= $GIBI) { $USED = nearest(.1, $RAWUSED * $VALUE/($GIBI)); $USEDUNITS = "GiB"; last SWITCH; };
                if ($RAWUSED * $VALUE >= $MEBI) { $USED = nearest(.1, $RAWUSED * $VALUE/($MEBI)); $USEDUNITS = "MiB"; last SWITCH; };
                if ($RAWUSED * $VALUE >= $KIBI) { $USED = nearest(.1, $RAWUSED * $VALUE/($KIBI)); $USEDUNITS = "KiB"; last SWITCH; };
                if ($RAWUSED * $VALUE > 0)              { $USED = nearest(.1, $RAWUSED * $VALUE); $USEDUNITS = "B"; last SWITCH; };
                $USED = 0;
        }

        # Calculate Free Space

        $RAWFREE=$RAWSIZE-$RAWUSED;

        # Calculate human-readable free space

        SWITCH: {
                if ($RAWFREE * $VALUE >= $TEBI) { $FREE = nearest(.1, $RAWFREE * $VALUE/($TEBI)); $FREEUNITS = "TiB"; last SWITCH; };
                if ($RAWFREE * $VALUE >= $GIBI) { $FREE = nearest(.1, $RAWFREE * $VALUE/($GIBI)); $FREEUNITS = "GiB"; last SWITCH; };
                if ($RAWFREE * $VALUE >= $MEBI) { $FREE = nearest(.1, $RAWFREE * $VALUE/($MEBI)); $FREEUNITS = "MiB"; last SWITCH; };
                if ($RAWFREE * $VALUE >= $KIBI) { $FREE = nearest(.1, $RAWFREE * $VALUE/($KIBI)); $FREEUNITS = "KiB"; last SWITCH; };
                if ($RAWFREE > 0)               { $FREE = nearest(.1, $RAWFREE * $VALUE); $FREEUNITS = "B"; last SWITCH; };
                $FREE = 0;
        }

        if ( $PERCENTUSED < $WARN ) {
                #print "OK : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                $LONGOUTPUT.="DISK: $DISKNAME(id: $LDISK) - OK : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                if ( ! $EXIT_CODE ){
                        $OUTPUT="DISK: $DISKNAME - OK : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                }
                #exit $STATE_OK;
                next;
        }

        if ( $PERCENTUSED < $CRITICAL ) {
                #print "WARNING : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                $LONGOUTPUT.="DISK: $DISKNAME(id: $LDISK) - WARNING : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                if ( $EXIT_CODE < $STATE_WARNING ){
                        if ( $PCTUSED <= $PERCENTUSED ){
                                $OUTPUT="DISK: $DISKNAME - WARNING : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                                $PCTUSED=$PERCENTUSED;
                        }
                        $EXIT_CODE=$STATE_WARNING;
                }
                #exit $STATE_WARNING;
                next;
        }

        if ( $PERCENTUSED >= $CRITICAL ) {
                #print "CRITICAL : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                $LONGOUTPUT.="DISK: $DISKNAME(id: $LDISK) - CRITICAL : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                if ( $EXIT_CODE <= $STATE_CRITICAL ){
                        if ( $PCTUSED < $PERCENTUSED ){
                                $OUTPUT="DISK: $DISKNAME - CRITICAL : Percent Used : $PERCENTUSED% $THRESHOLDS, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
                                $PCTUSED=$PERCENTUSED;
                        }
                        $EXIT_CODE=$STATE_CRITICAL;
                }
                #exit $STATE_CRITICAL;
        }
}#foreach
#print "ERROR : Unexpected Results : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n";
#exit $STATE_UNKNOWN;

print "$OUTPUT";
print "$LONGOUTPUT";
exit $EXIT_CODE;;
Command Details
define command {
command_name win_check_snmp_disk
command_line /usr/lib/nagios/plugins/added/win_check_snmp_disk.pl $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
}

Service Details
define service {
use generic-service
#hostgroup_name all
hostgroup_name netbios-ssn
service_description Windows-Check-Disk
check_command win_check_snmp_disk!public!90!95
#use generic-service
notification_interval 0 ; set > 0 if you want to be renotified
}

Mod Note: Please wrap your code in code tags!
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Nagios returns service did not exit properly

Post by sreinhardt »

What output do you get from the following commands?

Code: Select all

/usr/lib/nagios/plugins/added/win_check_snmp_disk.pl $HOSTADDRESS$ public 90 95
echo $?
From a quick peek, it looks like your code is fine, but it's hard to say.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
VisRyanWilliams
Posts: 8
Joined: Mon Apr 14, 2014 8:57 am

Re: Nagios returns service did not exit properly

Post by VisRyanWilliams »

Hi so I browsed to the location and then run the command and below is the following results

VSHMON41:/usr/lib/nagios/plugins/added# ls
win_check_snmp_disk.pl
VSHMON41:/usr/lib/nagios/plugins/added# /usr/lib/nagios/plugins/added/win_check_snmp_disk.pl $HOSTADDRESS$ public 90 95
ERROR: address argument not in correct format
Execute with no parameters to see usage information
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios returns service did not exit properly

Post by lmiltchev »

I believe you have your plugin's name wrong. You should be running "check_win_snmp_disk.pl", not "win_check_snmp_disk.pl". What is the output, when you run the following command from the plugins directory?

Code: Select all

./check_win_snmp_disk.pl -h
You need to be running something like the following:

Code: Select all

./check_win_snmp_disk.pl x.x.x.x community 1 80 90
OK : Percent Used : 74.1%, Total : 452.9 GiB, Used : 335.8 GiB,  Free : 117 GiB
Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
VisRyanWilliams
Posts: 8
Joined: Mon Apr 14, 2014 8:57 am

Re: Nagios returns service did not exit properly

Post by VisRyanWilliams »

Hi

I have at this point started from scratch and replaced the plugin, done a new command and definition in case I made any mistake.

I have obtained the script from here http://exchange.nagios.org/directory/Pl ... ck/details

Which is this code

Code: Select all

#!/usr/bin/perl
# Enhanced by: Dan Capper
# Date: 13/11/2007
# Based on original script:
# Author : jakubowski Benjamin
# Date : 19/12/2005
# check_win_snmp_disk.pl SERVEUR COMMUNITY

# ------------ "Nearest" routines (round to a multiple of any number)
# Copied from Math::Round on cpan.org
# Math::Round was written by Geoffrey Rommel GROMMEL@cpan.org in October 2000.

sub nearest {
 my ($targ, @inputs) = @_;
 my @res = ();
 my $x;

 $targ = abs($targ) if $targ < 0;
 foreach $x (@inputs) {
   if ($x >= 0) {
      push @res, $targ * int(($x + $half * $targ) / $targ);
   } else {
      push @res, $targ * POSIX::ceil(($x - $half * $targ) / $targ);
   }
 }
 return (wantarray) ? @res : $res[0];
}

$STATE_OK = 0;
$STATE_WARNING = 1; 
$STATE_CRITICAL = 2;
$STATE_ERROR = 255;

# IEC Multipliers
$TEBI = 1099511627776;
$GIBI = 1073741824;
$MEBI = 1048576;
$KIBI = 1024;

if ($#ARGV + 1 < 5) {
	print "Enhanced check_win_snmp_disk.pl by Dan Capper based on original script by jakubowski Benjamin\n";
	print "Reports disk usage of Windows systems via snmp to nagios\n";
	print "\n";
	print "usage:\n";
	print "check_win_snmp_disk.pl [address] [community-name] [logical disk] [warn-level] [critical-level]\n";
	print "Where:\n";
	print "[address]	= ip address or name of server to check\n";
	print "[community-name] = SNMP community name with at least READ ONLY rights to server\n";
	print "[logical disk]	= Logical disk number of disk to check - on windows systems, 0 = A:, 1 = C:, 2 = D:, etc\n";
	print "[warn-level]	= Percentage full before return warning level to nagios\n";
	print "[critical-level] = Percentage full before return critical level to nagios\n";
	print "For example the command:\n";
	print "./check_win_snmp_disk.pl 10.0.0.10 public 2 80 90\n";
	print "Will check disk 'C:' on the server at '10.0.0.10' using snmp community name 'public'. Warn at 80% full, Critical at 90% full\n";
	exit $STATE_ERROR;
}

if (@ARGV[0] =~ m/((\d{1,3}\.){3}\d{1,3})|(\w+)/) {
	$SERVER = @ARGV[0];
} else {
	print "ERROR: address argument not in correct format\n";
	print "Execute with no parameters to see usage information\n";
	exit $STATE_ERROR;
}

if (@ARGV[1] =~ m/\w+/) {
	$COMMUNITYNAME=@ARGV[1];
} else {
	print "ERROR: community-name argument not in correct format\n";
	print "Execute with no parameters to see usage information\n";
	exit $STATE_ERROR;
}

if (@ARGV[2] =~ m/\d{1,2}/) {
	$LDISK=@ARGV[2];
} else {
	print "ERROR: logical disk argument not in correct format\n";
	print "Execute with no parameters to see usage information\n";
	exit $STATE_ERROR;
}

if (@ARGV[4] =~ m/\d{1,3}/ and @ARGV[4] <= 100) {
	$CRITICAL=@ARGV[4];	
} else {
	print "ERROR: critical argument not in correct format\n";
	print "critical level must no more than 100\n";
	print "Execute with no parameters to see usage information\n";
	exit $STATE_ERROR;
}
 
if (@ARGV[3] =~ m/\d{1,3}/ and @ARGV[3] <= 100 and @ARGV[3] <= $CRITICAL) {
	$WARN=@ARGV[3];	
} else {
	print "ERROR: warning-level argument not in correct format\n";
	print "warning-level must no more than 100 and less than critical level\n";
	print "Execute with no parameters to see usage information\n";
	exit $STATE_ERROR;
}

# Used Space
$RAWUSED=`snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.$LDISK -t 5| awk '{ print \$4 }'`;
$RAWUSED =~ s/\n//g;
if ($RAWUSED !~ m/\d+/) {
	print "ERROR : Unexpected result from snmpget\n";
	exit $STATE_ERROR;
}

# Size of disk
$RAWSIZE=`/usr/bin/snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize.$LDISK -t 5| awk '{ print  \$4  }'`;
$RAWSIZE =~ s/\n//g;
if ($RAWSIZE !~ m/\d+/) {
	print "ERROR : Unexpected result from snmpget\n";
	exit $STATE_ERROR;
}

# GET BYTE VALUE FOR DISK SYSTEM (512;1024;2048;4096)
$VALUE=`/usr/bin/snmpget -v 1 $SERVER -c $COMMUNITYNAME .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageAllocationUnits.$LDISK -t 5 | awk '{ print \$4 }'`;

$VALUE =~ s/\n//g;
if ($VALUE !~ m/\d+/) {
	print "ERROR : Unexpected result from snmpget\n";
	exit $STATE_ERROR;
}

# Calculate percentage used

SWITCH: {
	if ($RAWSIZE > 0)		{ $PERCENTUSED = nearest(.1, $RAWUSED/$RAWSIZE * 100); last SWITCH; };
	$PERCENTUSED = 0;
}

# Calculate human-readable total space

SWITCH: {
	if ($RAWSIZE * $VALUE >= $TEBI)		{ $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($TEBI)); $TOTALUNITS = "TiB"; last SWITCH; };	
	if ($RAWSIZE * $VALUE >= $GIBI)		{ $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($GIBI)); $TOTALUNITS = "GiB"; last SWITCH; };	
	if ($RAWSIZE * $VALUE >= $MEBI)		{ $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($MEBI)); $TOTALUNITS = "MiB"; last SWITCH; };	
	if ($RAWSIZE * $VALUE >= $KIBI)		{ $TOTAL = nearest(.1, $RAWSIZE * $VALUE/($KIBI)); $TOTALUNITS = "KiB"; last SWITCH; };	
	if ($RAWSIZE > 0) 			{ $TOTAL = nearest(.1, $RAWTOTAL * $VALUE); $TOTALUNITS = "B"; last SWITCH; };
	$TOTAL = 0;
}

# Calculate human-readable used space

SWITCH: {
	if ($RAWUSED * $VALUE >= $TEBI)	{ $USED = nearest(.1, $RAWUSED * $VALUE/($TEBI)); $USEDUNITS = "TiB"; last SWITCH; };	
	if ($RAWUSED * $VALUE >= $GIBI)	{ $USED = nearest(.1, $RAWUSED * $VALUE/($GIBI)); $USEDUNITS = "GiB"; last SWITCH; };	
	if ($RAWUSED * $VALUE >= $MEBI)	{ $USED = nearest(.1, $RAWUSED * $VALUE/($MEBI)); $USEDUNITS = "MiB"; last SWITCH; };	
	if ($RAWUSED * $VALUE >= $KIBI)	{ $USED = nearest(.1, $RAWUSED * $VALUE/($KIBI)); $USEDUNITS = "KiB"; last SWITCH; };	
	if ($RAWUSED * $VALUE > 0) 		{ $USED = nearest(.1, $RAWUSED * $VALUE); $USEDUNITS = "B"; last SWITCH; };
	$USED = 0;
}

# Calculate Free Space

$RAWFREE=$RAWSIZE-$RAWUSED; 

# Calculate human-readable free space

SWITCH: {
	if ($RAWFREE * $VALUE >= $TEBI)	{ $FREE = nearest(.1, $RAWFREE * $VALUE/($TEBI)); $FREEUNITS = "TiB"; last SWITCH; };	
	if ($RAWFREE * $VALUE >= $GIBI)	{ $FREE = nearest(.1, $RAWFREE * $VALUE/($GIBI)); $FREEUNITS = "GiB"; last SWITCH; };	
	if ($RAWFREE * $VALUE >= $MEBI)	{ $FREE = nearest(.1, $RAWFREE * $VALUE/($MEBI)); $FREEUNITS = "MiB"; last SWITCH; };	
	if ($RAWFREE * $VALUE >= $KIBI)	{ $FREE = nearest(.1, $RAWFREE * $VALUE/($KIBI)); $FREEUNITS = "KiB"; last SWITCH; };	
	if ($RAWFREE > 0) 		{ $FREE = nearest(.1, $RAWFREE * $VALUE); $FREEUNITS = "B"; last SWITCH; };
	$FREE = 0;
}

if ( $PERCENTUSED < $WARN ) { 
	print "OK : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n"; 
	exit $STATE_OK; 
}

if ( $PERCENTUSED < $CRITICAL ) { 
	print "WARNING : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n"; 
	exit $STATE_WARNING;
}

if ( $PERCENTUSED >= $CRITICAL ) {
	print "CRITICAL : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n"; 
	exit $STATE_CRITICAL;
}

print "ERROR : Unexpected Results : Percent Used : $PERCENTUSED%, Total : $TOTAL $TOTALUNITS, Used : $USED $USEDUNITS,  Free : $FREE $FREEUNITS\n"; 
exit $STATE_ERROR;

Command Definition

Code: Select all

define command{
        command_name    check_win_snmp_disk
        command_line    /usr/lib/nagios/plugins/check_win_snmp_disk.pl $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
        }
Service Definition

Code: Select all

#check disk space
define service {
        hostgroup_name                  netbios-ssn
        service_description             Windows-Check-Disk
        check_command                   check_win_snmp_disk!public!90!95
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}
I then run the following

Code: Select all

VSHMON41:/usr/lib/nagios/plugins# ./check_win_snmp_disk.pl -h
Enhanced check_win_snmp_disk.pl by Dan Capper based on original script by jakubowski Benjamin
Reports disk usage of Windows systems via snmp to nagios

usage:
check_win_snmp_disk.pl [address] [community-name] [logical disk] [warn-level] [critical-level]
Where:
[address]       = ip address or name of server to check
[community-name] = SNMP community name with at least READ ONLY rights to server
[logical disk]  = Logical disk number of disk to check - on windows systems, 0 = A:, 1 = C:, 2 = D:, etc
[warn-level]    = Percentage full before return warning level to nagios
[critical-level] = Percentage full before return critical level to nagios
For example the command:
./check_win_snmp_disk.pl 10.0.0.10 public 2 80 90
Will check disk 'C:' on the server at '10.0.0.10' using snmp community name 'public'. Warn at 80% full, Critical at 90% full
Which returned the result

Code: Select all

VSHMON41:/usr/lib/nagios/plugins# ./check_win_snmp_disk.pl 172.16.233.109 public 1 80 90
.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.1: Unknown Object Identifier (org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.1)
ERROR : Unexpected result from snmpget
I'm seriously stumped
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios returns service did not exit properly

Post by lmiltchev »

Can you run snmpwalk against this host?

Code: Select all

snmpwalk -v 1 172.16.233.109 -c public
Be sure to check out our Knowledgebase for helpful articles and solutions!
VisRyanWilliams
Posts: 8
Joined: Mon Apr 14, 2014 8:57 am

Re: Nagios returns service did not exit properly

Post by VisRyanWilliams »

Yes I can

It runs through printing a bunch of things out to the screen.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios returns service did not exit properly

Post by lmiltchev »

OK, run the following command:

Code: Select all

snmpwalk -v 1 172.16.233.109 -c public mib-2.host > /tmp/debug.txt
and post the debug.txt that was generated by running the above command.
Be sure to check out our Knowledgebase for helpful articles and solutions!
VisRyanWilliams
Posts: 8
Joined: Mon Apr 14, 2014 8:57 am

Re: Nagios returns service did not exit properly

Post by VisRyanWilliams »

Sorry for late reply

I have uploaded the debug.txt
Attachments
debug.txt
(200.7 KiB) Downloaded 399 times
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Nagios returns service did not exit properly

Post by sreinhardt »

The plugin is using a bunch of shortnames instead of numeric oids. Unfortunately your system does not seem to contain mibs to translate them to oids for sending to the remote system. You could certainly look at oidview or something similar for the mibs that will provide them, otherwise a different plugin would probably be easiest, and actually check_snmp_storage will likely do what you want out of the box.

More details on what is failing: http://www.net-snmp.org/wiki/index.php/ ... cations_08
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked