Module: monitoring-plugins
Branch: master
Commit: 8a71cf947f14d731e8ffaa4214d5c82eead912d1
Author: Lorenz Kästle <[email protected]>
Date: Wed Nov 5 13:59:08 2025 +0100
URL:
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=8a71cf94
check_pgsql: implement cli params for output format
---
plugins/check_pgsql.c | 18 ++++++++++++++++--
plugins/check_pgsql.d/config.h | 6 ++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index cd314f29..5fbffa70 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -150,8 +150,8 @@ int main(int argc, char **argv) {
const check_pgsql_config config = tmp_config.config;
- if (verbose > 2) {
- printf("Arguments initialized\n");
+ if (config.output_format_is_set) {
+ mp_set_format(config.output_format);
}
/* Set signal handling and alarm */
@@ -335,6 +335,7 @@ static check_pgsql_config_wrapper process_arguments(int
argc, char **argv) {
enum {
OPTID_QUERYNAME = CHAR_MAX + 1,
+ output_format_index,
};
static struct option longopts[] = {{"help", no_argument, 0, 'h'},
@@ -354,6 +355,7 @@ static check_pgsql_config_wrapper process_arguments(int
argc, char **argv) {
{"query_critical", required_argument, 0, 'C'},
{"query_warning", required_argument, 0, 'W'},
{"verbose", no_argument, 0, 'v'},
+
{"output-format", required_argument, 0, output_format_index},
{0,
0, 0, 0}};
check_pgsql_config_wrapper result = {
@@ -371,6 +373,17 @@ static check_pgsql_config_wrapper process_arguments(int
argc, char **argv) {
}
switch (option_char) {
+ 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;
+ }
case '?': /* usage */
usage5();
case 'h': /* help */
@@ -557,6 +570,7 @@ void print_help(void) {
printf(" %s\n", _("SQL query value to result in critical status
(double)"));
printf(UT_VERBOSE);
+ printf(UT_OUTPUT_FORMAT);
printf("\n");
printf(" %s\n", _("All parameters are optional."));
diff --git a/plugins/check_pgsql.d/config.h b/plugins/check_pgsql.d/config.h
index 7c1ff55a..7cf0637b 100644
--- a/plugins/check_pgsql.d/config.h
+++ b/plugins/check_pgsql.d/config.h
@@ -1,6 +1,7 @@
#pragma once
#include "../../config.h"
+#include "output.h"
#include "perfdata.h"
#include "thresholds.h"
#include <stddef.h>
@@ -27,6 +28,9 @@ typedef struct {
mp_thresholds time_thresholds;
mp_thresholds qthresholds;
+
+ bool output_format_is_set;
+ mp_output_format output_format;
} check_pgsql_config;
/* begin, by setting the parameters for a backend connection if the
@@ -51,6 +55,8 @@ check_pgsql_config check_pgsql_config_init() {
.time_thresholds = mp_thresholds_init(),
.qthresholds = mp_thresholds_init(),
+
+ .output_format_is_set = false,
};
mp_range tmp_range = mp_range_init();