summaryrefslogtreecommitdiffstats
path: root/web/attachments/376677-nagiosplug_check_http_search_string_in_not_found_output.patch
blob: ac18fe25366b6c930575917e907305bcc84f7ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 7f773c8..3fe6998 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -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 output_string_match = FALSE;
 double warning_time = 0;
 int check_warning_time = FALSE;
 double critical_time = 0;
@@ -198,6 +199,7 @@ process_arguments (int argc, char **argv)
     {"authorization", required_argument, 0, 'a'},
     {"proxy_authorization", required_argument, 0, 'b'},
     {"string", required_argument, 0, 's'},
+    {"output-string-match", no_argument, 0, 'o'},
     {"expect", required_argument, 0, 'e'},
     {"regex", required_argument, 0, 'r'},
     {"ereg", required_argument, 0, 'r'},
@@ -234,7 +236,7 @@ process_arguments (int argc, char **argv)
   }
 
   while (1) {
-    c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option);
+    c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:oR:r:u:f:C:nlLSm:M:N", longopts, &option);
     if (c == -1 || c == EOF)
       break;
 
@@ -377,6 +379,9 @@ process_arguments (int argc, char **argv)
       strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
       string_expect[MAX_INPUT_BUFFER - 1] = 0;
       break;
+    case 'o': /* output 'string' in STDOUT 'string not found' msg */
+      output_string_match = TRUE;
+      break;
     case 'e': /* string or substring */
       strncpy (server_expect, optarg, MAX_INPUT_BUFFER - 1);
       server_expect[MAX_INPUT_BUFFER - 1] = 0;
@@ -1037,7 +1042,11 @@ check_http (void)
 
   if (strlen (string_expect)) {
     if (!strstr (page, string_expect)) {
-      asprintf (&msg, _("%sstring not found, "), msg);
+      if(!output_string_match){
+        asprintf (&msg, _("%sstring not found, "), msg);
+      } else {
+        asprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, string_expect, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
+      }
       result = STATE_CRITICAL;
     }
   }
@@ -1346,6 +1355,8 @@ print_help (void)
   printf ("    %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
   printf (" %s\n", "-s, --string=STRING");
   printf ("    %s\n", _("String to expect in the content"));
+  printf (" %s\n", "-o, --output-string-match");
+  printf ("    %s\n", _("Show given string as 'string xxx not found' message"));
   printf (" %s\n", "-u, --url=PATH");
   printf ("    %s\n", _("URL to GET or POST (default: /)"));
   printf (" %s\n", "-P, --post=STRING");