[monitoring-plugins] check_curl: adopt output format from check_http
Sven Nierlein
git at monitoring-plugins.org
Sat Mar 18 23:50:12 CET 2017
Module: monitoring-plugins
Branch: feature_check_curl
Commit: 6e18c3c09672e40ffb6885e9b76429a972d364cd
Author: Sven Nierlein <sven at nierlein.de>
Date: Sat Mar 18 22:50:18 2017 +0100
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=6e18c3c
check_curl: adopt output format from check_http
---
plugins/check_curl.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 3d368c1..20ac5b7 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -332,15 +332,15 @@ check_http (void)
/* no-body */
if (no_body)
curl_easy_setopt (curl, CURLOPT_NOBODY, 1);
-
+
/* IPv4 or IPv6 forced DNS resolution */
if (address_family == AF_UNSPEC)
curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
else if (address_family == AF_INET)
curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
else if (address_family == AF_INET6)
- curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
-
+ curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
+
/* do the request */
res = curl_easy_perform(curl);
@@ -466,9 +466,9 @@ check_http (void)
}
else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
if (invert_regex == 0)
- snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found"), msg);
+ snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg);
else
- snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found"), msg);
+ snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg);
result = STATE_CRITICAL;
}
else {
@@ -495,11 +495,18 @@ check_http (void)
/* -w, -c: check warning and critical level */
result = max_state_alt(get_status(total_time, thlds), result);
+ /* Cut-off trailing characters */
+ if(msg[strlen(msg)-2] == ',')
+ msg[strlen(msg)-2] = '\0';
+ else
+ 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 HTTP/%d.%d %d %s - %s - %.3g seconds response time|%s\n",
+ die (result, "HTTP %s: HTTP/%d.%d %d %s%s%s - %d bytes in %.3f second response time |%s\n",
state_text(result), status_line.http_major, status_line.http_minor,
- status_line.http_code, status_line.msg, msg,
- total_time, perfstring);
+ status_line.http_code, status_line.msg,
+ strlen(msg) > 0 ? " - " : "",
+ msg, page_len, total_time, perfstring);
/* proper cleanup after die? */
curlhelp_free_statusline(&status_line);
More information about the Commits
mailing list