summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-10-29 23:27:31 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-10-29 23:27:31 +0100
commit408783f53d0baaf7341c7c584ca64a9073d66ee2 (patch)
tree7a8c5124384471e9d327c06051ec4b310d69cb58
parent071de8a73a283ac7e262194c2c08fabfef4473b1 (diff)
downloadmonitoring-plugins-408783f53d0baaf7341c7c584ca64a9073d66ee2.tar.gz
check_dbi: add output format parameter
-rw-r--r--plugins/check_dbi.c20
-rw-r--r--plugins/check_dbi.d/config.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index ddd0b328..286635cc 100644
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
@@ -100,6 +100,10 @@ int main(int argc, char **argv) {
100 100
101 const check_dbi_config config = tmp.config; 101 const check_dbi_config config = tmp.config;
102 102
103 if (config.output_format_is_set) {
104 mp_set_format(config.output_format);
105 }
106
103 /* Set signal handling and alarm */ 107 /* Set signal handling and alarm */
104 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { 108 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
105 usage4(_("Cannot catch SIGALRM")); 109 usage4(_("Cannot catch SIGALRM"));
@@ -421,6 +425,9 @@ int main(int argc, char **argv) {
421 425
422/* process command-line arguments */ 426/* process command-line arguments */
423check_dbi_config_wrapper process_arguments(int argc, char **argv) { 427check_dbi_config_wrapper process_arguments(int argc, char **argv) {
428 enum {
429 output_format_index = CHAR_MAX + 1,
430 };
424 431
425 int option = 0; 432 int option = 0;
426 static struct option longopts[] = {STD_LONG_OPTS, 433 static struct option longopts[] = {STD_LONG_OPTS,
@@ -432,6 +439,7 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
432 {"option", required_argument, 0, 'o'}, 439 {"option", required_argument, 0, 'o'},
433 {"query", required_argument, 0, 'q'}, 440 {"query", required_argument, 0, 'q'},
434 {"database", required_argument, 0, 'D'}, 441 {"database", required_argument, 0, 'D'},
442 {"output-format", required_argument, 0, output_format_index},
435 {0, 0, 0, 0}}; 443 {0, 0, 0, 0}};
436 444
437 check_dbi_config_wrapper result = { 445 check_dbi_config_wrapper result = {
@@ -556,6 +564,18 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
556 case 'D': 564 case 'D':
557 result.config.dbi_database = optarg; 565 result.config.dbi_database = optarg;
558 break; 566 break;
567 case output_format_index: {
568 parsed_output_format parser = mp_parse_output_format(optarg);
569 if (!parser.parsing_success) {
570 // TODO List all available formats here, maybe add anothoer usage function
571 printf("Invalid output format: %s\n", optarg);
572 exit(STATE_UNKNOWN);
573 }
574
575 result.config.output_format_is_set = true;
576 result.config.output_format = parser.output_format;
577 break;
578 }
559 } 579 }
560 } 580 }
561 581
diff --git a/plugins/check_dbi.d/config.h b/plugins/check_dbi.d/config.h
index f6f0d7b3..09aa67da 100644
--- a/plugins/check_dbi.d/config.h
+++ b/plugins/check_dbi.d/config.h
@@ -38,6 +38,8 @@ typedef struct {
38 char *critical_range; 38 char *critical_range;
39 thresholds *dbi_thresholds; 39 thresholds *dbi_thresholds;
40 40
41 bool output_format_is_set;
42 mp_output_format output_format;
41} check_dbi_config; 43} check_dbi_config;
42 44
43check_dbi_config check_dbi_config_init() { 45check_dbi_config check_dbi_config_init() {
@@ -58,6 +60,8 @@ check_dbi_config check_dbi_config_init() {
58 .warning_range = NULL, 60 .warning_range = NULL,
59 .critical_range = NULL, 61 .critical_range = NULL,
60 .dbi_thresholds = NULL, 62 .dbi_thresholds = NULL,
63
64 .output_format_is_set = false,
61 }; 65 };
62 return tmp; 66 return tmp;
63} 67}