summaryrefslogtreecommitdiffstats
path: root/reg-tests/mailers
diff options
context:
space:
mode:
Diffstat (limited to 'reg-tests/mailers')
-rw-r--r--reg-tests/mailers/healthcheckmail.lua70
-rw-r--r--reg-tests/mailers/healthcheckmail.vtc60
l---------reg-tests/mailers/mailers.lua1
3 files changed, 131 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..208d350
--- /dev/null
+++ b/reg-tests/mailers/healthcheckmail.vtc
@@ -0,0 +1,60 @@
+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}/mailers.lua
+ 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
diff --git a/reg-tests/mailers/mailers.lua b/reg-tests/mailers/mailers.lua
new file mode 120000
index 0000000..5ea4673
--- /dev/null
+++ b/reg-tests/mailers/mailers.lua
@@ -0,0 +1 @@
+../../examples/lua/mailers.lua \ No newline at end of file