[monitoring-plugins] Updated check_curl.c to display a specific ...
Jan Wagner
git at monitoring-plugins.org
Wed Apr 7 18:10:12 CEST 2021
Module: monitoring-plugins
Branch: wip-2.3.1
Commit: ee6187d01b40bc45afe81c97e4f20c890fe89173
Author: Barak Shohat <barak at bazzisoft.com>
Committer: Jan Wagner <waja at cyconet.org>
Date: Tue Apr 6 16:35:20 2021 +0300
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=ee6187d
Updated check_curl.c to display a specific human-readable error message where possible
---
plugins/check_curl.c | 6 +++---
plugins/t/check_curl.t | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 9f1eafa..ee9c8b1 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -313,8 +313,8 @@ static char *string_statuscode (int major, int minor)
/* assuming here HTTP/N with N>=4 */
snprintf (buf, sizeof (buf), "HTTP/%d", major);
break;
- }
-
+ }
+
return buf;
}
@@ -662,7 +662,7 @@ check_http (void)
/* Curl errors, result in critical Nagios state */
if (res != CURLE_OK) {
snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"),
- server_port, res, curl_easy_strerror(res));
+ server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res));
die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
}
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t
index 4bff538..cc65f03 100644
--- a/plugins/t/check_curl.t
+++ b/plugins/t/check_curl.t
@@ -46,7 +46,7 @@ $res = NPTest->testCmd(
);
cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
# was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!)
-cmp_ok( $res->output, 'eq', "HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Timeout was reached", "Output OK");
+like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK");
$res = NPTest->testCmd(
"./$plugin $hostname_invalid -wt 1 -ct 2"
@@ -56,7 +56,7 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename
# Is also possible to get a socket timeout if DNS is not responding fast enough
# cURL gives us consistent strings from it's own 'lib/strerror.c'
-like( $res->output, "/cURL returned 6 - Couldn't resolve host name/", "Output OK");
+like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK");
# host header checks
$res = NPTest->testCmd("./$plugin -v -H $host_tcp_http");
More information about the Commits
mailing list