summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2012-06-26 18:53:13 (GMT)
committerSven Nierlein <sven@nierlein.de>2012-06-26 18:53:13 (GMT)
commit9c886d049d1dec9be0ac147c57d2094d2d4773da (patch)
tree277c3a24d09892713f4d651d980ad748db86d440
parentcf07b50a8213a5d4e6739e3a426cbe93c7113b1b (diff)
downloadmonitoring-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
-rw-r--r--NEWS2
-rw-r--r--THANKS.in1
-rw-r--r--plugins/check_snmp.c26
-rwxr-xr-xplugins/tests/check_snmp.t23
4 files changed, 48 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 686fb82..aeca4f7 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ This file documents the major additions and syntax changes between releases.
16 Add perfdata to check_disk_smb (Debian #654259 - Charles-Henri Larose) 16 Add perfdata to check_disk_smb (Debian #654259 - Charles-Henri Larose)
17 Updated Nagios::Plugin perl module 17 Updated Nagios::Plugin perl module
18 Add warning threshold to certificate expiration checks of check_tcp/http/smtp (William Leibzon) 18 Add warning threshold to certificate expiration checks of check_tcp/http/smtp (William Leibzon)
19 Add --perf-oids option for check_snmp (Jochen Bern)
19 20
20 FIXES 21 FIXES
21 Fix check_disk free space calculation if blocksizes differ within a disk group (Bekar - #2973603) 22 Fix check_disk free space calculation if blocksizes differ within a disk group (Bekar - #2973603)
@@ -28,6 +29,7 @@ This file documents the major additions and syntax changes between releases.
28 Fix check_ping's parsing of ping6(1) output (#1894850, Debian #514588, Debian #662638 - Matej Vela) 29 Fix check_ping's parsing of ping6(1) output (#1894850, Debian #514588, Debian #662638 - Matej Vela)
29 Fix a check_dhcp bug which was triggered by checking Windows 2003 DHCP servers (#3503921) 30 Fix a check_dhcp bug which was triggered by checking Windows 2003 DHCP servers (#3503921)
30 Disable RFC4507 support, to work around SSL negotiation issues with (at least) some Tomcat versions 31 Disable RFC4507 support, to work around SSL negotiation issues with (at least) some Tomcat versions
32 Fix performance data label containing spaces in check_snmp (Jochen Bern)
31 33
321.4.15 27th July 2010 341.4.15 27th July 2010
33 ENHANCEMENTS 35 ENHANCEMENTS
diff --git a/THANKS.in b/THANKS.in
index f647a0c..018738e 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -273,3 +273,4 @@ Jason Ellison
273Charles-Henri Larose 273Charles-Henri Larose
274Tobias Brox 274Tobias Brox
275William Leibzon 275William Leibzon
276Jochen Bern
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 4cd3805..51ad6f4 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -141,6 +141,7 @@ int calculate_rate = 0;
141int rate_multiplier = 1; 141int rate_multiplier = 1;
142state_data *previous_state; 142state_data *previous_state;
143double previous_value[MAX_OIDS]; 143double previous_value[MAX_OIDS];
144int perf_labels = 1;
144 145
145 146
146int 147int
@@ -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 2645cc1..7a5a8b3 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -8,7 +8,7 @@ use Test::More;
8use NPTest; 8use NPTest;
9use FindBin qw($Bin); 9use FindBin qw($Bin);
10 10
11my $tests = 41; 11my $tests = 51;
12# Check that all dependent modules are available 12# Check that all dependent modules are available
13eval { 13eval {
14 require NetSNMP::OID; 14 require NetSNMP::OID;
@@ -144,6 +144,27 @@ is($res->return_code, 0, "OK as no thresholds" );
144is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); 144is($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" );
149is($res->return_code, 0, "OK as no thresholds" );
150is($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\"" );
153is($res->return_code, 0, "OK as no thresholds" );
154is($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'" );
157is($res->return_code, 0, "OK as no thresholds" );
158is($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" );
161is($res->return_code, 0, "OK as no thresholds" );
162is($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" );
165is($res->return_code, 0, "OK as no thresholds" );
166is($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" );
149is($res->return_code, 0, "OK for first call" ); 170is($res->return_code, 0, "OK for first call" );