[monitoring-plugins] check_ldap: implement output format selection

Lorenz Kästle git at monitoring-plugins.org
Tue Nov 25 14:00:12 CET 2025


 Module: monitoring-plugins
 Branch: master
 Commit: d6c4b799e3416d70448dea9ea886d29dbf69c820
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Tue Nov 25 12:41:07 2025 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=d6c4b799

check_ldap: implement output format selection

---

 plugins/check_ldap.c          | 22 ++++++++++++++++++++++
 plugins/check_ldap.d/config.h |  6 ++++++
 2 files changed, 28 insertions(+)

diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index c3f83901..8ee0e617 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -82,6 +82,10 @@ int main(int argc, char *argv[]) {
 
 	const check_ldap_config config = tmp_config.config;
 
+	if (config.output_format_is_set) {
+		mp_set_format(config.output_format);
+	}
+
 	/* initialize alarm signal handling */
 	signal(SIGALRM, socket_timeout_alarm_handler);
 
@@ -306,6 +310,10 @@ int main(int argc, char *argv[]) {
 
 /* process command-line arguments */
 check_ldap_config_wrapper process_arguments(int argc, char **argv) {
+	enum {
+		output_format_index = CHAR_MAX + 1,
+	};
+
 	/* initialize the long option struct */
 	static struct option longopts[] = {{"help", no_argument, 0, 'h'},
 									   {"version", no_argument, 0, 'V'},
@@ -329,6 +337,7 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
 									   {"warn-entries", required_argument, 0, 'W'},
 									   {"crit-entries", required_argument, 0, 'C'},
 									   {"verbose", no_argument, 0, 'v'},
+									   {"output-format", required_argument, 0, output_format_index},
 									   {0, 0, 0, 0}};
 
 	check_ldap_config_wrapper result = {
@@ -458,6 +467,18 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
 			usage(_("IPv6 support not available\n"));
 #endif
 			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;
+		}
 		default:
 			usage5();
 		}
@@ -553,6 +574,7 @@ void print_help(void) {
 	printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
 
 	printf(UT_VERBOSE);
+	printf(UT_OUTPUT_FORMAT);
 
 	printf("\n");
 	printf("%s\n", _("Notes:"));
diff --git a/plugins/check_ldap.d/config.h b/plugins/check_ldap.d/config.h
index 9e6bb845..50191725 100644
--- a/plugins/check_ldap.d/config.h
+++ b/plugins/check_ldap.d/config.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "../../config.h"
+#include "output.h"
 #include "thresholds.h"
 #include <stddef.h>
 
@@ -27,6 +28,9 @@ typedef struct {
 
 	mp_thresholds entries_thresholds;
 	mp_thresholds connection_time_threshold;
+
+	bool output_format_is_set;
+	mp_output_format output_format;
 } check_ldap_config;
 
 check_ldap_config check_ldap_config_init() {
@@ -45,6 +49,8 @@ check_ldap_config check_ldap_config_init() {
 
 		.entries_thresholds = mp_thresholds_init(),
 		.connection_time_threshold = mp_thresholds_init(),
+
+		.output_format_is_set = false,
 	};
 	return tmp;
 }



More information about the Commits mailing list