summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
authorlinkslice <sparctacus@gmail.com>2012-06-07 04:35:34 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-08-18 16:23:11 (GMT)
commit2a8eab6b31e0f461e52b504776caad6bb93b981f (patch)
tree087ab01032764d366d91849a619489b73d3c776c /plugins/check_http.c
parent0eeb8cde6756c1280f4925ba479d378541bbce04 (diff)
downloadmonitoring-plugins-2a8eab6b31e0f461e52b504776caad6bb93b981f.tar.gz
added ability to check regex against http headers. booyah!
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 6db38e8..5204028 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -100,7 +100,9 @@ char *user_agent;
100int server_url_length; 100int server_url_length;
101int server_expect_yn = 0; 101int server_expect_yn = 0;
102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; 102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
103char header_expect[MAX_INPUT_BUFFER] = "";
103char string_expect[MAX_INPUT_BUFFER] = ""; 104char string_expect[MAX_INPUT_BUFFER] = "";
105char output_header_search[30] = "";
104char output_string_search[30] = ""; 106char output_string_search[30] = "";
105char *warning_thresholds = NULL; 107char *warning_thresholds = NULL;
106char *critical_thresholds = NULL; 108char *critical_thresholds = NULL;
@@ -205,6 +207,7 @@ process_arguments (int argc, char **argv)
205 {"port", required_argument, 0, 'p'}, 207 {"port", required_argument, 0, 'p'},
206 {"authorization", required_argument, 0, 'a'}, 208 {"authorization", required_argument, 0, 'a'},
207 {"proxy_authorization", required_argument, 0, 'b'}, 209 {"proxy_authorization", required_argument, 0, 'b'},
210 {"header_string", required_argument, 0, 'd'},
208 {"string", required_argument, 0, 's'}, 211 {"string", required_argument, 0, 's'},
209 {"expect", required_argument, 0, 'e'}, 212 {"expect", required_argument, 0, 'e'},
210 {"regex", required_argument, 0, 'r'}, 213 {"regex", required_argument, 0, 'r'},
@@ -243,7 +246,7 @@ process_arguments (int argc, char **argv)
243 } 246 }
244 247
245 while (1) { 248 while (1) {
246 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option); 249 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option);
247 if (c == -1 || c == EOF) 250 if (c == -1 || c == EOF)
248 break; 251 break;
249 252
@@ -392,6 +395,10 @@ process_arguments (int argc, char **argv)
392 free(http_method); 395 free(http_method);
393 http_method = strdup (optarg); 396 http_method = strdup (optarg);
394 break; 397 break;
398 case 'd': /* string or substring */
399 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
400 header_expect[MAX_INPUT_BUFFER - 1] = 0;
401 break;
395 case 's': /* string or substring */ 402 case 's': /* string or substring */
396 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 403 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
397 string_expect[MAX_INPUT_BUFFER - 1] = 0; 404 string_expect[MAX_INPUT_BUFFER - 1] = 0;
@@ -1085,6 +1092,17 @@ check_http (void)
1085 } 1092 }
1086 1093
1087 /* Page and Header content checks go here */ 1094 /* Page and Header content checks go here */
1095 if (strlen (header_expect)) {
1096 if (!strstr (header, header_expect)) {
1097 strncpy(&output_header_search[0],header_expect,sizeof(output_header_search));
1098 if(output_header_search[sizeof(output_header_search)-1]!='\0') {
1099 bcopy("...",&output_header_search[sizeof(output_header_search)-4],4);
1100 }
1101 asprintf (&msg, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
1102 result = STATE_CRITICAL;
1103 }
1104 }
1105
1088 1106
1089 if (strlen (string_expect)) { 1107 if (strlen (string_expect)) {
1090 if (!strstr (page, string_expect)) { 1108 if (!strstr (page, string_expect)) {
@@ -1434,6 +1452,8 @@ print_help (void)
1434 printf (" %s", _("the first (status) line of the server response (default: ")); 1452 printf (" %s", _("the first (status) line of the server response (default: "));
1435 printf ("%s)\n", HTTP_EXPECT); 1453 printf ("%s)\n", HTTP_EXPECT);
1436 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); 1454 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
1455 printf (" %s\n", "-d, --header-string=STRING");
1456 printf (" %s\n", _("String to expect in the response headers"));
1437 printf (" %s\n", "-s, --string=STRING"); 1457 printf (" %s\n", "-s, --string=STRING");
1438 printf (" %s\n", _("String to expect in the content")); 1458 printf (" %s\n", _("String to expect in the content"));
1439 printf (" %s\n", "-u, --url=PATH"); 1459 printf (" %s\n", "-u, --url=PATH");
@@ -1535,7 +1555,7 @@ print_usage (void)
1535 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); 1555 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
1536 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n"); 1556 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n");
1537 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1557 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1538 printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1558 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1539 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1559 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1540 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1560 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n");
1541 printf (" [-T <content-type>] [-j method]\n"); 1561 printf (" [-T <content-type>] [-j method]\n");