summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-25 12:41:07 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-25 12:42:50 +0100
commitd6c4b799e3416d70448dea9ea886d29dbf69c820 (patch)
tree4b2b9d4a299a3184af6490de589f0f9e6ab424d1
parent2e3dff775dd92ea9880221c800f6dc6e53162fb4 (diff)
downloadmonitoring-plugins-d6c4b799e3416d70448dea9ea886d29dbf69c820.tar.gz
check_ldap: implement output format selection
-rw-r--r--plugins/check_ldap.c22
-rw-r--r--plugins/check_ldap.d/config.h6
2 files changed, 28 insertions, 0 deletions
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[]) {
82 82
83 const check_ldap_config config = tmp_config.config; 83 const check_ldap_config config = tmp_config.config;
84 84
85 if (config.output_format_is_set) {
86 mp_set_format(config.output_format);
87 }
88
85 /* initialize alarm signal handling */ 89 /* initialize alarm signal handling */
86 signal(SIGALRM, socket_timeout_alarm_handler); 90 signal(SIGALRM, socket_timeout_alarm_handler);
87 91
@@ -306,6 +310,10 @@ int main(int argc, char *argv[]) {
306 310
307/* process command-line arguments */ 311/* process command-line arguments */
308check_ldap_config_wrapper process_arguments(int argc, char **argv) { 312check_ldap_config_wrapper process_arguments(int argc, char **argv) {
313 enum {
314 output_format_index = CHAR_MAX + 1,
315 };
316
309 /* initialize the long option struct */ 317 /* initialize the long option struct */
310 static struct option longopts[] = {{"help", no_argument, 0, 'h'}, 318 static struct option longopts[] = {{"help", no_argument, 0, 'h'},
311 {"version", no_argument, 0, 'V'}, 319 {"version", no_argument, 0, 'V'},
@@ -329,6 +337,7 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
329 {"warn-entries", required_argument, 0, 'W'}, 337 {"warn-entries", required_argument, 0, 'W'},
330 {"crit-entries", required_argument, 0, 'C'}, 338 {"crit-entries", required_argument, 0, 'C'},
331 {"verbose", no_argument, 0, 'v'}, 339 {"verbose", no_argument, 0, 'v'},
340 {"output-format", required_argument, 0, output_format_index},
332 {0, 0, 0, 0}}; 341 {0, 0, 0, 0}};
333 342
334 check_ldap_config_wrapper result = { 343 check_ldap_config_wrapper result = {
@@ -458,6 +467,18 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
458 usage(_("IPv6 support not available\n")); 467 usage(_("IPv6 support not available\n"));
459#endif 468#endif
460 break; 469 break;
470 case output_format_index: {
471 parsed_output_format parser = mp_parse_output_format(optarg);
472 if (!parser.parsing_success) {
473 // TODO List all available formats here, maybe add anothoer usage function
474 printf("Invalid output format: %s\n", optarg);
475 exit(STATE_UNKNOWN);
476 }
477
478 result.config.output_format_is_set = true;
479 result.config.output_format = parser.output_format;
480 break;
481 }
461 default: 482 default:
462 usage5(); 483 usage5();
463 } 484 }
@@ -553,6 +574,7 @@ void print_help(void) {
553 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 574 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
554 575
555 printf(UT_VERBOSE); 576 printf(UT_VERBOSE);
577 printf(UT_OUTPUT_FORMAT);
556 578
557 printf("\n"); 579 printf("\n");
558 printf("%s\n", _("Notes:")); 580 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 @@
1#pragma once 1#pragma once
2 2
3#include "../../config.h" 3#include "../../config.h"
4#include "output.h"
4#include "thresholds.h" 5#include "thresholds.h"
5#include <stddef.h> 6#include <stddef.h>
6 7
@@ -27,6 +28,9 @@ typedef struct {
27 28
28 mp_thresholds entries_thresholds; 29 mp_thresholds entries_thresholds;
29 mp_thresholds connection_time_threshold; 30 mp_thresholds connection_time_threshold;
31
32 bool output_format_is_set;
33 mp_output_format output_format;
30} check_ldap_config; 34} check_ldap_config;
31 35
32check_ldap_config check_ldap_config_init() { 36check_ldap_config check_ldap_config_init() {
@@ -45,6 +49,8 @@ check_ldap_config check_ldap_config_init() {
45 49
46 .entries_thresholds = mp_thresholds_init(), 50 .entries_thresholds = mp_thresholds_init(),
47 .connection_time_threshold = mp_thresholds_init(), 51 .connection_time_threshold = mp_thresholds_init(),
52
53 .output_format_is_set = false,
48 }; 54 };
49 return tmp; 55 return tmp;
50} 56}