From 883fcb607f9b3e810e22b2e21da7441a073b6e32 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 10 Mar 2025 01:31:52 +0100 Subject: Refactor check_smtp --- plugins/check_smtp.d/config.h | 92 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 plugins/check_smtp.d/config.h (limited to 'plugins/check_smtp.d') diff --git a/plugins/check_smtp.d/config.h b/plugins/check_smtp.d/config.h new file mode 100644 index 00000000..c8660445 --- /dev/null +++ b/plugins/check_smtp.d/config.h @@ -0,0 +1,92 @@ +#pragma once + +#include "../../config.h" +#include +#include + +enum { + SMTP_PORT = 25, + SMTPS_PORT = 465 +}; + +#define SMTP_EXPECT "220" + +typedef struct { + int server_port; + char *server_address; + char *localhostname; + char *server_expect; + bool ignore_send_quit_failure; + + double warning_time; + bool check_warning_time; + double critical_time; + bool check_critical_time; + bool use_ehlo; + bool use_lhlo; + + char *from_arg; + bool send_mail_from; + + int ncommands; + char **commands; + + int nresponses; + char **responses; + + char *authtype; + char *authuser; + char *authpass; + + bool use_proxy_prefix; +#ifdef HAVE_SSL + bool check_cert; + int days_till_exp_warn; + int days_till_exp_crit; + bool use_ssl; + bool use_starttls; + bool use_sni; +#endif +} check_smtp_config; + +check_smtp_config check_smtp_config_init() { + check_smtp_config tmp = { + .server_port = SMTP_PORT, + .server_address = strdup("localhost"), + .localhostname = NULL, + + .server_expect = SMTP_EXPECT, + .ignore_send_quit_failure = false, + + .warning_time = 0, + .check_warning_time = false, + .critical_time = 0, + .check_critical_time = false, + .use_ehlo = false, + .use_lhlo = false, + + .from_arg = strdup(" "), + .send_mail_from = false, + + .ncommands = 0, + .commands = NULL, + + .nresponses = 0, + .responses = NULL, + + .authtype = NULL, + .authuser = NULL, + .authpass = NULL, + + .use_proxy_prefix = false, +#ifdef HAVE_SSL + .check_cert = false, + .days_till_exp_warn = 0, + .days_till_exp_crit = 0, + .use_ssl = false, + .use_starttls = false, + .use_sni = false, +#endif + }; + return tmp; +} -- cgit v1.2.3-74-g34f1 From 5cf53de34fa410702ca59437cdf3f304366c3c55 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:56:09 +0100 Subject: check_smtp: fix positional host logic --- plugins/check_smtp.c | 2 ++ plugins/check_smtp.d/config.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins/check_smtp.d') diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 324549d4..fd492294 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -697,6 +697,8 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) { } else { usage2(_("Invalid hostname/address"), argv[c]); } + } else { + result.config.server_address = strdup("localhost"); } } diff --git a/plugins/check_smtp.d/config.h b/plugins/check_smtp.d/config.h index c8660445..0a6511ef 100644 --- a/plugins/check_smtp.d/config.h +++ b/plugins/check_smtp.d/config.h @@ -52,7 +52,7 @@ typedef struct { check_smtp_config check_smtp_config_init() { check_smtp_config tmp = { .server_port = SMTP_PORT, - .server_address = strdup("localhost"), + .server_address = NULL, .localhostname = NULL, .server_expect = SMTP_EXPECT, -- cgit v1.2.3-74-g34f1