Module: monitoring-plugins
 Branch: master
 Commit: 408783f53d0baaf7341c7c584ca64a9073d66ee2
 Author: Lorenz Kästle <[email protected]>
   Date: Wed Oct 29 23:27:31 2025 +0100
    URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=408783f5

check_dbi: add output format parameter

---

 plugins/check_dbi.c          | 20 ++++++++++++++++++++
 plugins/check_dbi.d/config.h |  4 ++++
 2 files changed, 24 insertions(+)

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) {
 
        const check_dbi_config config = tmp.config;
 
+       if (config.output_format_is_set) {
+               mp_set_format(config.output_format);
+       }
+
        /* Set signal handling and alarm */
        if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
                usage4(_("Cannot catch SIGALRM"));
@@ -421,6 +425,9 @@ int main(int argc, char **argv) {
 
 /* process command-line arguments */
 check_dbi_config_wrapper process_arguments(int argc, char **argv) {
+       enum {
+               output_format_index = CHAR_MAX + 1,
+       };
 
        int option = 0;
        static struct option longopts[] = {STD_LONG_OPTS,
@@ -432,6 +439,7 @@ check_dbi_config_wrapper process_arguments(int argc, char 
**argv) {
                                                                           
{"option", required_argument, 0, 'o'},
                                                                           
{"query", required_argument, 0, 'q'},
                                                                           
{"database", required_argument, 0, 'D'},
+                                                                          
{"output-format", required_argument, 0, output_format_index},
                                                                           {0, 
0, 0, 0}};
 
        check_dbi_config_wrapper result = {
@@ -556,6 +564,18 @@ check_dbi_config_wrapper process_arguments(int argc, char 
**argv) {
                case 'D':
                        result.config.dbi_database = optarg;
                        break;
+               case output_format_index: {
+                       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;
+               }
                }
        }
 
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 {
        char *critical_range;
        thresholds *dbi_thresholds;
 
+       bool output_format_is_set;
+       mp_output_format output_format;
 } check_dbi_config;
 
 check_dbi_config check_dbi_config_init() {
@@ -58,6 +60,8 @@ check_dbi_config check_dbi_config_init() {
                .warning_range = NULL,
                .critical_range = NULL,
                .dbi_thresholds = NULL,
+
+               .output_format_is_set = false,
        };
        return tmp;
 }

Reply via email to