Code

Display missing search string and URL when failed (Duncan Ferguson #2999924)
authortonvoon <ton.voon@opsview.com>
Wed, 23 Jun 2010 14:44:34 +0000 (14:44 +0000)
committertonvoon <ton.voon@opsview.com>
Wed, 23 Jun 2010 14:44:34 +0000 (14:44 +0000)
NEWS
plugins/check_http.c
plugins/tests/check_http.t

diff --git a/NEWS b/NEWS
index c2917c1969563967d063810f1b0fe007ccb8028b..7211b14a94c172b61b4cb9b030d58571c6f81dd1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ This file documents the major additions and syntax changes between releases.
        New check_radius -N option which allows for specifying the value of the NAS-IP-Address attribute
        New check_snmp --rate option to store differences between invocations. Saves state in PREFIX/var/{plugin}
        check_snmp -l label option now also changes the perfdata label. See WARNINGS
        New check_radius -N option which allows for specifying the value of the NAS-IP-Address attribute
        New check_snmp --rate option to store differences between invocations. Saves state in PREFIX/var/{plugin}
        check_snmp -l label option now also changes the perfdata label. See WARNINGS
+       check_http now displays the missing search string and the URL in the output when failed (Duncan Ferguson - #2999924)
        Updated Nagios::Plugin perl module
        Updated gnulib to June 2010
        FIXES
        Updated Nagios::Plugin perl module
        Updated gnulib to June 2010
        FIXES
index 7f773c83fd5a4aaa3f6c947133ff3d7a5eb7d7df..f08ad17cd9e0838e25cc75604fdaeb4c06787bf7 100644 (file)
@@ -100,6 +100,7 @@ int server_url_length;
 int server_expect_yn = 0;
 char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
 char string_expect[MAX_INPUT_BUFFER] = "";
 int server_expect_yn = 0;
 char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
 char string_expect[MAX_INPUT_BUFFER] = "";
+char output_string_search[30] = "";
 double warning_time = 0;
 int check_warning_time = FALSE;
 double critical_time = 0;
 double warning_time = 0;
 int check_warning_time = FALSE;
 double critical_time = 0;
@@ -1037,7 +1038,11 @@ check_http (void)
 
   if (strlen (string_expect)) {
     if (!strstr (page, string_expect)) {
 
   if (strlen (string_expect)) {
     if (!strstr (page, string_expect)) {
-      asprintf (&msg, _("%sstring not found, "), msg);
+      strncpy(&output_string_search[0],string_expect,sizeof(output_string_search));
+      if(output_string_search[sizeof(output_string_search)-1]!='\0') {
+        bcopy("...",&output_string_search[sizeof(output_string_search)-4],4);
+      }
+      asprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
       result = STATE_CRITICAL;
     }
   }
       result = STATE_CRITICAL;
     }
   }
index 88b77d3b8cd7b662a8ebe99045451edd8d18f3e2..f03933bd39236ad29308cabacc512d73bde42d9a 100755 (executable)
@@ -157,7 +157,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
        }
 }
 
        }
 }
 
-my $common_tests = 62;
+my $common_tests = 66;
 my $ssl_only_tests = 6;
 if (-x "./check_http") {
        plan tests => $common_tests * 2 + $ssl_only_tests;
 my $ssl_only_tests = 6;
 if (-x "./check_http") {
        plan tests => $common_tests * 2 + $ssl_only_tests;
@@ -205,6 +205,14 @@ sub run_common_tests {
        is( $result->return_code, 0, "/file/root search for string");
        like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
 
        is( $result->return_code, 0, "/file/root search for string");
        like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
 
+       $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" );
+       is( $result->return_code, 2, "Missing string check");
+       like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
+
+       $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" );
+       is( $result->return_code, 2, "Missing string check");
+       like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
+
 
        my $cmd;
        $cmd = "$command -u /slow";
 
        my $cmd;
        $cmd = "$command -u /slow";