mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-13 18:50:01 -04:00
added ability to check regex against http headers. booyah!
This commit is contained in:
parent
0eeb8cde67
commit
2a8eab6b31
2 changed files with 33 additions and 2 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ sub run_server {
|
|||
unshift @persist, $c;
|
||||
delete($persist[1000]);
|
||||
next MAINLOOP;
|
||||
} elsif ($r->url->path eq "/header_check") {
|
||||
$c->send_basic_header;
|
||||
$c->send_header('foo');
|
||||
$c->send_crlf;
|
||||
} else {
|
||||
$c->send_error(HTTP::Status->RC_FORBIDDEN);
|
||||
}
|
||||
|
|
@ -223,6 +227,13 @@ sub run_common_tests {
|
|||
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");
|
||||
|
||||
$result = NPTest->testCmd( "$command -u /header_check -d foo" );
|
||||
is( $result->return_code, 0, "header_check 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 /header_check -d foobar" );
|
||||
is( $result->return_code, 2, "Missing header string check");
|
||||
like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'foobar' not found on 'https?://127\.0\.0\.1:\d+/header_check/root'%, "Shows search string and location");
|
||||
|
||||
my $cmd;
|
||||
$cmd = "$command -u /slow";
|
||||
|
|
|
|||
Loading…
Reference in a new issue