summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 67d89129..3f44c86b 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -273,9 +273,17 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state
273 273
274 /* Curl errors, result in critical Nagios state */ 274 /* Curl errors, result in critical Nagios state */
275 if (res != CURLE_OK) { 275 if (res != CURLE_OK) {
276 xasprintf(&sc_curl.output, _("Error while performing connection: cURL returned %d - %s"), 276 /* Custom handling for timeouts, state might be set to non CRITICAL */
277 res, errbuf[0] ? errbuf : curl_easy_strerror(res)); 277 if (res == CURLE_OPERATION_TIMEDOUT) {
278 sc_curl = mp_set_subcheck_state(sc_curl, STATE_CRITICAL); 278 xasprintf(&sc_curl.output, _("cURL returned %d - %s"), res,
279 errbuf[0] ? errbuf : curl_easy_strerror(res));
280 sc_curl = mp_set_subcheck_state(sc_curl, config.on_timeout_result_state);
281 } else {
282 xasprintf(&sc_curl.output,
283 _("Error while performing connection: cURL returned %d - %s"), res,
284 errbuf[0] ? errbuf : curl_easy_strerror(res));
285 sc_curl = mp_set_subcheck_state(sc_curl, STATE_CRITICAL);
286 }
279 mp_add_subcheck_to_subcheck(&sc_result, sc_curl); 287 mp_add_subcheck_to_subcheck(&sc_result, sc_curl);
280 return sc_result; 288 return sc_result;
281 } 289 }
@@ -890,6 +898,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
890 STATE_REGEX, 898 STATE_REGEX,
891 OUTPUT_FORMAT, 899 OUTPUT_FORMAT,
892 NO_PROXY, 900 NO_PROXY,
901 TIMEOUT_RESULT,
893 }; 902 };
894 903
895 static struct option longopts[] = { 904 static struct option longopts[] = {
@@ -939,6 +948,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
939 {"cookie-jar", required_argument, 0, COOKIE_JAR}, 948 {"cookie-jar", required_argument, 0, COOKIE_JAR},
940 {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL}, 949 {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL},
941 {"output-format", required_argument, 0, OUTPUT_FORMAT}, 950 {"output-format", required_argument, 0, OUTPUT_FORMAT},
951 {"timeout-result", required_argument, 0, TIMEOUT_RESULT},
942 {0, 0, 0, 0}}; 952 {0, 0, 0, 0}};
943 953
944 check_curl_config_wrapper result = { 954 check_curl_config_wrapper result = {
@@ -1004,6 +1014,21 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
1004 result.config.curl_config.socket_timeout = (int)strtol(optarg, NULL, 10); 1014 result.config.curl_config.socket_timeout = (int)strtol(optarg, NULL, 10);
1005 } 1015 }
1006 break; 1016 break;
1017 case TIMEOUT_RESULT:
1018 if (!strcmp(optarg, "0") || !strcasecmp(optarg, "ok")) {
1019 result.config.on_timeout_result_state = STATE_OK;
1020 } else if (!strcmp(optarg, "1") || !strcasecmp(optarg, "warning")) {
1021 result.config.on_timeout_result_state = STATE_WARNING;
1022 } else if (!strcmp(optarg, "2") || !strcasecmp(optarg, "critical")) {
1023 result.config.on_timeout_result_state = STATE_CRITICAL;
1024 } else if (!strcmp(optarg, "3") || !strcasecmp(optarg, "unknown")) {
1025 result.config.on_timeout_result_state = STATE_UNKNOWN;
1026 } else {
1027 usage2(_("Invalid timeout-result state option, give either a return code or state "
1028 "name in lowercase"),
1029 optarg);
1030 }
1031 break;
1007 case 'c': /* critical time threshold */ 1032 case 'c': /* critical time threshold */
1008 { 1033 {
1009 mp_range_parsed critical_range = mp_parse_range_string(optarg); 1034 mp_range_parsed critical_range = mp_parse_range_string(optarg);
@@ -1701,6 +1726,10 @@ void print_help(void) {
1701 1726
1702 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 1727 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
1703 1728
1729 printf(" %s\n", "--timeout-result=ok|warning|critical|unknown|0|1|2|3");
1730 printf(" %s\n", _("Timeouts default to returning STATE_CRITICAL."));
1731 printf(" %s\n", _("This argument changes the return state on timeouts."));
1732
1704 printf(UT_VERBOSE); 1733 printf(UT_VERBOSE);
1705 1734
1706 printf(UT_OUTPUT_FORMAT); 1735 printf(UT_OUTPUT_FORMAT);