summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 19d76b3)
raw | patch | inline | side by side (parent: 19d76b3)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 24 Mar 2006 16:12:05 +0000 (16:12 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 24 Mar 2006 16:12:05 +0000 (16:12 +0000) |
nc is available, will check send and receive working correctly
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1353 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1353 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_tcp.c | patch | blob | history | |
plugins/t/check_udp.t | patch | blob | history |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 5c287b7a7dcc2122cfb73edcb61628fad75f87a0..d8fc26e7d3e7aee3f273c3f536ac0c8b27111ccf 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
if(flags & FLAG_VERBOSE) {
printf("Using service %s\n", SERVICE);
- printf("Port: %d\n", PORT);
+ printf("Port: %d\n", server_port);
printf("flags: 0x%x\n", (int)flags);
}
if(EXPECT && !server_expect_count)
server_expect_count++;
+ if(PROTOCOL==IPPROTO_UDP && !(server_expect_count && server_send)){
+ usage(_("With UDP checks, a send/expect string must be specified."));
+ }
+
/* set up the timer */
signal (SIGALRM, socket_timeout_alarm_handler);
alarm (socket_timeout);
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t
index c80e08addc53eb3a0f3bd6a20e563d4a2d52217c..c9228adc64890064d1819120d7967dde964b1943 100644 (file)
--- a/plugins/t/check_udp.t
+++ b/plugins/t/check_udp.t
#
use strict;
-use Test;
+use Test::More;
use NPTest;
-use vars qw($tests);
-BEGIN {$tests = 3; plan tests => $tests} #TODO# Update to 4 when the commented out test is fixed
+my $res;
+
+plan tests => 14;
+
+$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333" );
+cmp_ok( $res->return_code, '==', 3, "Need send/expect string");
+like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
+
+$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s send" );
+cmp_ok( $res->return_code, '==', 3, "Need expect string");
+like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
+
+$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -e expect" );
+cmp_ok( $res->return_code, '==', 3, "Need send string");
+like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
+
+$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s foo -e bar" );
+cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" );
+like ( $res->output, '/No data received from host/', "Output OK");
+
+SKIP: {
+ skip "No netcat available", 6 unless (system("which nc > /dev/null") == 0);
+ open (NC, "echo 'barbar' | nc -l -p 3333 -u |");
+ sleep 1;
+ $res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s '' -e barbar -4" );
+ cmp_ok( $res->return_code, '==', 0, "Got barbar response back" );
+ like ( $res->output, '/\[barbar\]/', "Output OK");
+ close NC;
+
+ my $pid = open(NC, "nc -l -p 3333 -u |"); # Start up a udp server listening on port 3333
+ alarm(7);
+ sleep 1;
+ $SIG{ALRM} = sub { kill 'INT', $pid };
+ my $start = time;
+ $res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s foofoo -e barbar -t 5 -4" );
+ my $duration = time - $start;
+ cmp_ok( $res->return_code, '==', '2', "Hung waiting for response");
+ like ( $res->output, '/Socket timeout after 5 seconds/', "Timeout message");
+ cmp_ok( $duration, '==', 5, "Timeout exactly right");
+ my $read_nc = <NC>;
+ # nc gets killed here - I think expects a linefeed from stdin, so doesn't exit itself
+ close NC;
+ cmp_ok( $read_nc, 'eq', "foofoo", "Data received correctly" );
+}
-my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost",
- "A host providing the UDP Time Service" );
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
-
-my $successOutput = '/^Connection accepted on port [0-9]+ - [0-9]+ second response time$/';
-
-my $t;
-
-$t += checkCmd( "./check_udp -H $host_udp_time -p 37 -wt 300 -ct 600", 0, $successOutput );
-$t += checkCmd( "./check_udp $host_nonresponsive -p 37 -wt 0 -ct 0 -to 1", 2 );
-#TODO# $t += checkCmd( "./check_udp $hostname_invalid -p 37 -wt 0 -ct 0 -to 1", 2 ); # Currently returns 0 (ie success)
-
-exit(0) if defined($Test::Harness::VERSION);
-exit($tests - $t);