Email Notification haproxy
-
Hello,
I have currently haproxy-devel v 0.59_14 and pfSense 2.4.4. Occasionally i have a backend for a website showing status down. Is it possible to get an email notification to an email address when the backend status goes down? In the settings page for haproxy I added the information in the Global Email Notification section but i never got notified when i deliberately set the backend status to down. Do i need to select a specific dropdown choice the mail level? Any help would be much appreciated.
Thanks,
Karl
-
@kiekar
You do have a mailserver configured for haproxy to use that accepts incoming mails without authentication nor encryption? As haproxy just tries to send few plain text smtp commands when for example a health-check fails.. -
@kiekar
p.s. you might want to checkout some of these lua scripts i made, they produce less 'bulk mail' when something happens than haproxy's own mail notification method.. https://github.com/PiBa-NL/MyPublicProjects/tree/master/haproxy/lua-scripts
Though still should get a bit of tweaking to become truly 'beautiful' ;).. -
Thanks for your reply. I do have a mail server and I do currently have it setup with pfsense through Sysytem>Advanced>Notification which works. As for the setup in haproxy, i'm not sure if this is correct.
-
@kiekar
It looks like it 'should' work like that.. (Though the 'Mail myhostname' could probably be something like pfsense.yourdomain.com)Perhaps you can perform a packetcapture from between haproxy and the mailserver and watch if it tries to connect and mail something on startup? The smtp traffic is 'readable' if you capture the content, it should be possible to see why it isn't working.. I presume the backends dont have the level set to 'don't mail' setting?
Can you check haproxy.cfg contains a reference to the 'globalmailer' in each backend?
-
Will the lua script work if the backend goes down? If so what files do i need in order for the email notification to work as I saw files and folders at the link you provided.
-
@kiekar
You would need 3 scripts:/smtpmailqueue/smtpmailqueue.lua /serverhealthchecker/serverhealthchecker.lua /serverhealth_smtpmail.lua
And edit the 3rd to use proper mailserver and email address for at least the destination. Just putting their content into the haproxy files tab and mark them as type lua, it should work and send a mail if the backend go's down or comes back up. Also after startup it always sends 1 mail.
-
Thanks for you help up to now, much appreciated.
I added 3 separate entries to haproxy based on the 3 files you indicated. When saving the entries i received an Error shown below.
Does the passed variable "lumamailer" in Smtpmailqueue("lumamailer",5) need to replaced by mailer servers table name "mailer1" from the Global email notifications in settings tab I had setup?
haproxy: startup error output!: [ALERT] 335/102935 (32469) : parsing [/var/etc/haproxy/haproxy.cfg:16] : lua runtime error: /var/etc/haproxy/luascript_serverhealth_smtpmail:6: attempt to call a nil value (global 'Smtpmailqueue')[ALERT] 335/102935 (32469) : Error(s) found in configuration file : /var/etc/haproxy/haproxy.cfg[ALERT] 335/102935 (32469) : Fatal errors found in configuration.
-
@kiekar
I think the order is important, can you move the serverhealth_smtpmail.lua as the last script.? -
"I think the order is important, can you move the serverhealth_smtpmail.lua as the last script"
That did the trick.
Tested by deliberately shutting down the site, all worked perfectly.
Thanks again!!