Module: monitoring-plugins
Branch: master
Commit: 62035adf6c8199eba54755f23e8affe97e645300
Author: Lorenz Kästle <[email protected]>
Date: Sun Nov 9 11:32:43 2025 +0100
URL:
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=62035adf
check_smtp: implement output format cli parameter
---
plugins/check_smtp.c | 22 +++++++++++++++++++++-
plugins/check_smtp.d/config.h | 6 ++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index f2c7f05c..cb92421c 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -115,6 +115,10 @@ int main(int argc, char **argv) {
const check_smtp_config config = tmp_config.config;
+ if (config.output_format_is_set) {
+ mp_set_format(config.output_format);
+ }
+
/* If localhostname not set on command line, use gethostname to set */
char *localhostname = config.localhostname;
if (!localhostname) {
@@ -578,7 +582,8 @@ int main(int argc, char **argv) {
/* process command-line arguments */
check_smtp_config_wrapper process_arguments(int argc, char **argv) {
enum {
- SNI_OPTION = CHAR_MAX + 1
+ SNI_OPTION = CHAR_MAX + 1,
+ output_format_index,
};
int option = 0;
@@ -608,6 +613,7 @@ check_smtp_config_wrapper process_arguments(int argc, char
**argv) {
{"certificate", required_argument, 0, 'D'},
{"ignore-quit-failure", no_argument, 0, 'q'},
{"proxy", no_argument, 0, 'r'},
+
{"output-format", required_argument, 0, output_format_index},
{0,
0, 0, 0}};
check_smtp_config_wrapper result = {
@@ -809,6 +815,18 @@ check_smtp_config_wrapper process_arguments(int argc, char
**argv) {
exit(STATE_UNKNOWN);
case '?': /* help */
usage5();
+ 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;
+ }
}
}
@@ -1015,6 +1033,8 @@ void print_help(void) {
printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
+ printf(UT_OUTPUT_FORMAT);
+
printf(UT_VERBOSE);
printf("\n");
diff --git a/plugins/check_smtp.d/config.h b/plugins/check_smtp.d/config.h
index bc433093..11d7fe56 100644
--- a/plugins/check_smtp.d/config.h
+++ b/plugins/check_smtp.d/config.h
@@ -1,6 +1,7 @@
#pragma once
#include "../../config.h"
+#include "output.h"
#include "thresholds.h"
#include <stddef.h>
#include <string.h>
@@ -46,6 +47,9 @@ typedef struct {
bool use_starttls;
bool use_sni;
#endif
+
+ bool output_format_is_set;
+ mp_output_format output_format;
} check_smtp_config;
check_smtp_config check_smtp_config_init() {
@@ -83,6 +87,8 @@ check_smtp_config check_smtp_config_init() {
.use_starttls = false,
.use_sni = false,
#endif
+
+ .output_format_is_set = false,
};
return tmp;
}