summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_snmp.t
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-05-27 20:52:55 -0400
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-05-28 08:10:49 -0400
commit7cb3ae09334796f3b54e4e6438e38c2cc679b360 (patch)
tree398eb8bf5f022b4d5d158fcf9d39be664dd4fa59 /plugins/t/check_snmp.t
parent34fe4d62fe79236d0cd560f06f6e93bf46a41dd0 (diff)
downloadmonitoring-plugins-7cb3ae09334796f3b54e4e6438e38c2cc679b360.tar.gz
check_snmp: Make use of standard threshold functions
This patch makes use of standard threshold functions. This allows using doubles as thresholds. Since SNMP supports only integers, double precision numbers are only printed when parsed from a STRING type. In addition, support for printing properly Timeticks type has been added, and the code has been thoroughly cleaned.
Diffstat (limited to 'plugins/t/check_snmp.t')
-rw-r--r--plugins/t/check_snmp.t31
1 files changed, 29 insertions, 2 deletions
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index 646cfa43..6cc97b6e 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -8,7 +8,7 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11my $tests = 34; 11my $tests = 44;
12plan tests => $tests; 12plan tests => $tests;
13my $res; 13my $res;
14 14
@@ -44,7 +44,7 @@ SKIP: {
44 like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); 44 like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
45 45
46 SKIP: { 46 SKIP: {
47 skip "no snmp host defined", 20 if ( ! $host_snmp ); 47 skip "no snmp host defined", 30 if ( ! $host_snmp );
48 48
49 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); 49 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); 50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
@@ -85,6 +85,33 @@ SKIP: {
85 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); 85 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
86 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); 86 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
87 like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); 87 like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
88
89 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
90 cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
91 like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
92
93 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
94 $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
95 my $lower = $1 - 0.05;
96 my $higher = $1 + 0.05;
97 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
98 cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arcuments");
99
100 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
101 cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
102 like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s.*,\s.*\s\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
103
104 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
105 cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
106
107 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
108 cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
109 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
110
111 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
112 cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
113 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
114
88 } 115 }
89 116
90 SKIP: { 117 SKIP: {