diff options
| author | Sven Nierlein <sven@nierlein.de> | 2012-06-26 20:53:13 +0200 |
|---|---|---|
| committer | Sven Nierlein <sven@nierlein.de> | 2012-06-26 20:53:13 +0200 |
| commit | 9c886d049d1dec9be0ac147c57d2094d2d4773da (patch) | |
| tree | 277c3a24d09892713f4d651d980ad748db86d440 /plugins | |
| parent | cf07b50a8213a5d4e6739e3a426cbe93c7113b1b (diff) | |
| download | monitoring-plugins-9c886d049d1dec9be0ac147c57d2094d2d4773da.tar.gz | |
Fix performance data label containing spaces in check_snmp (Jochen Bern)
Add --perf-oids option for check_snmp to retain optional 1.4.14 compatibility
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_snmp.c | 26 | ||||
| -rwxr-xr-x | plugins/tests/check_snmp.t | 23 |
2 files changed, 45 insertions, 4 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 4cd38051..51ad6f4e 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -141,6 +141,7 @@ int calculate_rate = 0; | |||
| 141 | int rate_multiplier = 1; | 141 | int rate_multiplier = 1; |
| 142 | state_data *previous_state; | 142 | state_data *previous_state; |
| 143 | double previous_value[MAX_OIDS]; | 143 | double previous_value[MAX_OIDS]; |
| 144 | int perf_labels = 1; | ||
| 144 | 145 | ||
| 145 | 146 | ||
| 146 | int | 147 | int |
| @@ -169,6 +170,7 @@ main (int argc, char **argv) | |||
| 169 | char *state_string=NULL; | 170 | char *state_string=NULL; |
| 170 | size_t response_length, current_length, string_length; | 171 | size_t response_length, current_length, string_length; |
| 171 | char *temp_string=NULL; | 172 | char *temp_string=NULL; |
| 173 | char *quote_string=NULL; | ||
| 172 | time_t current_time; | 174 | time_t current_time; |
| 173 | double temp_double; | 175 | double temp_double; |
| 174 | time_t duration; | 176 | time_t duration; |
| @@ -485,11 +487,22 @@ main (int argc, char **argv) | |||
| 485 | ptr = NULL; | 487 | ptr = NULL; |
| 486 | strtod(show, &ptr); | 488 | strtod(show, &ptr); |
| 487 | if (ptr > show) { | 489 | if (ptr > show) { |
| 488 | if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) | 490 | if (perf_labels && nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
| 489 | temp_string=labels[i]; | 491 | temp_string=labels[i]; |
| 490 | else | 492 | else |
| 491 | temp_string=oidname; | 493 | temp_string=oidname; |
| 492 | strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); | 494 | if (strpbrk (temp_string, " ='\"") == NULL) { |
| 495 | strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 496 | } else { | ||
| 497 | if (strpbrk (temp_string, "\"") == NULL) { | ||
| 498 | quote_string="\""; | ||
| 499 | } else { | ||
| 500 | quote_string="'"; | ||
| 501 | } | ||
| 502 | strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 503 | strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 504 | strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 505 | } | ||
| 493 | strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); | 506 | strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); |
| 494 | len = sizeof(perfstr)-strlen(perfstr)-1; | 507 | len = sizeof(perfstr)-strlen(perfstr)-1; |
| 495 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 508 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
| @@ -583,6 +596,7 @@ process_arguments (int argc, char **argv) | |||
| 583 | {"rate", no_argument, 0, L_CALCULATE_RATE}, | 596 | {"rate", no_argument, 0, L_CALCULATE_RATE}, |
| 584 | {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, | 597 | {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, |
| 585 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, | 598 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, |
| 599 | {"perf-oids", no_argument, 0, 'O'}, | ||
| 586 | {0, 0, 0, 0} | 600 | {0, 0, 0, 0} |
| 587 | }; | 601 | }; |
| 588 | 602 | ||
| @@ -600,7 +614,7 @@ process_arguments (int argc, char **argv) | |||
| 600 | } | 614 | } |
| 601 | 615 | ||
| 602 | while (1) { | 616 | while (1) { |
| 603 | c = getopt_long (argc, argv, "nhvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", | 617 | c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", |
| 604 | longopts, &option); | 618 | longopts, &option); |
| 605 | 619 | ||
| 606 | if (c == -1 || c == EOF) | 620 | if (c == -1 || c == EOF) |
| @@ -798,6 +812,9 @@ process_arguments (int argc, char **argv) | |||
| 798 | case L_INVERT_SEARCH: | 812 | case L_INVERT_SEARCH: |
| 799 | invert_search=1; | 813 | invert_search=1; |
| 800 | break; | 814 | break; |
| 815 | case 'O': | ||
| 816 | perf_labels=0; | ||
| 817 | break; | ||
| 801 | } | 818 | } |
| 802 | } | 819 | } |
| 803 | 820 | ||
| @@ -1063,6 +1080,9 @@ print_help (void) | |||
| 1063 | printf (" %s\n", "-e, --retries=INTEGER"); | 1080 | printf (" %s\n", "-e, --retries=INTEGER"); |
| 1064 | printf (" %s\n", _("Number of retries to be used in the requests")); | 1081 | printf (" %s\n", _("Number of retries to be used in the requests")); |
| 1065 | 1082 | ||
| 1083 | printf (" %s\n", "-O, --perf-oids"); | ||
| 1084 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | ||
| 1085 | |||
| 1066 | printf (UT_VERBOSE); | 1086 | printf (UT_VERBOSE); |
| 1067 | 1087 | ||
| 1068 | printf ("\n"); | 1088 | printf ("\n"); |
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 2645cc1b..7a5a8b3f 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
| @@ -8,7 +8,7 @@ use Test::More; | |||
| 8 | use NPTest; | 8 | use NPTest; |
| 9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
| 10 | 10 | ||
| 11 | my $tests = 41; | 11 | my $tests = 51; |
| 12 | # Check that all dependent modules are available | 12 | # Check that all dependent modules are available |
| 13 | eval { | 13 | eval { |
| 14 | require NetSNMP::OID; | 14 | require NetSNMP::OID; |
| @@ -144,6 +144,27 @@ is($res->return_code, 0, "OK as no thresholds" ); | |||
| 144 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | 144 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); |
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | # label performance data check | ||
| 148 | $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 -l test" ); | ||
| 149 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 150 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | ||
| 151 | |||
| 152 | $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 -l \"test'test\"" ); | ||
| 153 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 154 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); | ||
| 155 | |||
| 156 | $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 -l 'test\"test'" ); | ||
| 157 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 158 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); | ||
| 159 | |||
| 160 | $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 -l test -O" ); | ||
| 161 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 162 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); | ||
| 163 | |||
| 164 | $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" ); | ||
| 165 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 166 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); | ||
| 167 | |||
| 147 | 168 | ||
| 148 | $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 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 169 | $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 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
| 149 | is($res->return_code, 0, "OK for first call" ); | 170 | is($res->return_code, 0, "OK for first call" ); |
