mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-10 09:10:08 -04:00
add cli argument to return custom states on timeout
This commit is contained in:
parent
1211edf2ea
commit
4f35a424b9
4 changed files with 43 additions and 1 deletions
|
|
@ -271,6 +271,14 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state
|
|||
|
||||
mp_subcheck sc_curl = mp_subcheck_init();
|
||||
|
||||
/* Custom handling for timeouts */
|
||||
if (res == CURLE_OPERATION_TIMEDOUT) {
|
||||
xasprintf(&sc_curl.output, _("cURL got a timeout error"));
|
||||
sc_curl = mp_set_subcheck_state(sc_curl, config.on_timeout_result_state);
|
||||
mp_add_subcheck_to_subcheck(&sc_result, sc_curl);
|
||||
return sc_curl;
|
||||
}
|
||||
|
||||
/* Curl errors, result in critical Nagios state */
|
||||
if (res != CURLE_OK) {
|
||||
xasprintf(&sc_curl.output, _("Error while performing connection: cURL returned %d - %s"),
|
||||
|
|
@ -890,6 +898,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
|
|||
STATE_REGEX,
|
||||
OUTPUT_FORMAT,
|
||||
NO_PROXY,
|
||||
TIMEOUT_CUSTOM_RESULT_STATE,
|
||||
};
|
||||
|
||||
static struct option longopts[] = {
|
||||
|
|
@ -939,6 +948,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
|
|||
{"cookie-jar", required_argument, 0, COOKIE_JAR},
|
||||
{"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL},
|
||||
{"output-format", required_argument, 0, OUTPUT_FORMAT},
|
||||
{"timeout-custom-result-state", required_argument, 0, TIMEOUT_CUSTOM_RESULT_STATE},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_curl_config_wrapper result = {
|
||||
|
|
@ -1004,6 +1014,19 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.curl_config.socket_timeout = (int)strtol(optarg, NULL, 10);
|
||||
}
|
||||
break;
|
||||
case TIMEOUT_CUSTOM_RESULT_STATE:
|
||||
if (!strcmp(optarg, "ok")) {
|
||||
result.config.on_timeout_result_state = STATE_OK;
|
||||
} else if (!strcmp(optarg, "warning")) {
|
||||
result.config.on_timeout_result_state = STATE_WARNING;
|
||||
} else if (!strcmp(optarg, "critical")) {
|
||||
result.config.on_timeout_result_state = STATE_CRITICAL;
|
||||
} else if (!strcmp(optarg, "unknown")) {
|
||||
result.config.on_timeout_result_state = STATE_UNKNOWN;
|
||||
} else {
|
||||
usage2(_("Invalid custom timeout result state option"), optarg);
|
||||
}
|
||||
break;
|
||||
case 'c': /* critical time threshold */
|
||||
{
|
||||
mp_range_parsed critical_range = mp_parse_range_string(optarg);
|
||||
|
|
|
|||
|
|
@ -755,6 +755,7 @@ check_curl_config check_curl_config_init(void) {
|
|||
.header_expect = "",
|
||||
.on_redirect_result_state = STATE_OK,
|
||||
.on_redirect_dependent = false,
|
||||
.on_timeout_result_state = STATE_CRITICAL,
|
||||
|
||||
.show_extended_perfdata = false,
|
||||
.show_body = false,
|
||||
|
|
|
|||
|
|
@ -113,9 +113,12 @@ typedef struct {
|
|||
mp_state_enum on_redirect_result_state;
|
||||
bool on_redirect_dependent;
|
||||
|
||||
mp_state_enum on_timeout_result_state;
|
||||
|
||||
bool show_extended_perfdata;
|
||||
bool show_body;
|
||||
|
||||
|
||||
bool output_format_is_set;
|
||||
mp_output_format output_format;
|
||||
} check_curl_config;
|
||||
|
|
|
|||
|
|
@ -205,7 +205,8 @@ bool process_arguments(int argc, char **argv) {
|
|||
SNI_OPTION,
|
||||
MAX_REDIRS_OPTION,
|
||||
CONTINUE_AFTER_CHECK_CERT,
|
||||
STATE_REGEX
|
||||
STATE_REGEX,
|
||||
TIMEOUT_CUSTOM_RESULT_STATE
|
||||
};
|
||||
|
||||
int option = 0;
|
||||
|
|
@ -247,6 +248,7 @@ bool process_arguments(int argc, char **argv) {
|
|||
{"extended-perfdata", no_argument, 0, 'E'},
|
||||
{"show-body", no_argument, 0, 'B'},
|
||||
{"max-redirs", required_argument, 0, MAX_REDIRS_OPTION},
|
||||
{"timeout-custom-result-state", required_argument, 0, TIMEOUT_CUSTOM_RESULT_STATE},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
if (argc < 2) {
|
||||
|
|
@ -298,6 +300,19 @@ bool process_arguments(int argc, char **argv) {
|
|||
socket_timeout = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case TIMEOUT_CUSTOM_RESULT_STATE:
|
||||
if (!strcmp(optarg, "ok")) {
|
||||
socket_timeout_state = STATE_OK;
|
||||
} else if (!strcmp(optarg, "warning")) {
|
||||
socket_timeout_state = STATE_WARNING;
|
||||
} else if (!strcmp(optarg, "critical")) {
|
||||
socket_timeout_state = STATE_CRITICAL;
|
||||
} else if (!strcmp(optarg, "unknown")) {
|
||||
socket_timeout_state = STATE_UNKNOWN;
|
||||
} else {
|
||||
usage2(_("Invalid custom timeout result state option"), optarg);
|
||||
}
|
||||
break;
|
||||
case 'c': /* critical time threshold */
|
||||
critical_thresholds = optarg;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue