Browse Source

check_snmp: use single quotes for perf data labels

Sven Nierlein 13 năm trước cách đây
mục cha
commit
843f954056
2 tập tin đã thay đổi với 8 bổ sung4 xóa
  1. 3 3
      plugins/check_snmp.c
  2. 5 1
      plugins/tests/check_snmp.t

+ 3 - 3
plugins/check_snmp.c

@@ -494,10 +494,10 @@ main (int argc, char **argv)
 			if (strpbrk (temp_string, " ='\"") == NULL) {
 				strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1);
 			} else {
-				if (strpbrk (temp_string, "\"") == NULL) {
-					quote_string="\"";
-				} else {
+				if (strpbrk (temp_string, "'") == NULL) {
 					quote_string="'";
+				} else {
+					quote_string="\"";
 				}
 				strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1);
 				strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1);

+ 5 - 1
plugins/tests/check_snmp.t

@@ -8,7 +8,7 @@ use Test::More;
 use NPTest;
 use FindBin qw($Bin);
 
-my $tests = 51;
+my $tests = 53;
 # Check that all dependent modules are available
 eval {
 	require NetSNMP::OID;
@@ -165,6 +165,10 @@ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1
 is($res->return_code, 0, "OK as no thresholds" );
 is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label");
 
+$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'" );
+is($res->return_code, 0, "OK as no thresholds" );
+is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label");
+
 
 $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" );
 is($res->return_code, 0, "OK for first call" );