summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-21 02:32:50 -0400
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-21 02:32:50 -0400
commite7cdcfee2a6025b41f67ead5020df3965ef05a98 (patch)
treeaa9e7122e32e952379fac068e773d29941db21d3
parent3fa3707b5752adfe348e101a194635cc11ace2af (diff)
downloadmonitoring-plugins-e7cdcfee2a6025b41f67ead5020df3965ef05a98.tar.gz
check_http: add --onredirect=stickyport - also follow the same port
-rw-r--r--NEWS1
-rw-r--r--plugins/check_http.c22
-rwxr-xr-xplugins/tests/check_http.t48
3 files changed, 52 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index a03877cd..164ef9fa 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ This file documents the major additions and syntax changes between releases.
21 Fixed check_mrtg returning UNKNOWN instead of OK (bug #2378068) 21 Fixed check_mrtg returning UNKNOWN instead of OK (bug #2378068)
22 Fixed check_http behaviour: all check are now performed as long as a valid response is returned (sf.net #1460312) 22 Fixed check_http behaviour: all check are now performed as long as a valid response is returned (sf.net #1460312)
23 check_http --onredirect=sticky follows using the same IP address (sf.net #2550208) 23 check_http --onredirect=sticky follows using the same IP address (sf.net #2550208)
24 check_http --onredirect=stickyport also follows the same port
24 Fixed coredump from check_nt when invalid drive is specified (#2179754 - Olli Hauer) 25 Fixed coredump from check_nt when invalid drive is specified (#2179754 - Olli Hauer)
25 Fixed passing of quotes in OID for check_snmp (#1985230 - Jan Wagner, patch by John Barbuto) 26 Fixed passing of quotes in OID for check_snmp (#1985230 - Jan Wagner, patch by John Barbuto)
26 Fixed check_http sending HTTP/1.0 with v1.1 headers (#2638765) 27 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 72d0a2b6..5a859f98 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -44,6 +44,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
44#include <ctype.h> 44#include <ctype.h>
45 45
46#define INPUT_DELIMITER ";" 46#define INPUT_DELIMITER ";"
47#define STICKY_NONE 0
48#define STICKY_HOST 1
49#define STICKY_PORT 2
47 50
48#define HTTP_EXPECT "HTTP/1." 51#define HTTP_EXPECT "HTTP/1."
49enum { 52enum {
@@ -106,7 +109,7 @@ int display_html = FALSE;
106char **http_opt_headers; 109char **http_opt_headers;
107int http_opt_headers_count = 0; 110int http_opt_headers_count = 0;
108int onredirect = STATE_OK; 111int onredirect = STATE_OK;
109int followsticky = 0; 112int followsticky = STICKY_NONE;
110int use_ssl = FALSE; 113int use_ssl = FALSE;
111int verbose = FALSE; 114int verbose = FALSE;
112int sd; 115int sd;
@@ -300,10 +303,12 @@ process_arguments (int argc, char **argv)
300 server_port = HTTPS_PORT; 303 server_port = HTTPS_PORT;
301 break; 304 break;
302 case 'f': /* onredirect */ 305 case 'f': /* onredirect */
306 if (!strcmp (optarg, "stickyport"))
307 onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT;
303 if (!strcmp (optarg, "sticky")) 308 if (!strcmp (optarg, "sticky"))
304 onredirect = STATE_DEPENDENT, followsticky = 1; 309 onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST;
305 if (!strcmp (optarg, "follow")) 310 if (!strcmp (optarg, "follow"))
306 onredirect = STATE_DEPENDENT, followsticky = 0; 311 onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE;
307 if (!strcmp (optarg, "unknown")) 312 if (!strcmp (optarg, "unknown"))
308 onredirect = STATE_UNKNOWN; 313 onredirect = STATE_UNKNOWN;
309 if (!strcmp (optarg, "ok")) 314 if (!strcmp (optarg, "ok"))
@@ -1203,15 +1208,18 @@ redir (char *pos, char *status_line)
1203 free (host_name); 1208 free (host_name);
1204 host_name = strdup (addr); 1209 host_name = strdup (addr);
1205 1210
1206 if (followsticky == 0) { 1211 if (!(followsticky & STICKY_HOST)) {
1207 free (server_address); 1212 free (server_address);
1208 server_address = strdup (addr); 1213 server_address = strdup (addr);
1209 } 1214 }
1215 if (!(followsticky & STICKY_PORT)) {
1216 server_port = i;
1217 }
1210 1218
1211 free (server_url); 1219 free (server_url);
1212 server_url = url; 1220 server_url = url;
1213 1221
1214 if ((server_port = i) > MAX_PORT) 1222 if (server_port > MAX_PORT)
1215 die (STATE_UNKNOWN, 1223 die (STATE_UNKNOWN,
1216 _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"), 1224 _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"),
1217 MAX_PORT, server_type, server_address, server_port, server_url, 1225 MAX_PORT, server_type, server_address, server_port, server_url,
@@ -1343,9 +1351,9 @@ print_help (void)
1343 printf (" %s\n", _(" Any other tags to be sent in http header. Use multiple times for additional headers")); 1351 printf (" %s\n", _(" Any other tags to be sent in http header. Use multiple times for additional headers"));
1344 printf (" %s\n", "-L, --link"); 1352 printf (" %s\n", "-L, --link");
1345 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); 1353 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
1346 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky>"); 1354 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
1347 printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); 1355 printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the"));
1348 printf (" %s\n", _("specified IP address")); 1356 printf (" %s\n", _("specified IP address. stickyport also ensure post stays the same."));
1349 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); 1357 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>");
1350 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); 1358 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)"));
1351 1359
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index b0df960c..88b77d3b 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -125,11 +125,11 @@ sub run_server {
125 } elsif ($r->url->path eq "/redirect") { 125 } elsif ($r->url->path eq "/redirect") {
126 $c->send_redirect( "/redirect2" ); 126 $c->send_redirect( "/redirect2" );
127 } elsif ($r->url->path eq "/redir_external") { 127 } elsif ($r->url->path eq "/redir_external") {
128 $c->send_redirect( "http://169.254.169.254/redirect2" ); 128 $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" );
129 } elsif ($r->url->path eq "/redirect2") { 129 } elsif ($r->url->path eq "/redirect2") {
130 $c->send_basic_header; 130 $c->send_basic_header;
131 $c->send_crlf; 131 $c->send_crlf;
132 $c->send_response("redirected"); 132 $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' ));
133 } elsif ($r->url->path eq "/redir_timeout") { 133 } elsif ($r->url->path eq "/redir_timeout") {
134 $c->send_redirect( "/timeout" ); 134 $c->send_redirect( "/timeout" );
135 } elsif ($r->url->path eq "/timeout") { 135 } elsif ($r->url->path eq "/timeout") {
@@ -157,7 +157,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
157 } 157 }
158} 158}
159 159
160my $common_tests = 55; 160my $common_tests = 62;
161my $ssl_only_tests = 6; 161my $ssl_only_tests = 6;
162if (-x "./check_http") { 162if (-x "./check_http") {
163 plan tests => $common_tests * 2 + $ssl_only_tests; 163 plan tests => $common_tests * 2 + $ssl_only_tests;
@@ -181,7 +181,6 @@ SKIP: {
181 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 181 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
182 like( $result->output, '/WARNING - Certificate expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); 182 like( $result->output, '/WARNING - Certificate expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
183 183
184
185 # Expired cert tests 184 # Expired cert tests
186 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 185 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
187 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 186 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
@@ -316,7 +315,6 @@ sub run_common_tests {
316 is( $result->return_code, 0, $cmd); 315 is( $result->return_code, 0, $cmd);
317 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 316 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
318 317
319
320 $cmd = "$command -u /redirect -k 'follow: me'"; 318 $cmd = "$command -u /redirect -k 'follow: me'";
321 $result = NPTest->testCmd( $cmd ); 319 $result = NPTest->testCmd( $cmd );
322 is( $result->return_code, 0, $cmd); 320 is( $result->return_code, 0, $cmd);
@@ -327,25 +325,50 @@ sub run_common_tests {
327 is( $result->return_code, 0, $cmd); 325 is( $result->return_code, 0, $cmd);
328 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 326 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
329 327
328 $cmd = "$command -f sticky -u /redirect -k 'follow: me'";
329 $result = NPTest->testCmd( $cmd );
330 is( $result->return_code, 0, $cmd);
331 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
332
333 $cmd = "$command -f stickyport -u /redirect -k 'follow: me'";
334 $result = NPTest->testCmd( $cmd );
335 is( $result->return_code, 0, $cmd);
336 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
337
330 # These tests may block 338 # These tests may block
331 print "ALRM\n"; 339 print "ALRM\n";
332 340
333 $cmd = "$command -f sticky -u /redir_external -t 5"; 341 # stickyport - on full urlS port is set back to 80 otherwise
342 $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected";
334 eval { 343 eval {
335 local $SIG{ALRM} = sub { die "alarm\n" }; 344 local $SIG{ALRM} = sub { die "alarm\n" };
336 alarm(2); 345 alarm(2);
337 $result = NPTest->testCmd( $cmd ); 346 $result = NPTest->testCmd( $cmd );
338 alarm(0); }; 347 alarm(0); };
339 isnt( $@, "alarm\n", $cmd); 348 isnt( $@, "alarm\n", $cmd );
349 is( $result->return_code, 0, $cmd );
340 350
341 # Will this one work everywhere??? 351 # Let's hope there won't be any web server on :80 returning "redirected"!
342 $cmd = "$command -f follow -u /redir_external -t 5"; 352 $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected";
343 eval { 353 eval {
344 local $SIG{ALRM} = sub { die "alarm\n" }; 354 local $SIG{ALRM} = sub { die "alarm\n" };
345 alarm(2); 355 alarm(2);
346 $result = NPTest->testCmd( $cmd ); 356 $result = NPTest->testCmd( $cmd );
347 alarm(0); }; 357 alarm(0); };
348 is( $@, "alarm\n", $cmd); 358 isnt( $@, "alarm\n", $cmd );
359 isnt( $result->return_code, 0, $cmd );
360
361 # Test an external address - timeout
362 SKIP: {
363 skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
364 $cmd = "$command -f follow -u /redir_external -t 5";
365 eval {
366 local $SIG{ALRM} = sub { die "alarm\n" };
367 alarm(2);
368 $result = NPTest->testCmd( $cmd );
369 alarm(0); };
370 is( $@, "alarm\n", $cmd );
371 }
349 372
350 $cmd = "$command -u /timeout -t 5"; 373 $cmd = "$command -u /timeout -t 5";
351 eval { 374 eval {
@@ -353,7 +376,7 @@ sub run_common_tests {
353 alarm(2); 376 alarm(2);
354 $result = NPTest->testCmd( $cmd ); 377 $result = NPTest->testCmd( $cmd );
355 alarm(0); }; 378 alarm(0); };
356 is( $@, "alarm\n", $cmd); 379 is( $@, "alarm\n", $cmd );
357 380
358 $cmd = "$command -f follow -u /redir_timeout -t 2"; 381 $cmd = "$command -f follow -u /redir_timeout -t 2";
359 eval { 382 eval {
@@ -361,6 +384,7 @@ sub run_common_tests {
361 alarm(5); 384 alarm(5);
362 $result = NPTest->testCmd( $cmd ); 385 $result = NPTest->testCmd( $cmd );
363 alarm(0); }; 386 alarm(0); };
364 isnt( $@, "alarm\n", $cmd); 387 isnt( $@, "alarm\n", $cmd );
365 388
366} 389}
390