diff options
author | Sven Nierlein <sven@nierlein.de> | 2021-11-17 10:58:41 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.org> | 2021-11-17 13:04:09 (GMT) |
commit | 024d268386353133af1a9ff5c0b5879397c19b1c (patch) | |
tree | 285cae08903f564af57304df3344e35a2ccbb401 | |
parent | 3f9b22ab16b5a9b74d62d7fff9b6bf3a51ed93f7 (diff) | |
download | monitoring-plugins-024d268386353133af1a9ff5c0b5879397c19b1c.tar.gz |
check_snmp: fix performance thresholds when using multiple oids
when using check_snmp with multiple oids it simply printed the unparsed content
from -w/-c into the thresholds for each oid. So each oid contained the hole -w
from all oids.
./check_snmp ... -o iso.3.6.1.2.1.25.1.3.0,iso.3.6.1.2.1.25.1.5.0 -w '1,2' -c '3,4'
before:
SNMP ... | HOST-RESOURCES-MIB::hrSystemInitialLoadDevice.0=393216;1,2;3,4 HOST-RESOURCES-MIB::hrSystemNumUsers.0=24;1,2;3,4
after:
SNMP ... | HOST-RESOURCES-MIB::hrSystemInitialLoadDevice.0=393216;1;3 HOST-RESOURCES-MIB::hrSystemNumUsers.0=24;2;4
This also applies to fixed thresholds since check_snmp translates negative infinities from: '~:-1' to '@-1:~'
-rw-r--r-- | lib/utils_base.c | 2 | ||||
-rw-r--r-- | lib/utils_base.h | 1 | ||||
-rw-r--r-- | plugins/check_snmp.c | 9 | ||||
-rwxr-xr-x | plugins/tests/check_snmp.t | 17 |
4 files changed, 23 insertions, 6 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index fd7058d..08fa215 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -128,6 +128,7 @@ range | |||
128 | temp_range->end = 0; | 128 | temp_range->end = 0; |
129 | temp_range->end_infinity = TRUE; | 129 | temp_range->end_infinity = TRUE; |
130 | temp_range->alert_on = OUTSIDE; | 130 | temp_range->alert_on = OUTSIDE; |
131 | temp_range->text = strdup(str); | ||
131 | 132 | ||
132 | if (str[0] == '@') { | 133 | if (str[0] == '@') { |
133 | temp_range->alert_on = INSIDE; | 134 | temp_range->alert_on = INSIDE; |
@@ -706,4 +707,3 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
706 | 707 | ||
707 | np_free(temp_file); | 708 | np_free(temp_file); |
708 | } | 709 | } |
709 | |||
diff --git a/lib/utils_base.h b/lib/utils_base.h index d7e7dff..9482f23 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -23,6 +23,7 @@ typedef struct range_struct { | |||
23 | double end; | 23 | double end; |
24 | int end_infinity; | 24 | int end_infinity; |
25 | int alert_on; /* OUTSIDE (default) or INSIDE */ | 25 | int alert_on; /* OUTSIDE (default) or INSIDE */ |
26 | char* text; /* original unparsed text input */ | ||
26 | } range; | 27 | } range; |
27 | 28 | ||
28 | typedef struct thresholds_struct { | 29 | typedef struct thresholds_struct { |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index afc568b..58d46b1 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -468,6 +468,9 @@ main (int argc, char **argv) | |||
468 | /* Process this block for numeric comparisons */ | 468 | /* Process this block for numeric comparisons */ |
469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ | 469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
471 | if (verbose > 2) { | ||
472 | print_thresholds(" thresholds", thlds[i]); | ||
473 | } | ||
471 | ptr = strpbrk (show, "-0123456789"); | 474 | ptr = strpbrk (show, "-0123456789"); |
472 | if (ptr == NULL) | 475 | if (ptr == NULL) |
473 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 476 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
@@ -581,14 +584,16 @@ main (int argc, char **argv) | |||
581 | 584 | ||
582 | if (warning_thresholds) { | 585 | if (warning_thresholds) { |
583 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 586 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
584 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 587 | if(thlds[i]->warning && thlds[i]->warning->text) |
588 | strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
585 | } | 589 | } |
586 | 590 | ||
587 | if (critical_thresholds) { | 591 | if (critical_thresholds) { |
588 | if (!warning_thresholds) | 592 | if (!warning_thresholds) |
589 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 593 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
590 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 594 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
591 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 595 | if(thlds[i]->critical && thlds[i]->critical->text) |
596 | strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
592 | } | 597 | } |
593 | 598 | ||
594 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 599 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 85d6bf5..0a77fa8 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -9,7 +9,7 @@ use NPTest; | |||
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | 10 | use POSIX qw/strftime/; |
11 | 11 | ||
12 | my $tests = 67; | 12 | my $tests = 73; |
13 | # Check that all dependent modules are available | 13 | # Check that all dependent modules are available |
14 | eval { | 14 | eval { |
15 | require NetSNMP::OID; | 15 | require NetSNMP::OID; |
@@ -251,9 +251,20 @@ is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: | |||
251 | 251 | ||
252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); | 252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); |
253 | is($res->return_code, 0, "Negative float OK" ); | 253 | is($res->return_code, 0, "Negative float OK" ); |
254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;~:-6.5 ', "Negative float OK output" ); | 254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); |
255 | 255 | ||
256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); | 256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); |
257 | is($res->return_code, 1, "Negative float WARNING" ); | 257 | is($res->return_code, 1, "Negative float WARNING" ); |
258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;~:-6.65;~:-6.55 ', "Negative float WARNING output" ); | 258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;@-6.65:~;@-6.55:~ ', "Negative float WARNING output" ); |
259 | 259 | ||
260 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); | ||
261 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); | ||
262 | like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | ||
263 | |||
264 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); | ||
265 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); | ||
266 | like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | ||
267 | |||
268 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" ); | ||
269 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); | ||
270 | like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); | ||