diff options
author | Patrick Uiterwijk <patrick@puiterwijk.org> | 2018-12-13 18:24:53 +0100 |
---|---|---|
committer | Franz Schwartau <franz@electromail.org> | 2023-06-12 21:49:42 +0200 |
commit | ce85affd208cd8c873dd88c17b8d3d0540c8872e (patch) | |
tree | 09cfefad8695b979df958ab0d9da6307744aa7da /plugins/check_smtp.c | |
parent | d01740f22e9282845f2a6f345a33d6e813c22466 (diff) | |
download | monitoring-plugins-ce85aff.tar.gz |
check_smtp: Add option to prefix PROXY header
This enables checks of SMTP servers that expect the haproxy
PROXY protocol: -o smtpd_upstream_proxy_protocol=haproxy.
Backported from nagios-plugins:
https://github.com/nagios-plugins/nagios-plugins/commit/3246efe923b5482c5024c40e593ce942e628a3cb
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index eaa7eeba..addabfc6 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -52,6 +52,7 @@ int days_till_exp_warn, days_till_exp_crit; | |||
52 | enum { | 52 | enum { |
53 | SMTP_PORT = 25 | 53 | SMTP_PORT = 25 |
54 | }; | 54 | }; |
55 | #define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n" | ||
55 | #define SMTP_EXPECT "220" | 56 | #define SMTP_EXPECT "220" |
56 | #define SMTP_HELO "HELO " | 57 | #define SMTP_HELO "HELO " |
57 | #define SMTP_EHLO "EHLO " | 58 | #define SMTP_EHLO "EHLO " |
@@ -102,6 +103,7 @@ double critical_time = 0; | |||
102 | int check_critical_time = FALSE; | 103 | int check_critical_time = FALSE; |
103 | int verbose = 0; | 104 | int verbose = 0; |
104 | int use_ssl = FALSE; | 105 | int use_ssl = FALSE; |
106 | short use_proxy_prefix = FALSE; | ||
105 | short use_ehlo = FALSE; | 107 | short use_ehlo = FALSE; |
106 | short use_lhlo = FALSE; | 108 | short use_lhlo = FALSE; |
107 | short ssl_established = 0; | 109 | short ssl_established = 0; |
@@ -184,6 +186,13 @@ main (int argc, char **argv) | |||
184 | 186 | ||
185 | if (result == STATE_OK) { /* we connected */ | 187 | if (result == STATE_OK) { /* we connected */ |
186 | 188 | ||
189 | /* If requested, send PROXY header */ | ||
190 | if (use_proxy_prefix) { | ||
191 | if (verbose) | ||
192 | printf ("Sending header %s\n", PROXY_PREFIX); | ||
193 | send(sd, PROXY_PREFIX, strlen(PROXY_PREFIX), 0); | ||
194 | } | ||
195 | |||
187 | /* watch for the SMTP connection string and */ | 196 | /* watch for the SMTP connection string and */ |
188 | /* return a WARNING status if we couldn't read any data */ | 197 | /* return a WARNING status if we couldn't read any data */ |
189 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { | 198 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { |
@@ -478,6 +487,7 @@ process_arguments (int argc, char **argv) | |||
478 | {"starttls",no_argument,0,'S'}, | 487 | {"starttls",no_argument,0,'S'}, |
479 | {"certificate",required_argument,0,'D'}, | 488 | {"certificate",required_argument,0,'D'}, |
480 | {"ignore-quit-failure",no_argument,0,'q'}, | 489 | {"ignore-quit-failure",no_argument,0,'q'}, |
490 | {"proxy",no_argument,0,'r'}, | ||
481 | {0, 0, 0, 0} | 491 | {0, 0, 0, 0} |
482 | }; | 492 | }; |
483 | 493 | ||
@@ -494,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
494 | } | 504 | } |
495 | 505 | ||
496 | while (1) { | 506 | while (1) { |
497 | c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", | 507 | c = getopt_long (argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", |
498 | longopts, &option); | 508 | longopts, &option); |
499 | 509 | ||
500 | if (c == -1 || c == EOF) | 510 | if (c == -1 || c == EOF) |
@@ -621,6 +631,9 @@ process_arguments (int argc, char **argv) | |||
621 | use_ssl = TRUE; | 631 | use_ssl = TRUE; |
622 | use_ehlo = TRUE; | 632 | use_ehlo = TRUE; |
623 | break; | 633 | break; |
634 | case 'r': | ||
635 | use_proxy_prefix = TRUE; | ||
636 | break; | ||
624 | case 'L': | 637 | case 'L': |
625 | use_lhlo = TRUE; | 638 | use_lhlo = TRUE; |
626 | break; | 639 | break; |
@@ -819,6 +832,8 @@ print_help (void) | |||
819 | printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), | 832 | printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), |
820 | printf (" %s\n", "-F, --fqdn=STRING"); | 833 | printf (" %s\n", "-F, --fqdn=STRING"); |
821 | printf (" %s\n", _("FQDN used for HELO")); | 834 | printf (" %s\n", _("FQDN used for HELO")); |
835 | printf (" %s\n", "-r, --proxy"); | ||
836 | printf (" %s\n", _("Use PROXY protocol prefix for the connection.")); | ||
822 | #ifdef HAVE_SSL | 837 | #ifdef HAVE_SSL |
823 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); | 838 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); |
824 | printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); | 839 | printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); |