Module: monitoring-plugins
 Branch: master
 Commit: 317ee266a88bd8752113df39f12e2d133edd6802
 Author: Lorenz Kästle <[email protected]>
   Date: Wed Nov 26 13:50:58 2025 +0100
    URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=317ee266

Add output formatting option where they were forgotten

---

 plugins/check_dbi.c                  |  2 ++
 plugins/check_mysql.c                | 19 +++++++++++++++++++
 plugins/check_mysql.d/config.h       |  5 +++++
 plugins/check_mysql_query.c          | 22 ++++++++++++++++++++++
 plugins/check_mysql_query.d/config.h |  6 ++++++
 5 files changed, 54 insertions(+)

diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index 9bc68eb3..81d92952 100644
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
@@ -688,6 +688,8 @@ void print_help(void) {
 
        printf(UT_VERBOSE);
 
+       printf(UT_OUTPUT_FORMAT);
+
        printf("\n");
        printf(" %s\n", _("A DBI driver (-d option) is required. If the 
specified metric operates"));
        printf(" %s\n\n", _("on a query, one has to be specified (-q 
option)."));
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 9d8094c0..009c9908 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -96,6 +96,10 @@ int main(int argc, char **argv) {
 
        const check_mysql_config config = tmp_config.config;
 
+       if (config.output_format_is_set) {
+               mp_set_format(config.output_format);
+       }
+
        MYSQL mysql;
        /* initialize mysql  */
        mysql_init(&mysql);
@@ -471,6 +475,7 @@ check_mysql_config_wrapper process_arguments(int argc, char 
**argv) {
 
        enum {
                CHECK_REPLICA_OPT = CHAR_MAX + 1,
+               output_format_index,
        };
 
        static struct option longopts[] = {{"hostname", required_argument, 0, 
'H'},
@@ -495,6 +500,7 @@ check_mysql_config_wrapper process_arguments(int argc, char 
**argv) {
                                                                           
{"cert", required_argument, 0, 'a'},
                                                                           
{"ca-dir", required_argument, 0, 'D'},
                                                                           
{"ciphers", required_argument, 0, 'L'},
+                                                                          
{"output-format", required_argument, 0, output_format_index},
                                                                           {0, 
0, 0, 0}};
 
        check_mysql_config_wrapper result = {
@@ -605,6 +611,17 @@ check_mysql_config_wrapper process_arguments(int argc, 
char **argv) {
                        break;
                case '?': /* help */
                        usage5();
+               case output_format_index: {
+                       parsed_output_format parser = 
mp_parse_output_format(optarg);
+                       if (!parser.parsing_success) {
+                               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;
+               }
                }
        }
 
@@ -711,6 +728,8 @@ void print_help(void) {
        printf(" %s\n", "-L, --ciphers=STRING");
        printf("    %s\n", _("List of valid SSL ciphers"));
 
+       printf(UT_OUTPUT_FORMAT);
+
        printf("\n");
        printf(" %s\n",
                   _("There are no required arguments. By default, the local 
database is checked"));
diff --git a/plugins/check_mysql.d/config.h b/plugins/check_mysql.d/config.h
index ef086cfc..1d8c82bb 100644
--- a/plugins/check_mysql.d/config.h
+++ b/plugins/check_mysql.d/config.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "../../config.h"
+#include "output.h"
 #include "thresholds.h"
 #include <stddef.h>
 #include <mysql.h>
@@ -26,6 +27,8 @@ typedef struct {
 
        mp_thresholds replica_thresholds;
 
+       bool output_format_is_set;
+       mp_output_format output_format;
 } check_mysql_config;
 
 check_mysql_config check_mysql_config_init() {
@@ -49,6 +52,8 @@ check_mysql_config check_mysql_config_init() {
                .ignore_auth = false,
 
                .replica_thresholds = mp_thresholds_init(),
+
+               .output_format_is_set = false,
        };
        return tmp;
 }
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 8af378d5..ae6cc15d 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -73,6 +73,10 @@ int main(int argc, char **argv) {
 
        const check_mysql_query_config config = tmp_config.config;
 
+       if (config.output_format_is_set) {
+               mp_set_format(config.output_format);
+       }
+
        MYSQL mysql;
        /* initialize mysql  */
        mysql_init(&mysql);
@@ -185,6 +189,10 @@ int main(int argc, char **argv) {
 
 /* process command-line arguments */
 check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
+       enum {
+               output_format_index = CHAR_MAX + 1,
+       };
+
        static struct option longopts[] = {{"hostname", required_argument, 0, 
'H'},
                                                                           
{"socket", required_argument, 0, 's'},
                                                                           
{"database", required_argument, 0, 'd'},
@@ -199,6 +207,7 @@ check_mysql_query_config_wrapper process_arguments(int 
argc, char **argv) {
                                                                           
{"query", required_argument, 0, 'q'},
                                                                           
{"warning", required_argument, 0, 'w'},
                                                                           
{"critical", required_argument, 0, 'c'},
+                                                                          
{"output-format", required_argument, 0, output_format_index},
                                                                           {0, 
0, 0, 0}};
 
        check_mysql_query_config_wrapper result = {
@@ -282,6 +291,17 @@ check_mysql_query_config_wrapper process_arguments(int 
argc, char **argv) {
                } break;
                case '?': /* help */
                        usage5();
+               case output_format_index: {
+                       parsed_output_format parser = 
mp_parse_output_format(optarg);
+                       if (!parser.parsing_success) {
+                               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;
+               }
                }
        }
 
@@ -344,6 +364,8 @@ void print_help(void) {
        printf("    ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS 
NOT SECURE!!!"));
        printf("    %s\n", _("Your clear-text password could be visible as a 
process table entry"));
 
+       printf(UT_OUTPUT_FORMAT);
+
        printf("\n");
        printf(" %s\n", _("A query is required. The result from the query 
should be numeric."));
        printf(" %s\n", _("For extra security, create a user with minimal 
access."));
diff --git a/plugins/check_mysql_query.d/config.h 
b/plugins/check_mysql_query.d/config.h
index 1c9952e5..32ab455a 100644
--- a/plugins/check_mysql_query.d/config.h
+++ b/plugins/check_mysql_query.d/config.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "../../config.h"
+#include "output.h"
 #include "thresholds.h"
 #include <mysql.h>
 
@@ -16,6 +17,9 @@ typedef struct {
 
        char *sql_query;
        mp_thresholds thresholds;
+
+       bool output_format_is_set;
+       mp_output_format output_format;
 } check_mysql_query_config;
 
 check_mysql_query_config check_mysql_query_config_init() {
@@ -31,6 +35,8 @@ check_mysql_query_config check_mysql_query_config_init() {
 
                .sql_query = NULL,
                .thresholds = mp_thresholds_init(),
+
+               .output_format_is_set = false,
        };
        return tmp;
 }

Reply via email to