diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:35:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:35:11 +0000 |
commit | da76459dc21b5af2449af2d36eb95226cb186ce2 (patch) | |
tree | 542ebb3c1e796fac2742495b8437331727bbbfa0 /reg-tests/mailers | |
parent | Initial commit. (diff) | |
download | haproxy-da76459dc21b5af2449af2d36eb95226cb186ce2.tar.xz haproxy-da76459dc21b5af2449af2d36eb95226cb186ce2.zip |
Adding upstream version 2.6.12.upstream/2.6.12upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'reg-tests/mailers')
-rw-r--r-- | reg-tests/mailers/healthcheckmail.lua | 70 | ||||
-rw-r--r-- | reg-tests/mailers/healthcheckmail.vtc | 59 |
2 files changed, 129 insertions, 0 deletions
diff --git a/reg-tests/mailers/healthcheckmail.lua b/reg-tests/mailers/healthcheckmail.lua new file mode 100644 index 0000000..4cb0e9d --- /dev/null +++ b/reg-tests/mailers/healthcheckmail.lua @@ -0,0 +1,70 @@ + +local vtc_port1 = 0 +local mailsreceived = 0 +local mailconnectionsmade = 0 +local healthcheckcounter = 0 + +function RecieveAndCheck(applet, expect) + data = applet:getline() + if data:sub(1,expect:len()) ~= expect then + core.Info("Expected: "..expect.." but got:"..data:sub(1,expect:len())) + applet:send("Expected: "..expect.." but got:"..data.."\r\n") + return false + end + return true +end + +core.register_service("mailservice", "tcp", function(applet) + core.Info("############# Mailservice Called #############") + mailconnectionsmade = mailconnectionsmade + 1 + applet:send("220 Welcome\r\n") + local data + + if RecieveAndCheck(applet, "HELO") == false then + applet:set_var("txn.result", "ERROR (step: HELO)") + return + end + applet:send("250 OK\r\n") + if RecieveAndCheck(applet, "MAIL FROM:") == false then + applet:set_var("txn.result", "ERROR (step: MAIL FROM)") + return + end + applet:send("250 OK\r\n") + if RecieveAndCheck(applet, "RCPT TO:") == false then + applet:set_var("txn.result", "ERROR (step: RCPT TO)") + return + end + applet:send("250 OK\r\n") + if RecieveAndCheck(applet, "DATA") == false then + applet:set_var("txn.result", "ERROR (step: DATA)") + return + end + applet:send("354 OK\r\n") + core.Info("#### Send your mailbody") + local endofmail = false + local subject = "" + while endofmail ~= true do + data = applet:getline() -- BODY CONTENT + --core.Info(data) + if data:sub(1, 9) == "Subject: " then + subject = data + end + if (data == "\r\n") then + data = applet:getline() -- BODY CONTENT + core.Info(data) + if (data == ".\r\n") then + endofmail = true + end + end + end + core.Info("#### Body received OK") + applet:send("250 OK\r\n") + + if RecieveAndCheck(applet, "QUIT") == false then + applet:set_var("txn.result", "ERROR (step: QUIT)") + return + end + applet:send("221 Mail queued for delivery to /dev/null \r\n") + core.Info("Mail queued for delivery to /dev/null subject: "..subject) + applet:set_var("txn.result", "SUCCESS") +end) diff --git a/reg-tests/mailers/healthcheckmail.vtc b/reg-tests/mailers/healthcheckmail.vtc new file mode 100644 index 0000000..821250f --- /dev/null +++ b/reg-tests/mailers/healthcheckmail.vtc @@ -0,0 +1,59 @@ +varnishtest "Check health-check email alerts" +#REQUIRE_OPTIONS=LUA + +feature ignore_unknown_macro + +syslog S1 -level notice { + recv + expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 failed.+check duration: [[:digit:]]+ms.+status: 0/1 DOWN." + recv info + expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Result=SUCCESS Bytes=[[:digit:]]+" +} -start + +haproxy h1 -conf { + global + lua-load ${testdir}/healthcheckmail.lua + + defaults + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + + listen lisrv + mode tcp + bind "fd@${lisrv}" + tcp-request connection reject + + listen lismtp + mode tcp + bind "fd@${lismtp}" + log ${S1_addr}:${S1_port} daemon + log-format "Result=%[var(txn.result)] Bytes=%B" + tcp-request content use-service lua.mailservice + + frontend fe1 + mode http + bind "fd@${fe1}" + default_backend be1 + + backend be1 + mode http + log ${S1_addr}:${S1_port} daemon + option httpchk + option log-health-checks + + default-server inter 200ms downinter 100ms rise 1 fall 1 + + email-alert mailers mymailers + email-alert level info + email-alert from from@domain.tld + email-alert to to@domain.tld + + server srv1 ${h1_lisrv_addr}:${h1_lisrv_port} check + + mailers mymailers + mailer smtp1 ${h1_lismtp_addr}:${h1_lismtp_port} + +} -start + +syslog S1 -wait |