summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 02:30:42 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 02:30:42 +0200
commit5a2c1b2c3aeb99e7a703b0c5f6fe1a21d29b3be4 (patch)
tree9b9b45a6a611c4f37cf5dd447b37f74e48d56c14
parenteca9eaf9f5771e417366bd3dac0cd463f405eb70 (diff)
downloadmonitoring-plugins-5a2c1b2c3aeb99e7a703b0c5f6fe1a21d29b3be4.tar.gz
Add output formatting option
-rw-r--r--plugins/check_curl.c22
-rw-r--r--plugins/check_curl.d/check_curl_helpers.c2
-rw-r--r--plugins/check_curl.d/config.h3
3 files changed, 26 insertions, 1 deletions
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) {
139 139
140 const check_curl_config config = tmp_config.config; 140 const check_curl_config config = tmp_config.config;
141 141
142 if (config.output_format_is_set) {
143 mp_set_format(config.output_format);
144 }
145
142 check_curl_working_state working_state = config.initial_config; 146 check_curl_working_state working_state = config.initial_config;
143 147
144 mp_check overall = mp_check_init(); 148 mp_check overall = mp_check_init();
@@ -828,7 +832,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
828 AUTOMATIC_DECOMPRESSION, 832 AUTOMATIC_DECOMPRESSION,
829 COOKIE_JAR, 833 COOKIE_JAR,
830 HAPROXY_PROTOCOL, 834 HAPROXY_PROTOCOL,
831 STATE_REGEX 835 STATE_REGEX,
836 OUTPUT_FORMAT
832 }; 837 };
833 838
834 static struct option longopts[] = { 839 static struct option longopts[] = {
@@ -875,6 +880,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
875 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, 880 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
876 {"cookie-jar", required_argument, 0, COOKIE_JAR}, 881 {"cookie-jar", required_argument, 0, COOKIE_JAR},
877 {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL}, 882 {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL},
883 {"output-format", required_argument, 0, OUTPUT_FORMAT},
878 {0, 0, 0, 0}}; 884 {0, 0, 0, 0}};
879 885
880 check_curl_config_wrapper result = { 886 check_curl_config_wrapper result = {
@@ -1301,6 +1307,18 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
1301 /* print short usage statement if args not parsable */ 1307 /* print short usage statement if args not parsable */
1302 usage5(); 1308 usage5();
1303 break; 1309 break;
1310 case OUTPUT_FORMAT: {
1311 parsed_output_format parser = mp_parse_output_format(optarg);
1312 if (!parser.parsing_success) {
1313 // TODO List all available formats here, maybe add anothoer usage function
1314 printf("Invalid output format: %s\n", optarg);
1315 exit(STATE_UNKNOWN);
1316 }
1317
1318 result.config.output_format_is_set = true;
1319 result.config.output_format = parser.output_format;
1320 break;
1321 }
1304 } 1322 }
1305 } 1323 }
1306 1324
@@ -1602,6 +1620,8 @@ void print_help(void) {
1602 1620
1603 printf(UT_VERBOSE); 1621 printf(UT_VERBOSE);
1604 1622
1623 printf(UT_OUTPUT_FORMAT);
1624
1605 printf("\n"); 1625 printf("\n");
1606 printf("%s\n", _("Notes:")); 1626 printf("%s\n", _("Notes:"));
1607 printf(" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); 1627 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() {
632 632
633 .show_extended_perfdata = false, 633 .show_extended_perfdata = false,
634 .show_body = false, 634 .show_body = false,
635
636 .output_format_is_set = false,
635 }; 637 };
636 638
637 snprintf(tmp.curl_config.user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)", 639 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 {
108 108
109 bool show_extended_perfdata; 109 bool show_extended_perfdata;
110 bool show_body; 110 bool show_body;
111
112 bool output_format_is_set;
113 mp_output_format output_format;
111} check_curl_config; 114} check_curl_config;
112 115
113check_curl_config check_curl_config_init(); 116check_curl_config check_curl_config_init();