]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mailers: make it possible to configure the connection timeout
authorPieter Baauw <piba.nl.dev@gmail.com>
Sat, 13 Feb 2016 14:33:40 +0000 (15:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 20 Feb 2016 14:33:06 +0000 (15:33 +0100)
This patch introduces a configurable connection timeout for mailers
with a new "timeout mail <time>" directive.

Acked-by: Simon Horman <horms@verge.net.au>
doc/configuration.txt
include/types/mailers.h
src/cfgparse.c
src/checks.c

index f55f68dd68ec9c886d07460571970a227dd428d1..279d07601f24ddf7b5ffef4b07eaf024600621ee 100644 (file)
@@ -1574,6 +1574,16 @@ mailer <mailername> <ip>:<port>
         server srv1 192.168.0.30:80
         server srv2 192.168.0.31:80
 
+timeout mail <time>
+  Defines the time available for a mail/connection to be made and send to
+  the mail-server. If not defined the default value is 10 seconds. To allow
+  for at least two SYN-ACK packets to be send during initial TCP handshake it
+  is advised to keep this value above 4 seconds.
+
+  Example:
+    mailers mymailers
+        timeout mail 20s
+        mailer smtp1 192.168.0.1:587
 
 4. Proxies
 ----------
index 07374a732061d814968bdd50f72ba50065b191fa..2b884429833006c12ad877fdcf51916a747f329d 100644 (file)
@@ -56,6 +56,9 @@ struct mailers {
        struct mailers *next;           /* next mailers section */
        int count;                      /* total number of mailers in this mailers section */
        int users;                      /* number of users of this mailers section */
+       struct {                        /* time to: */
+               int mail;               /*   try connecting to mailserver and sending a email */
+       } timeout;
 };
 
 
index 99e97c7de551978ef422a8fef2957c19a3893068..dd6f8a23f87640ba1a4bd7394358aacea3992be8 100644 (file)
@@ -2537,6 +2537,9 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
                curmailers->conf.file = strdup(file);
                curmailers->conf.line = linenum;
                curmailers->id = strdup(args[1]);
+               curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
+                       * But need enough time so that timeouts don't occur
+                       * during tcp procssing. For now just us an arbitrary default. */
        }
        else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
                struct sockaddr_storage *sk;
@@ -2607,7 +2610,43 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
                newmailer->proto = proto;
                newmailer->xprt  = &raw_sock;
                newmailer->sock_init_arg = NULL;
-       } /* neither "mailer" nor "mailers" */
+       }
+       else if (strcmp(args[0], "timeout") == 0) {
+               if (!*args[1]) {
+                       Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
+                               file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+               else if (strcmp(args[1], "mail") == 0) {
+                       const char *res;
+                       unsigned int timeout_mail;
+                       if (!*args[2]) {
+                               Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
+                                       file, linenum, args[0], args[1]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+                       res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
+                       if (res) {
+                               Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
+                                       file, linenum, *res, args[0]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+                       if (timeout_mail <= 0) {
+                               Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+                       curmailers->timeout.mail = timeout_mail;
+               } else {
+                       Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
+                               file, linenum, args[0], args[1]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+       }
        else if (*args[0] != 0) {
                Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
                err_code |= ERR_ALERT | ERR_FATAL;
index 4d3b39345ce1539a7a75031672f78d89710c1d43..35fd020e3e2c55fe7e3b61114ed7cf4915861a9c 100644 (file)
@@ -3108,9 +3108,7 @@ static int init_email_alert_checks(struct server *s)
 
                LIST_INIT(&q->email_alerts);
 
-               check->inter = DEF_MAILALERTTIME; /* XXX: Would like to Skip to the next alert, if any, ASAP.
-                                            * But need enough time so that timeouts don't occur
-                                            * during tcp check procssing. For now just us an arbitrary default. */
+               check->inter = p->email_alert.mailers.m->timeout.mail;
                check->rise = DEF_AGENT_RISETIME;
                check->fall = DEF_AGENT_FALLTIME;
                err_str = init_check(check, PR_O2_TCPCHK_CHK);