SF.net SVN: nagiosplug:[2180] nagiosplug/trunk

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 2180
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2180&view=rev
Author:   dermoth
Date:     2009-03-21 06:41:16 +0000 (Sat, 21 Mar 2009)

Log Message:
-----------
check_http: add --onredirect=stickyport - also follow the same port

From: Thomas Guyot-Sionnest <[email protected]>

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/plugins/check_http.c
    nagiosplug/trunk/plugins/tests/check_http.t

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2009-03-20 07:00:35 UTC (rev 2179)
+++ nagiosplug/trunk/NEWS	2009-03-21 06:41:16 UTC (rev 2180)
@@ -21,6 +21,7 @@
 	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)

Modified: nagiosplug/trunk/plugins/check_http.c
===================================================================
--- nagiosplug/trunk/plugins/check_http.c	2009-03-20 07:00:35 UTC (rev 2179)
+++ nagiosplug/trunk/plugins/check_http.c	2009-03-21 06:41:16 UTC (rev 2180)
@@ -44,6 +44,9 @@
 #include <ctype.h>
 
 #define INPUT_DELIMITER ";"
+#define STICKY_NONE 0
+#define STICKY_HOST 1
+#define STICKY_PORT 2
 
 #define HTTP_EXPECT "HTTP/1."
 enum {
@@ -106,7 +109,7 @@
 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;
@@ -300,10 +303,12 @@
         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"))
@@ -1203,15 +1208,18 @@
   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,
@@ -1343,9 +1351,9 @@
   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)"));
 

Modified: nagiosplug/trunk/plugins/tests/check_http.t
===================================================================
--- nagiosplug/trunk/plugins/tests/check_http.t	2009-03-20 07:00:35 UTC (rev 2179)
+++ nagiosplug/trunk/plugins/tests/check_http.t	2009-03-21 06:41:16 UTC (rev 2180)
@@ -125,11 +125,11 @@
 			} 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") {
@@ -157,7 +157,7 @@
 	}
 }
 
-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;
@@ -181,7 +181,6 @@
 	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" );
@@ -316,7 +315,6 @@
 	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);
@@ -327,33 +325,58 @@
 	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 {
 		local $SIG{ALRM} = sub { die "alarm\n" };
 		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 {
@@ -361,6 +384,7 @@
 		alarm(5);
 		$result = NPTest->testCmd( $cmd );
 		alarm(0); };
-	isnt( $@, "alarm\n", $cmd);
+	isnt( $@, "alarm\n", $cmd );
 
 }
+


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.