aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_http.c
diff options
context:
space:
mode:
authorGravatar linkslice <sparctacus@gmail.com> 2012-06-06 21:35:34 -0700
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2013-08-18 18:23:11 +0200
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 6db38e8c..52040281 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -100,7 +100,9 @@ char *user_agent;
int server_url_length;
int server_expect_yn = 0;
char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
+char header_expect[MAX_INPUT_BUFFER] = "";
char string_expect[MAX_INPUT_BUFFER] = "";
+char output_header_search[30] = "";
char output_string_search[30] = "";
char *warning_thresholds = NULL;
char *critical_thresholds = NULL;
@@ -205,6 +207,7 @@ process_arguments (int argc, char **argv)
{"port", required_argument, 0, 'p'},
{"authorization", required_argument, 0, 'a'},
{"proxy_authorization", required_argument, 0, 'b'},
+ {"header_string", required_argument, 0, 'd'},
{"string", required_argument, 0, 's'},
{"expect", required_argument, 0, 'e'},
{"regex", required_argument, 0, 'r'},
@@ -243,7 +246,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:b:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option);
+ 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);
if (c == -1 || c == EOF)
break;
@@ -392,6 +395,10 @@ process_arguments (int argc, char **argv)
free(http_method);
http_method = strdup (optarg);
break;
+ case 'd': /* string or substring */
+ strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
+ header_expect[MAX_INPUT_BUFFER - 1] = 0;
+ break;
case 's': /* string or substring */
strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
string_expect[MAX_INPUT_BUFFER - 1] = 0;
@@ -1085,6 +1092,17 @@ check_http (void)
}
/* Page and Header content checks go here */
+ if (strlen (header_expect)) {
+ if (!strstr (header, header_expect)) {
+ strncpy(&output_header_search[0],header_expect,sizeof(output_header_search));
+ if(output_header_search[sizeof(output_header_search)-1]!='\0') {
+ bcopy("...",&output_header_search[sizeof(output_header_search)-4],4);
+ }
+ 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);
+ result = STATE_CRITICAL;
+ }
+ }
+
if (strlen (string_expect)) {
if (!strstr (page, string_expect)) {
@@ -1434,6 +1452,8 @@ print_help (void)
printf (" %s", _("the first (status) line of the server response (default: "));
printf ("%s)\n", HTTP_EXPECT);
printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
+ printf (" %s\n", "-d, --header-string=STRING");
+ printf (" %s\n", _("String to expect in the response headers"));
printf (" %s\n", "-s, --string=STRING");
printf (" %s\n", _("String to expect in the content"));
printf (" %s\n", "-u, --url=PATH");
@@ -1535,7 +1555,7 @@ print_usage (void)
printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n");
printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
- printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
+ printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n");
printf (" [-T <content-type>] [-j method]\n");