From 5a2c1b2c3aeb99e7a703b0c5f6fe1a21d29b3be4 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 15 Sep 2025 02:30:42 +0200 Subject: Add output formatting option --- plugins/check_curl.c | 22 +++++++++++++++++++++- plugins/check_curl.d/check_curl_helpers.c | 2 ++ plugins/check_curl.d/config.h | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 6d50568f..fc704171 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -139,6 +139,10 @@ int main(int argc, char **argv) { const check_curl_config config = tmp_config.config; + if (config.output_format_is_set) { + mp_set_format(config.output_format); + } + check_curl_working_state working_state = config.initial_config; mp_check overall = mp_check_init(); @@ -828,7 +832,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { AUTOMATIC_DECOMPRESSION, COOKIE_JAR, HAPROXY_PROTOCOL, - STATE_REGEX + STATE_REGEX, + OUTPUT_FORMAT }; static struct option longopts[] = { @@ -875,6 +880,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, {"cookie-jar", required_argument, 0, COOKIE_JAR}, {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL}, + {"output-format", required_argument, 0, OUTPUT_FORMAT}, {0, 0, 0, 0}}; check_curl_config_wrapper result = { @@ -1301,6 +1307,18 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { /* print short usage statement if args not parsable */ usage5(); break; + case OUTPUT_FORMAT: { + parsed_output_format parser = mp_parse_output_format(optarg); + if (!parser.parsing_success) { + // TODO List all available formats here, maybe add anothoer usage function + printf("Invalid output format: %s\n", optarg); + exit(STATE_UNKNOWN); + } + + result.config.output_format_is_set = true; + result.config.output_format = parser.output_format; + break; + } } } @@ -1602,6 +1620,8 @@ void print_help(void) { printf(UT_VERBOSE); + printf(UT_OUTPUT_FORMAT); + printf("\n"); printf("%s\n", _("Notes:")); printf(" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c index ab43a1e1..c3c2ba55 100644 --- a/plugins/check_curl.d/check_curl_helpers.c +++ b/plugins/check_curl.d/check_curl_helpers.c @@ -632,6 +632,8 @@ check_curl_config check_curl_config_init() { .show_extended_perfdata = false, .show_body = false, + + .output_format_is_set = false, }; snprintf(tmp.curl_config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)", diff --git a/plugins/check_curl.d/config.h b/plugins/check_curl.d/config.h index 6100af3e..f51b2ee9 100644 --- a/plugins/check_curl.d/config.h +++ b/plugins/check_curl.d/config.h @@ -108,6 +108,9 @@ typedef struct { bool show_extended_perfdata; bool show_body; + + bool output_format_is_set; + mp_output_format output_format; } check_curl_config; check_curl_config check_curl_config_init(); -- cgit v1.2.3-74-g34f1