From 07d3eb9e2c729b6ab5effc0f664b6d5d9958fa72 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 25 Nov 2025 12:31:00 +0100 Subject: check_ldap: modern output implementation --- plugins/check_ldap.d/config.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'plugins/check_ldap.d/config.h') diff --git a/plugins/check_ldap.d/config.h b/plugins/check_ldap.d/config.h index c8a40610..9e6bb845 100644 --- a/plugins/check_ldap.d/config.h +++ b/plugins/check_ldap.d/config.h @@ -25,13 +25,8 @@ typedef struct { int ld_protocol; #endif - char *warn_entries; - char *crit_entries; - thresholds *entries_thresholds; - bool warn_time_set; - double warn_time; - bool crit_time_set; - double crit_time; + mp_thresholds entries_thresholds; + mp_thresholds connection_time_threshold; } check_ldap_config; check_ldap_config check_ldap_config_init() { @@ -48,13 +43,8 @@ check_ldap_config check_ldap_config_init() { .ld_protocol = DEFAULT_PROTOCOL, #endif - .warn_entries = NULL, - .crit_entries = NULL, - .entries_thresholds = NULL, - .warn_time_set = false, - .warn_time = 0, - .crit_time_set = false, - .crit_time = 0, + .entries_thresholds = mp_thresholds_init(), + .connection_time_threshold = mp_thresholds_init(), }; return tmp; } -- cgit v1.2.3-74-g34f1 From d6c4b799e3416d70448dea9ea886d29dbf69c820 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 25 Nov 2025 12:41:07 +0100 Subject: check_ldap: implement output format selection --- plugins/check_ldap.c | 22 ++++++++++++++++++++++ plugins/check_ldap.d/config.h | 6 ++++++ 2 files changed, 28 insertions(+) (limited to 'plugins/check_ldap.d/config.h') 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 @@ -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; } -- cgit v1.2.3-74-g34f1