diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_tcp.c | 26 | ||||
-rw-r--r-- | plugins/t/check_tcp.t | 5 |
2 files changed, 22 insertions, 9 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 7e1bd38b..8187bcde 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -347,7 +347,10 @@ main (int argc, char **argv) | |||
347 | if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT)) | 347 | if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT)) |
348 | printf("Unexpected response from host/socket: %s", status); | 348 | printf("Unexpected response from host/socket: %s", status); |
349 | else { | 349 | else { |
350 | printf("%.3f second response time on ", elapsed_time); | 350 | if(match == -2) |
351 | printf("Unexpected response from host/socket on "); | ||
352 | else | ||
353 | printf("%.3f second response time on ", elapsed_time); | ||
351 | if(server_address[0] != '/') | 354 | if(server_address[0] != '/') |
352 | printf("port %d", server_port); | 355 | printf("port %d", server_port); |
353 | else | 356 | else |
@@ -358,17 +361,24 @@ main (int argc, char **argv) | |||
358 | printf (" [%s]", status); | 361 | printf (" [%s]", status); |
359 | 362 | ||
360 | /* perf-data doesn't apply when server doesn't talk properly, | 363 | /* perf-data doesn't apply when server doesn't talk properly, |
361 | * so print all zeroes on warn and crit */ | 364 | * so print all zeroes on warn and criti. Use fperfdata since |
365 | * localisation settings can make different outputs */ | ||
362 | if(match == -2) | 366 | if(match == -2) |
363 | printf ("|time=%fs;0.0;0.0;0.0;0.0", elapsed_time); | 367 | printf ("|%s", |
368 | fperfdata ("time", elapsed_time, "s", | ||
369 | TRUE, 0, | ||
370 | TRUE, 0, | ||
371 | TRUE, 0, | ||
372 | TRUE, socket_timeout) | ||
373 | ); | ||
364 | else | 374 | else |
365 | printf("|%s", | 375 | printf("|%s", |
366 | fperfdata ("time", elapsed_time, "s", | 376 | fperfdata ("time", elapsed_time, "s", |
367 | TRUE, warning_time, | 377 | TRUE, warning_time, |
368 | TRUE, critical_time, | 378 | TRUE, critical_time, |
369 | TRUE, 0, | 379 | TRUE, 0, |
370 | TRUE, socket_timeout) | 380 | TRUE, socket_timeout) |
371 | ); | 381 | ); |
372 | 382 | ||
373 | putchar('\n'); | 383 | putchar('\n'); |
374 | return result; | 384 | return result; |
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index ffe559df..67e527a0 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -10,7 +10,7 @@ use Test; | |||
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | 13 | BEGIN {$tests = 7; plan tests => $tests} |
14 | 14 | ||
15 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", | 15 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", |
16 | "A host providing the HTTP Service (a web server)" ); | 16 | "A host providing the HTTP Service (a web server)" ); |
@@ -23,12 +23,15 @@ my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_IN | |||
23 | 23 | ||
24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; | 24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; |
25 | 25 | ||
26 | my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/'; | ||
27 | |||
26 | my $t; | 28 | my $t; |
27 | 29 | ||
28 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); | 30 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); |
29 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test | 31 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test |
30 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); | 32 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); |
31 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); | 33 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); |
34 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -s 'GET /\n' -e 'ThisShouldntMatch' -j", 1, $failedExpect ); | ||
32 | 35 | ||
33 | exit(0) if defined($Test::Harness::VERSION); | 36 | exit(0) if defined($Test::Harness::VERSION); |
34 | exit($tests - $t); | 37 | exit($tests - $t); |