aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@nierlein.de> 2021-04-09 08:54:15 +0200
committerGravatar GitHub <noreply@github.com> 2021-04-09 08:54:15 +0200
commit5c1d2efd687eaef33b61e4d20706be9fadc0be6a (patch)
treec1d52be490b59218333d113128aa3c5612e4c4db /plugins/check_curl.c
parentf6fd14e886e2c5f6bf141e9542cf6212a1a6f5b5 (diff)
parentcd358cd08a6ddceece836788078ec96b5f8eb0c5 (diff)
downloadmonitoring-plugins-5c1d2efd687eaef33b61e4d20706be9fadc0be6a.tar.gz
Merge pull request #1671 from monitoring-plugins/feature_check_curl
Feature check curl
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 8125ee84..99833f6f 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -117,7 +117,7 @@ typedef enum curlhelp_ssl_library {
enum {
REGS = 2,
- MAX_RE_SIZE = 256
+ MAX_RE_SIZE = 1024
};
#include "regex.h"
regex_t preg;
@@ -145,6 +145,7 @@ thresholds *thlds;
char user_agent[DEFAULT_BUFFER_SIZE];
int verbose = 0;
int show_extended_perfdata = FALSE;
+int show_body = FALSE;
int min_page_len = 0;
int max_page_len = 0;
int redir_depth = 0;
@@ -792,7 +793,9 @@ GOT_FIRST_CERT:
snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line);
else
snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line);
- die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
+ die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg,
+ show_body ? "\n" : "",
+ show_body ? body_buf.buf : "");
}
if( server_expect_yn ) {
@@ -921,13 +924,15 @@ GOT_FIRST_CERT:
msg[strlen(msg)-3] = '\0';
/* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */
- die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n",
+ die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s",
state_text(result), string_statuscode (status_line.http_major, status_line.http_minor),
status_line.http_code, status_line.msg,
strlen(msg) > 0 ? " - " : "",
msg, page_len, total_time,
(display_html ? "</A>" : ""),
- perfstring);
+ perfstring,
+ (show_body ? body_buf.buf : ""),
+ (show_body ? "\n" : "") );
/* proper cleanup after die? */
curlhelp_free_statusline(&status_line);
@@ -1173,6 +1178,7 @@ process_arguments (int argc, char **argv)
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{"extended-perfdata", no_argument, 0, 'E'},
+ {"show-body", no_argument, 0, 'B'},
{"http-version", required_argument, 0, HTTP_VERSION_OPTION},
{0, 0, 0, 0}
};
@@ -1197,7 +1203,7 @@ process_arguments (int argc, char **argv)
server_url = strdup(DEFAULT_SERVER_URL);
while (1) {
- 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:J:K:DnlLS::m:M:NE", 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:J:K:DnlLS::m:M:NEB", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
@@ -1545,6 +1551,9 @@ process_arguments (int argc, char **argv)
case 'E': /* show extended perfdata */
show_extended_perfdata = TRUE;
break;
+ case 'B': /* print body content after status line */
+ show_body = TRUE;
+ break;
case HTTP_VERSION_OPTION:
curl_http_version = CURL_HTTP_VERSION_NONE;
if (strcmp (optarg, "1.0") == 0) {
@@ -1757,6 +1766,8 @@ print_help (void)
printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers"));
printf (" %s\n", "-E, --extended-perfdata");
printf (" %s\n", _("Print additional performance data"));
+ printf (" %s\n", "-B, --show-body");
+ printf (" %s\n", _("Print body content below status line"));
printf (" %s\n", "-L, --link");
printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport|curl>");
@@ -1852,10 +1863,16 @@ print_usage (void)
printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\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 (" [-A string] [-k string] [-S <version>] [--sni]\n");
printf (" [-T <content-type>] [-j method]\n");
printf (" [--http-version=<version>]\n");
+ printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
+ printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
printf ("\n");
+#ifdef LIBCURL_FEATURE_SSL
+ printf ("%s\n", _("In the first form, make an HTTP request."));
+ printf ("%s\n\n", _("In the second form, connect to the server and check the TLS certificate."));
+#endif
printf ("%s\n", _("WARNING: check_curl is experimental. Please use"));
printf ("%s\n\n", _("check_http if you need a stable version."));
}