diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index e4230dc..4a62c1d 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -90,6 +90,7 @@ char *server_address; | |||
90 | char *host_name; | 90 | char *host_name; |
91 | char *server_url = DEFAULT_SERVER_URL; | 91 | char *server_url = DEFAULT_SERVER_URL; |
92 | unsigned short server_port = DEFAULT_HTTP_PORT; | 92 | unsigned short server_port = DEFAULT_HTTP_PORT; |
93 | char output_string_search[30] = ""; | ||
93 | char *warning_thresholds = NULL; | 94 | char *warning_thresholds = NULL; |
94 | char *critical_thresholds = NULL; | 95 | char *critical_thresholds = NULL; |
95 | thresholds *thlds; | 96 | thresholds *thlds; |
@@ -109,6 +110,7 @@ CURLcode res; | |||
109 | char url[DEFAULT_BUFFER_SIZE]; | 110 | char url[DEFAULT_BUFFER_SIZE]; |
110 | char msg[DEFAULT_BUFFER_SIZE]; | 111 | char msg[DEFAULT_BUFFER_SIZE]; |
111 | char perfstring[DEFAULT_BUFFER_SIZE]; | 112 | char perfstring[DEFAULT_BUFFER_SIZE]; |
113 | char string_expect[MAX_INPUT_BUFFER] = ""; | ||
112 | char user_auth[MAX_INPUT_BUFFER] = ""; | 114 | char user_auth[MAX_INPUT_BUFFER] = ""; |
113 | int onredirect = STATE_OK; | 115 | int onredirect = STATE_OK; |
114 | int use_ssl = FALSE; | 116 | int use_ssl = FALSE; |
@@ -246,18 +248,6 @@ main (int argc, char **argv) | |||
246 | //~ curl_easy_setopt( curl, CURLOPT_CAINFO, args_info.cacert_arg ); | 248 | //~ curl_easy_setopt( curl, CURLOPT_CAINFO, args_info.cacert_arg ); |
247 | //~ } | 249 | //~ } |
248 | 250 | ||
249 | /* TODO: old option -s: check if the excepted string matches */ | ||
250 | //~ if( args_info.string_given ) { | ||
251 | //~ if( strstr( body_buf.buf, args_info.string_arg ) == NULL ) { | ||
252 | //~ printf( "HTTP CRITICAL - string not found|%s\n", perfstring ); | ||
253 | //~ curl_easy_cleanup( curl ); | ||
254 | //~ curl_global_cleanup( ); | ||
255 | //~ curlhelp_freebuffer( &body_buf ); | ||
256 | //~ curlhelp_freebuffer( &header_buf ); | ||
257 | //~ exit( STATE_CRITICAL ); | ||
258 | //~ } | ||
259 | //~ } | ||
260 | |||
261 | /* handle redirections */ | 251 | /* handle redirections */ |
262 | if (onredirect == STATE_DEPENDENT) { | 252 | if (onredirect == STATE_DEPENDENT) { |
263 | curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1); | 253 | curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1); |
@@ -280,7 +270,7 @@ main (int argc, char **argv) | |||
280 | remove_newlines (errbuf); | 270 | remove_newlines (errbuf); |
281 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), | 271 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), |
282 | server_port, status_line.msg, status_line.msg); | 272 | server_port, status_line.msg, status_line.msg); |
283 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", errbuf); | 273 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
284 | } | 274 | } |
285 | 275 | ||
286 | /* we got the data and we executed the request in a given time, so we can append | 276 | /* we got the data and we executed the request in a given time, so we can append |
@@ -334,8 +324,9 @@ main (int argc, char **argv) | |||
334 | code = status_line.http_code; | 324 | code = status_line.http_code; |
335 | } | 325 | } |
336 | result = max_state_alt (onredirect, result); | 326 | result = max_state_alt (onredirect, result); |
337 | // TODO: make sure the last status line has been | 327 | /* TODO: make sure the last status line has been |
338 | // parsed into the status_line structure | 328 | parsed into the status_line structure |
329 | */ | ||
339 | /* all other codes are considered ok */ | 330 | /* all other codes are considered ok */ |
340 | } else { | 331 | } else { |
341 | result = STATE_OK; | 332 | result = STATE_OK; |
@@ -348,13 +339,25 @@ main (int argc, char **argv) | |||
348 | status_line.http_code, status_line.msg, code); | 339 | status_line.http_code, status_line.msg, code); |
349 | } | 340 | } |
350 | 341 | ||
342 | /* Page and Header content checks go here */ | ||
343 | if (strlen (string_expect)) { | ||
344 | if (!strstr (body_buf.buf, string_expect)) { | ||
345 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); | ||
346 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { | ||
347 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); | ||
348 | } | ||
349 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%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); | ||
350 | result = STATE_CRITICAL; | ||
351 | } | ||
352 | } | ||
353 | |||
351 | /* -w, -c: check warning and critical level */ | 354 | /* -w, -c: check warning and critical level */ |
352 | result = max_state_alt(get_status(total_time, thlds), result); | 355 | result = max_state_alt(get_status(total_time, thlds), result); |
353 | 356 | ||
354 | //~ die (result, "HTTP %s: %s\n", state_text(result), msg); | 357 | //~ die (result, "HTTP %s: %s\n", state_text(result), msg); |
355 | die (result, "HTTP %s HTTP/%d.%d %d %s - %.3g seconds response time|%s\n", | 358 | die (result, "HTTP %s HTTP/%d.%d %d %s - %s - %.3g seconds response time|%s\n", |
356 | state_text(result), status_line.http_major, status_line.http_minor, | 359 | state_text(result), status_line.http_major, status_line.http_minor, |
357 | status_line.http_code, status_line.msg, | 360 | status_line.http_code, status_line.msg, msg, |
358 | total_time, perfstring); | 361 | total_time, perfstring); |
359 | 362 | ||
360 | /* proper cleanup after die? */ | 363 | /* proper cleanup after die? */ |
@@ -393,6 +396,7 @@ process_arguments (int argc, char **argv) | |||
393 | {"url", required_argument, 0, 'u'}, | 396 | {"url", required_argument, 0, 'u'}, |
394 | {"port", required_argument, 0, 'p'}, | 397 | {"port", required_argument, 0, 'p'}, |
395 | {"authorization", required_argument, 0, 'a'}, | 398 | {"authorization", required_argument, 0, 'a'}, |
399 | {"string", required_argument, 0, 's'}, | ||
396 | {"onredirect", required_argument, 0, 'f'}, | 400 | {"onredirect", required_argument, 0, 'f'}, |
397 | {"client-cert", required_argument, 0, 'J'}, | 401 | {"client-cert", required_argument, 0, 'J'}, |
398 | {"private-key", required_argument, 0, 'K'}, | 402 | {"private-key", required_argument, 0, 'K'}, |
@@ -405,7 +409,7 @@ process_arguments (int argc, char **argv) | |||
405 | usage ("\n"); | 409 | usage ("\n"); |
406 | 410 | ||
407 | while (1) { | 411 | while (1) { |
408 | c = getopt_long (argc, argv, "Vvht:c:w:A:H:I:a:p:u:f:C:J:K:S::", longopts, &option); | 412 | c = getopt_long (argc, argv, "Vvht:c:w:A:H:I:a:p:s:u:f:C:J:K:S::", longopts, &option); |
409 | if (c == -1 || c == EOF || c == 1) | 413 | if (c == -1 || c == EOF || c == 1) |
410 | break; | 414 | break; |
411 | 415 | ||
@@ -532,6 +536,10 @@ process_arguments (int argc, char **argv) | |||
532 | if (verbose >= 2) | 536 | if (verbose >= 2) |
533 | printf(_("* Following redirects set to %s\n"), state_text(onredirect)); | 537 | printf(_("* Following redirects set to %s\n"), state_text(onredirect)); |
534 | break; | 538 | break; |
539 | case 's': /* string or substring */ | ||
540 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); | ||
541 | string_expect[MAX_INPUT_BUFFER - 1] = 0; | ||
542 | break; | ||
535 | case '?': | 543 | case '?': |
536 | /* print short usage statement if args not parsable */ | 544 | /* print short usage statement if args not parsable */ |
537 | usage5 (); | 545 | usage5 (); |
@@ -578,6 +586,7 @@ print_help (void) | |||
578 | { | 586 | { |
579 | print_revision(progname, NP_VERSION); | 587 | print_revision(progname, NP_VERSION); |
580 | 588 | ||
589 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | ||
581 | printf ("Copyright (c) 2017 Andreas Baumann <abaumann@yahoo.com>\n"); | 590 | printf ("Copyright (c) 2017 Andreas Baumann <abaumann@yahoo.com>\n"); |
582 | printf (COPYRIGHT, copyright, email); | 591 | printf (COPYRIGHT, copyright, email); |
583 | 592 | ||
@@ -633,6 +642,8 @@ print_help (void) | |||
633 | printf (" %s\n", _("matching the client certificate")); | 642 | printf (" %s\n", _("matching the client certificate")); |
634 | #endif | 643 | #endif |
635 | 644 | ||
645 | printf (" %s\n", "-s, --string=STRING"); | ||
646 | printf (" %s\n", _("String to expect in the content")); | ||
636 | printf (" %s\n", "-u, --url=PATH"); | 647 | printf (" %s\n", "-u, --url=PATH"); |
637 | printf (" %s\n", _("URL to GET or POST (default: /)")); | 648 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
638 | 649 | ||