diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-08-29 06:25:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 06:25:10 (GMT) |
commit | 29613c3be27fb9c7f97ca87e3da3712977e419dc (patch) | |
tree | c033f29162569445495e379cc47e9a632d203b8e /plugins | |
parent | b90b09e1472426993d1c88949a8b30da3f2f900e (diff) | |
parent | 55c0e1738e3397b007ed189f216f8b431da96943 (diff) | |
download | monitoring-plugins-29613c3be27fb9c7f97ca87e3da3712977e419dc.tar.gz |
Merge pull request #1907 from RincewindsHat/fix/repair_test_pipeline
Implement option for check_snmp to ignore mib parsing errors (to fix test pipeline)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_snmp.c | 63 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 68 |
2 files changed, 76 insertions, 55 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 04dc6c6..2acada2 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -65,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
66 | #define L_INVERT_SEARCH CHAR_MAX+3 | 66 | #define L_INVERT_SEARCH CHAR_MAX+3 |
67 | #define L_OFFSET CHAR_MAX+4 | 67 | #define L_OFFSET CHAR_MAX+4 |
68 | #define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 | ||
68 | 69 | ||
69 | /* Gobble to string - stop incrementing c when c[0] match one of the | 70 | /* Gobble to string - stop incrementing c when c[0] match one of the |
70 | * characters in s */ | 71 | * characters in s */ |
@@ -159,6 +160,7 @@ char* ip_version = ""; | |||
159 | double multiplier = 1.0; | 160 | double multiplier = 1.0; |
160 | char *fmtstr = ""; | 161 | char *fmtstr = ""; |
161 | char buffer[DEFAULT_BUFFER_SIZE]; | 162 | char buffer[DEFAULT_BUFFER_SIZE]; |
163 | bool ignore_mib_parsing_errors = false; | ||
162 | 164 | ||
163 | static char *fix_snmp_range(char *th) | 165 | static char *fix_snmp_range(char *th) |
164 | { | 166 | { |
@@ -306,42 +308,55 @@ main (int argc, char **argv) | |||
306 | } | 308 | } |
307 | 309 | ||
308 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 310 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
309 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 311 | |
310 | command_line[0] = snmpcmd; | 312 | unsigned index = 0; |
311 | command_line[1] = strdup ("-Le"); | 313 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
312 | command_line[2] = strdup ("-t"); | 314 | |
313 | xasprintf (&command_line[3], "%d", timeout_interval); | 315 | command_line[index++] = snmpcmd; |
314 | command_line[4] = strdup ("-r"); | 316 | command_line[index++] = strdup ("-Le"); |
315 | xasprintf (&command_line[5], "%d", retries); | 317 | command_line[index++] = strdup ("-t"); |
316 | command_line[6] = strdup ("-m"); | 318 | xasprintf (&command_line[index++], "%d", timeout_interval); |
317 | command_line[7] = strdup (miblist); | 319 | command_line[index++] = strdup ("-r"); |
318 | command_line[8] = "-v"; | 320 | xasprintf (&command_line[index++], "%d", retries); |
319 | command_line[9] = strdup (proto); | 321 | command_line[index++] = strdup ("-m"); |
322 | command_line[index++] = strdup (miblist); | ||
323 | command_line[index++] = "-v"; | ||
324 | command_line[index++] = strdup (proto); | ||
325 | |||
326 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", | ||
327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); | ||
328 | |||
329 | if (ignore_mib_parsing_errors) { | ||
330 | command_line[index++] = "-Pe"; | ||
331 | xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); | ||
332 | } | ||
333 | |||
320 | 334 | ||
321 | for (i = 0; i < numcontext; i++) { | 335 | for (i = 0; i < numcontext; i++) { |
322 | command_line[10 + i] = contextargs[i]; | 336 | command_line[index++] = contextargs[i]; |
323 | } | 337 | } |
324 | 338 | ||
325 | for (i = 0; i < numauthpriv; i++) { | 339 | for (i = 0; i < numauthpriv; i++) { |
326 | command_line[10 + numcontext + i] = authpriv[i]; | 340 | command_line[index++] = authpriv[i]; |
327 | } | 341 | } |
328 | 342 | ||
329 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 343 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
330 | 344 | ||
331 | /* This is just for display purposes, so it can remain a string */ | 345 | xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", |
332 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", | 346 | cl_hidden_auth, |
333 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 347 | server_address, |
334 | server_address, port); | 348 | port); |
335 | 349 | ||
336 | for (i = 0; i < numoids; i++) { | 350 | for (i = 0; i < numoids; i++) { |
337 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 351 | command_line[index++] = oids[i]; |
338 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 352 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
339 | } | 353 | } |
340 | 354 | ||
341 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 355 | command_line[index++] = NULL; |
342 | 356 | ||
343 | if (verbose) | 357 | if (verbose) { |
344 | printf ("%s\n", cl_hidden_auth); | 358 | printf ("%s\n", cl_hidden_auth); |
359 | } | ||
345 | 360 | ||
346 | /* Set signal handling and alarm */ | 361 | /* Set signal handling and alarm */ |
347 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 362 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
@@ -708,6 +723,7 @@ process_arguments (int argc, char **argv) | |||
708 | {"ipv6", no_argument, 0, '6'}, | 723 | {"ipv6", no_argument, 0, '6'}, |
709 | {"multiplier", required_argument, 0, 'M'}, | 724 | {"multiplier", required_argument, 0, 'M'}, |
710 | {"fmtstr", required_argument, 0, 'f'}, | 725 | {"fmtstr", required_argument, 0, 'f'}, |
726 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
711 | {0, 0, 0, 0} | 727 | {0, 0, 0, 0} |
712 | }; | 728 | }; |
713 | 729 | ||
@@ -974,6 +990,8 @@ process_arguments (int argc, char **argv) | |||
974 | fmtstr=optarg; | 990 | fmtstr=optarg; |
975 | } | 991 | } |
976 | break; | 992 | break; |
993 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
994 | ignore_mib_parsing_errors = true; | ||
977 | } | 995 | } |
978 | } | 996 | } |
979 | 997 | ||
@@ -1307,6 +1325,9 @@ print_help (void) | |||
1307 | printf (" %s\n", "-O, --perf-oids"); | 1325 | printf (" %s\n", "-O, --perf-oids"); |
1308 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1326 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
1309 | 1327 | ||
1328 | printf (" %s\n", "--ignore-mib-parsing-errors"); | ||
1329 | printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); | ||
1330 | |||
1310 | printf (UT_VERBOSE); | 1331 | printf (UT_VERBOSE); |
1311 | 1332 | ||
1312 | printf ("\n"); | 1333 | printf ("\n"); |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index f2f218f..576cc50 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -26,22 +26,22 @@ $res = NPTest->testCmd( "./check_snmp -t 1" ); | |||
26 | is( $res->return_code, 3, "No host name" ); | 26 | is( $res->return_code, 3, "No host name" ); |
27 | is( $res->output, "No host specified" ); | 27 | is( $res->output, "No host specified" ); |
28 | 28 | ||
29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname" ); | 29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname --ignore-mib-parsing-errors" ); |
30 | is( $res->return_code, 3, "No OIDs specified" ); | 30 | is( $res->return_code, 3, "No OIDs specified" ); |
31 | is( $res->output, "No OIDs specified" ); | 31 | is( $res->output, "No OIDs specified" ); |
32 | 32 | ||
33 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 -U not_a_user --seclevel=rubbish" ); | 33 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3 -U not_a_user --seclevel=rubbish" ); |
34 | is( $res->return_code, 3, "Invalid seclevel" ); | 34 | is( $res->return_code, 3, "Invalid seclevel" ); |
35 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); | 35 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); |
36 | 36 | ||
37 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" ); | 37 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3c" ); |
38 | is( $res->return_code, 3, "Invalid protocol" ); | 38 | is( $res->return_code, 3, "Invalid protocol" ); |
39 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 39 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); |
40 | 40 | ||
41 | SKIP: { | 41 | SKIP: { |
42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); | 42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); |
43 | 43 | ||
44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
46 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | 46 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); |
47 | $res->output =~ /^SNMP OK - (\d+)/; | 47 | $res->output =~ /^SNMP OK - (\d+)/; |
@@ -51,111 +51,111 @@ SKIP: { | |||
51 | 51 | ||
52 | 52 | ||
53 | # some more threshold tests | 53 | # some more threshold tests |
54 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1"); | 54 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1"); |
55 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); | 55 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); |
56 | 56 | ||
57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:"); | 57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:"); |
58 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); | 58 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); |
59 | 59 | ||
60 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1"); | 60 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c ~:1"); |
61 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); | 61 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); |
62 | 62 | ||
63 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10"); | 63 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:10"); |
64 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); | 64 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); |
65 | 65 | ||
66 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); | 66 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); |
67 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); | 67 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); |
68 | 68 | ||
69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1"); | 69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 10:1"); |
70 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); | 70 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); |
71 | 71 | ||
72 | 72 | ||
73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); | 73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); |
74 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); | 74 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); |
75 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | 75 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); |
76 | 76 | ||
77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | 77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0"); |
78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | 78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); |
79 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | 79 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); |
80 | 80 | ||
81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | 81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); |
82 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | 82 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); |
83 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 83 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
84 | 84 | ||
85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | 85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); |
86 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | 86 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); |
87 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 87 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
88 | 88 | ||
89 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | 89 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); |
90 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | 90 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); |
91 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | 91 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); |
92 | 92 | ||
93 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | 93 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); |
94 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | 94 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); |
95 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | 95 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); |
96 | 96 | ||
97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | 97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); |
98 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | 98 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); |
99 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | 99 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); |
100 | 100 | ||
101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | 101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); |
102 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | 102 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); |
103 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | 103 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); |
104 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 104 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); |
105 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | 105 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); |
106 | 106 | ||
107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); | 107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); |
108 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | 108 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); |
109 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | 109 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); |
110 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 110 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); |
111 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | 111 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); |
112 | 112 | ||
113 | $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:"); | 113 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); |
114 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); | 114 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); |
115 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); | 115 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); |
116 | 116 | ||
117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); | 117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); |
118 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); | 118 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); |
119 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); | 119 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); |
120 | 120 | ||
121 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); | 121 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); |
122 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; | 122 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; |
123 | my $lower = $1 - 0.05; | 123 | my $lower = $1 - 0.05; |
124 | my $higher = $1 + 0.05; | 124 | my $higher = $1 + 0.05; |
125 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); | 125 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); |
126 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); | 126 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); |
127 | 127 | ||
128 | $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"); | 128 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); |
129 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); | 129 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); |
130 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); | 130 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); |
131 | 131 | ||
132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); | 132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); |
133 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); | 133 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); |
134 | 134 | ||
135 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); | 135 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); |
136 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); | 136 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); |
137 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); | 137 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); |
138 | 138 | ||
139 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); | 139 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); |
140 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | 140 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); |
141 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | 141 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); |
142 | 142 | ||
143 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); | 143 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); |
144 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | 144 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); |
145 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | 145 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); |
146 | 146 | ||
147 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | 147 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0"); |
148 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | 148 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); |
149 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | 149 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); |
150 | 150 | ||
151 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1"); | 151 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1"); |
152 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); | 152 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); |
153 | like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" ); | 153 | like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" ); |
154 | } | 154 | } |
155 | 155 | ||
156 | SKIP: { | 156 | SKIP: { |
157 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); | 157 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); |
158 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); | 158 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); |
159 | like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" ); | 159 | like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" ); |
160 | } | 160 | } |
161 | 161 | ||
@@ -163,14 +163,14 @@ SKIP: { | |||
163 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway | 163 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway |
164 | SKIP: { | 164 | SKIP: { |
165 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 165 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
166 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 166 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
167 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); | 167 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); |
168 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); | 168 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); |
169 | } | 169 | } |
170 | 170 | ||
171 | SKIP: { | 171 | SKIP: { |
172 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | 172 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); |
173 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 173 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
174 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 174 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
175 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); | 175 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host).*/s', "String matches invalid host"); |
176 | } | 176 | } |