[Nagiosplug-checkins] SF.net SVN: nagiosplug: [2022] nagiosplug/trunk/plugins/t/check_snmp.t

psychotrahe at users.sourceforge.net psychotrahe at users.sourceforge.net
Wed Jul 9 23:54:43 CEST 2008


Revision: 2022
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2022&view=rev
Author:   psychotrahe
Date:     2008-07-09 14:54:41 -0700 (Wed, 09 Jul 2008)

Log Message:
-----------
rewrote check_snmp.t to use Test::More
added perfdata checking for string values

Modified Paths:
--------------
    nagiosplug/trunk/plugins/t/check_snmp.t

Modified: nagiosplug/trunk/plugins/t/check_snmp.t
===================================================================
--- nagiosplug/trunk/plugins/t/check_snmp.t	2008-07-09 21:53:12 UTC (rev 2021)
+++ nagiosplug/trunk/plugins/t/check_snmp.t	2008-07-09 21:54:41 UTC (rev 2022)
@@ -6,52 +6,65 @@
 #
 
 use strict;
-use Test;
+use Test::More;
 use NPTest;
 
 use vars qw($tests);
-BEGIN {$tests = 12; plan tests => $tests}
+BEGIN {$tests = 14; plan tests => $tests}
 
-my $t;
+my $res;
 
-if ( -x "./check_snmp" )
-{
-  my $host_snmp          = getTestParameter( "host_snmp",          "NP_HOST_SNMP",      "localhost",
-					     "A host providing an SNMP Service");
+SKIP: {
+	skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
 
-  my $snmp_community     = getTestParameter( "snmp_community",     "NP_SNMP_COMMUNITY", "public",
-					     "The SNMP Community string for SNMP Testing" );
+	my $host_snmp = getTestParameter( "host_snmp",          "NP_HOST_SNMP",      "localhost",
+	                                   "A host providing an SNMP Service");
 
-  my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
-					     "The hostname of system not responsive to network requests" );
+	my $snmp_community = getTestParameter( "snmp_community",     "NP_SNMP_COMMUNITY", "public",
+                                           "The SNMP Community string for SNMP Testing" );
 
-  my $hostname_invalid   = getTestParameter( "hostname_invalid",   "NP_HOSTNAME_INVALID",   "nosuchhost",
-					     "An invalid (not known to DNS) hostname" );
+	my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
+	                                           "The hostname of system not responsive to network requests" );
 
-  my %exceptions = ( 3 => "No SNMP Server present?" );
+	my $hostname_invalid   = getTestParameter( "hostname_invalid",   "NP_HOSTNAME_INVALID",   "nosuchhost",
+	                                           "An invalid (not known to DNS) hostname" );
 
+	SKIP: {
+		skip "no snmp host defined", 10 if ( ! $host_snmp );
 
-  $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:",
-		  { 0 => 'continue',  3 => 'skip' }, '/^SNMP OK - \d+/',		%exceptions );
+		$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
+		cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); 
+		like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
 
-  $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1",
-		  { 0 => 'continue',  3 => 'skip' }, '/^SNMP OK - 1\s.*$/',		%exceptions );
+		$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
+		cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); 
+		unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
 
-  $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0   -c 1:",
-		  { 1 => 'continue',  3 => 'skip' }, '/^SNMP WARNING - \*1\*\s.*$/',	%exceptions );
+		$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
+		cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); 
+		like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
 
-  $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w  :0 -c 0",
-		  { 2 => 'continue',  3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s.*$/',	%exceptions );
+		$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0   -c 1:");
+		cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); 
+		like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
 
-  $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
+		$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w  :0 -c 0");
+		cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); 
+		like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and ouput format");
+	}
 
-  $t += checkCmd( "./check_snmp -H $hostname_invalid   -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
+	SKIP: {
+		skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
+		$res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
+		cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); 
+		like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
+	}
 
+	SKIP: {
+		skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
+		$res = NPTest->testCmd( "./check_snmp -H $hostname_invalid   -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
+		cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); 
+		like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
+	}
+
 }
-else
-{
-  $t += skipMissingCmd( "./check_snmp", $tests );
-}
-
-exit(0) if defined($Test::Harness::VERSION);
-exit($tests - $t);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list