Imported Upstream version 1.4.16+git20130912

This commit is contained in:
Jan Wagner 2013-11-27 00:00:46 +01:00
parent ea90af2ba1
commit 01ca3b324f
14 changed files with 514 additions and 442 deletions

View file

@ -33,6 +33,7 @@ const char *copyright = "1999-2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#include "runcmd.h"
#include "utils.h"
#include "utils_cmd.h"
@ -330,9 +331,18 @@ main (int argc, char **argv)
if (verbose)
printf ("%s\n", cl_hidden_auth);
/* Set signal handling and alarm */
if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
usage4 (_("Cannot catch SIGALRM"));
}
alarm(timeout_interval * retries + 5);
/* Run the command */
return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
/* disable alarm again */
alarm(0);
/* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs,
only return state unknown if return code is non zero or there is no stdout.
Do this way so that if there is stderr, will get added to output, which helps problem diagnosis

View file

@ -3,7 +3,7 @@
* Nagios check_tcp plugin
*
* License: GPL
* Copyright (c) 1999-2008 Nagios Plugins Development Team
* Copyright (c) 1999-2013 Nagios Plugins Development Team
*
* Description:
*
@ -82,15 +82,14 @@ static int sd = 0;
#define MAXBUF 1024
static char buffer[MAXBUF];
static int expect_mismatch_state = STATE_WARNING;
static int match_flags = NP_MATCH_EXACT;
#define FLAG_SSL 0x01
#define FLAG_VERBOSE 0x02
#define FLAG_EXACT_MATCH 0x04
#define FLAG_TIME_WARN 0x08
#define FLAG_TIME_CRIT 0x10
#define FLAG_HIDE_OUTPUT 0x20
#define FLAG_MATCH_ALL 0x40
static size_t flags = FLAG_EXACT_MATCH;
#define FLAG_TIME_WARN 0x04
#define FLAG_TIME_CRIT 0x08
#define FLAG_HIDE_OUTPUT 0x10
static size_t flags;
int
main (int argc, char **argv)
@ -278,30 +277,32 @@ main (int argc, char **argv)
status = realloc(status, len + i + 1);
memcpy(&status[len], buffer, i);
len += i;
status[len] = '\0';
/* stop reading if user-forced */
if (maxbytes && len >= maxbytes)
break;
if ((match = np_expect_match(status,
server_expect,
server_expect_count,
match_flags)) != NP_MATCH_RETRY)
break;
}
if (match == NP_MATCH_RETRY)
match = NP_MATCH_FAILURE;
/* no data when expected, so return critical */
if (len == 0)
die (STATE_CRITICAL, _("No data received from host\n"));
/* force null-termination and strip whitespace from end of output */
status[len--] = '\0';
/* print raw output if we're debugging */
if(flags & FLAG_VERBOSE)
printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
(int)len + 1, status);
while(isspace(status[len])) status[len--] = '\0';
match = np_expect_match(status,
server_expect,
server_expect_count,
(flags & FLAG_MATCH_ALL ? TRUE : FALSE),
(flags & FLAG_EXACT_MATCH ? TRUE : FALSE),
(flags & FLAG_VERBOSE ? TRUE : FALSE));
/* strip whitespace from end of output */
while(--len > 0 && isspace(status[len]))
status[len] = '\0';
}
if (server_quit != NULL) {
@ -321,7 +322,7 @@ main (int argc, char **argv)
result = STATE_WARNING;
/* did we get the response we hoped? */
if(match == FALSE && result != STATE_CRITICAL)
if(match == NP_MATCH_FAILURE && result != STATE_CRITICAL)
result = expect_mismatch_state;
/* reset the alarm */
@ -332,10 +333,10 @@ main (int argc, char **argv)
* the response we were looking for. if-else */
printf("%s %s - ", SERVICE, state_text(result));
if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
if(match == NP_MATCH_FAILURE && len && !(flags & FLAG_HIDE_OUTPUT))
printf("Unexpected response from host/socket: %s", status);
else {
if(match == FALSE)
if(match == NP_MATCH_FAILURE)
printf("Unexpected response from host/socket on ");
else
printf("%.3f second response time on ", elapsed_time);
@ -345,13 +346,13 @@ main (int argc, char **argv)
printf("socket %s", server_address);
}
if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
if (match != NP_MATCH_FAILURE && !(flags & FLAG_HIDE_OUTPUT) && len)
printf (" [%s]", status);
/* perf-data doesn't apply when server doesn't talk properly,
* so print all zeroes on warn and crit. Use fperfdata since
* localisation settings can make different outputs */
if(match == FALSE)
if(match == NP_MATCH_FAILURE)
printf ("|%s",
fperfdata ("time", elapsed_time, "s",
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
@ -450,6 +451,7 @@ process_arguments (int argc, char **argv)
exit (STATE_OK);
case 'v': /* verbose mode */
flags |= FLAG_VERBOSE;
match_flags |= NP_MATCH_VERBOSE;
break;
case '4':
address_family = AF_INET;
@ -506,7 +508,7 @@ process_arguments (int argc, char **argv)
xasprintf(&server_send, "%s", optarg);
break;
case 'e': /* expect string (may be repeated) */
flags &= ~FLAG_EXACT_MATCH;
match_flags &= ~NP_MATCH_EXACT;
if (server_expect_count == 0)
server_expect = malloc (sizeof (char *) * (++server_expect_count));
else
@ -584,7 +586,7 @@ process_arguments (int argc, char **argv)
#endif
break;
case 'A':
flags |= FLAG_MATCH_ALL;
match_flags |= NP_MATCH_ALL;
break;
}
}

View file

@ -9,7 +9,18 @@ use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 14; plan tests => $tests}
my $has_ipv6;
BEGIN {
$tests = 11;
# do we have ipv6
`ping6 -c 1 2a02:2e0:3fe:100::7 2>&1`;
if($? == 0) {
$has_ipv6 = 1;
$tests += 3;
}
plan tests => $tests;
}
my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
"A host providing the HTTP Service (a web server)" );
@ -27,7 +38,6 @@ my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on po
my $t;
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput );
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput );
$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
@ -35,11 +45,16 @@ $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0
$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
# so that perl doesn't interpret the \r\n and is passed onto command line correctly
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -E -s ".'"GET / HTTP/1.1\r\n\r\n"'." -e 'ThisShouldntMatch' -j", 1, $failedExpect );
# IPv6 checks
if($has_ipv6) {
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput );
$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
}
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);