summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3fa3707)
raw | patch | inline | side by side (parent: 3fa3707)
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | |
Sat, 21 Mar 2009 06:32:50 +0000 (02:32 -0400) | ||
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | |
Sat, 21 Mar 2009 06:32:50 +0000 (02:32 -0400) |
NEWS | patch | blob | history | |
plugins/check_http.c | patch | blob | history | |
plugins/tests/check_http.t | patch | blob | history |
index a03877cd7ccc986c8fde3f3efbad0ad8b33e3a37..164ef9fa6d6f948e817719b4468677bf7a6f7a0c 100644 (file)
--- a/NEWS
+++ b/NEWS
Fixed check_mrtg returning UNKNOWN instead of OK (bug #2378068)
Fixed check_http behaviour: all check are now performed as long as a valid response is returned (sf.net #1460312)
check_http --onredirect=sticky follows using the same IP address (sf.net #2550208)
+ check_http --onredirect=stickyport also follows the same port
Fixed coredump from check_nt when invalid drive is specified (#2179754 - Olli Hauer)
Fixed passing of quotes in OID for check_snmp (#1985230 - Jan Wagner, patch by John Barbuto)
Fixed check_http sending HTTP/1.0 with v1.1 headers (#2638765)
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 72d0a2b6d52e00548a2a584f2a38414436b33d35..5a859f98774bafa8513cbe64d91bb08fdfd277d2 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
#include <ctype.h>
#define INPUT_DELIMITER ";"
+#define STICKY_NONE 0
+#define STICKY_HOST 1
+#define STICKY_PORT 2
#define HTTP_EXPECT "HTTP/1."
enum {
char **http_opt_headers;
int http_opt_headers_count = 0;
int onredirect = STATE_OK;
-int followsticky = 0;
+int followsticky = STICKY_NONE;
int use_ssl = FALSE;
int verbose = FALSE;
int sd;
server_port = HTTPS_PORT;
break;
case 'f': /* onredirect */
+ if (!strcmp (optarg, "stickyport"))
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT;
if (!strcmp (optarg, "sticky"))
- onredirect = STATE_DEPENDENT, followsticky = 1;
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST;
if (!strcmp (optarg, "follow"))
- onredirect = STATE_DEPENDENT, followsticky = 0;
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE;
if (!strcmp (optarg, "unknown"))
onredirect = STATE_UNKNOWN;
if (!strcmp (optarg, "ok"))
free (host_name);
host_name = strdup (addr);
- if (followsticky == 0) {
+ if (!(followsticky & STICKY_HOST)) {
free (server_address);
server_address = strdup (addr);
}
+ if (!(followsticky & STICKY_PORT)) {
+ server_port = i;
+ }
free (server_url);
server_url = url;
- if ((server_port = i) > MAX_PORT)
+ if (server_port > MAX_PORT)
die (STATE_UNKNOWN,
_("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"),
MAX_PORT, server_type, server_address, server_port, server_url,
printf (" %s\n", _(" Any other tags to be sent in http header. Use multiple times for additional headers"));
printf (" %s\n", "-L, --link");
printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
- printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky>");
+ printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the"));
- printf (" %s\n", _("specified IP address"));
+ printf (" %s\n", _("specified IP address. stickyport also ensure post stays the same."));
printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>");
printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)"));
index b0df960c3032a4d441e579e79dc70d483cf0dcf2..88b77d3b8cd7b662a8ebe99045451edd8d18f3e2 100755 (executable)
} elsif ($r->url->path eq "/redirect") {
$c->send_redirect( "/redirect2" );
} elsif ($r->url->path eq "/redir_external") {
- $c->send_redirect( "http://169.254.169.254/redirect2" );
+ $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" );
} elsif ($r->url->path eq "/redirect2") {
$c->send_basic_header;
$c->send_crlf;
- $c->send_response("redirected");
+ $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' ));
} elsif ($r->url->path eq "/redir_timeout") {
$c->send_redirect( "/timeout" );
} elsif ($r->url->path eq "/timeout") {
}
}
-my $common_tests = 55;
+my $common_tests = 62;
my $ssl_only_tests = 6;
if (-x "./check_http") {
plan tests => $common_tests * 2 + $ssl_only_tests;
is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
like( $result->output, '/WARNING - Certificate expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
-
# Expired cert tests
$result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
is( $result->return_code, 0, $cmd);
like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
-
$cmd = "$command -u /redirect -k 'follow: me'";
$result = NPTest->testCmd( $cmd );
is( $result->return_code, 0, $cmd);
is( $result->return_code, 0, $cmd);
like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+ $cmd = "$command -f sticky -u /redirect -k 'follow: me'";
+ $result = NPTest->testCmd( $cmd );
+ is( $result->return_code, 0, $cmd);
+ like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+
+ $cmd = "$command -f stickyport -u /redirect -k 'follow: me'";
+ $result = NPTest->testCmd( $cmd );
+ is( $result->return_code, 0, $cmd);
+ like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+
# These tests may block
print "ALRM\n";
- $cmd = "$command -f sticky -u /redir_external -t 5";
+ # stickyport - on full urlS port is set back to 80 otherwise
+ $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected";
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(2);
$result = NPTest->testCmd( $cmd );
alarm(0); };
- isnt( $@, "alarm\n", $cmd);
+ isnt( $@, "alarm\n", $cmd );
+ is( $result->return_code, 0, $cmd );
- # Will this one work everywhere???
- $cmd = "$command -f follow -u /redir_external -t 5";
+ # Let's hope there won't be any web server on :80 returning "redirected"!
+ $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected";
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(2);
$result = NPTest->testCmd( $cmd );
alarm(0); };
- is( $@, "alarm\n", $cmd);
+ isnt( $@, "alarm\n", $cmd );
+ isnt( $result->return_code, 0, $cmd );
+
+ # Test an external address - timeout
+ SKIP: {
+ skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
+ $cmd = "$command -f follow -u /redir_external -t 5";
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm(2);
+ $result = NPTest->testCmd( $cmd );
+ alarm(0); };
+ is( $@, "alarm\n", $cmd );
+ }
$cmd = "$command -u /timeout -t 5";
eval {
alarm(2);
$result = NPTest->testCmd( $cmd );
alarm(0); };
- is( $@, "alarm\n", $cmd);
+ is( $@, "alarm\n", $cmd );
$cmd = "$command -f follow -u /redir_timeout -t 2";
eval {
alarm(5);
$result = NPTest->testCmd( $cmd );
alarm(0); };
- isnt( $@, "alarm\n", $cmd);
+ isnt( $@, "alarm\n", $cmd );
}
+