]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn/mailers: handle timeout mail from mailers section
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 7 Jul 2023 14:55:43 +0000 (16:55 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 10 Jul 2023 16:28:08 +0000 (18:28 +0200)
As the example/lua/mailers.lua script does its best to mimic the c-mailer
implementation, it should support the "timeout mail" directive as well.

This could be backported in 2.8.

doc/lua-api/index.rst
examples/lua/mailers.lua
src/hlua_fcn.c

index c635741ab95a8048bd48e2447badc264bde61aae..d2720d22c8a2411c71014b664d87b9be95394a3d 100644 (file)
@@ -1198,6 +1198,12 @@ ProxyMailers class
   Each array entry is a name:desc pair where desc represents the full server
   address (including port) as described in haproxy's configuration file.
 
+.. js:attribute:: ProxyMailers.mailservers_timeout
+
+  An integer representing the maximum time in milliseconds to wait for the
+  email to be sent. See "timeout mail" directive from "mailers" section in
+  haproxy configuration file.
+
 .. js:attribute:: ProxyMailers.smtp_hostname
 
   A string containing the hostname to use for the SMTP transaction.
index c7ffa03762bc3ff1d93bc92df77ca3a6c2060e33..0d146ff173eb391eb984989af862698f0c634a06 100644 (file)
@@ -30,7 +30,9 @@ local mailqueue = core.queue()
 -- same format used in haproxy config file. It will be passed as it is to
 -- tcp::connect() without explicit port argument. See Socket.connect()
 -- manual for more information.
-function smtp_send_email(server, domain, from, to, data)
+--
+-- The function will abort after <timeout> ms
+function smtp_send_email(server, timeout, domain, from, to, data)
         local ret
         local reason
         local tcp = core.tcp()
@@ -55,6 +57,10 @@ function smtp_send_email(server, domain, from, to, data)
                 end
         end
 
+       if timeout ~= 0 then
+               tcp:settimeout(timeout / 1000)
+       end
+
         if tcp:connect(server) == nil then
                 return false, "Can't connect to \""..server.."\""
         end
@@ -406,6 +412,7 @@ core.register_task(function()
                        for name, mailsrv in pairs(job.mailconf.mailservers) do
                                -- finally, send email to server
                                local ret, reason = smtp_send_email(mailsrv,
+                                                                   job.mailconf.mailservers_timeout,
                                                                    job.mailconf.smtp_hostname,
                                                                    job.mailconf.smtp_from,
                                                                    job.mailconf.smtp_to,
index a92daa3b03e5bcc158a7ce4a50560221fef25166..91c5155d22bdb7a001e48fcf72d911c2f61ce651 100644 (file)
@@ -2134,6 +2134,11 @@ int hlua_proxy_get_mailers(lua_State *L)
        }
        lua_settable(L, -3);
 
+       /* mailers timeout (from mailers section) */
+       lua_pushstring(L, "mailservers_timeout");
+       lua_pushinteger(L, px->email_alert.mailers.m->timeout.mail);
+       lua_settable(L, -3);
+
        /* email-alert myhostname */
        lua_pushstring(L, "smtp_hostname");
        lua_pushstring(L, px->email_alert.myhostname);