Alerts and monitoring
Email alerts
Email alerts can be a crucial part of your monitoring and alerting strategy, enabling you to stay informed about the health of your servers.
You can configure email alerts to get notifications about load balancer events. When an event is generated, it is categorized under a specific level of importance. These levels range from debug (the least serious) to emergency (the most serious). You will set the level for which you want to receive alerts.
Alerts will be sent when:
- An active server is marked as down and the configured alert level is
alert
or lower. - A disabled server is marked as down and the configured alert level is
notice
or lower. - A server is marked as up or enters the drain state and the configured alert level is
notice
or lower. - The
option log-health-checks
directive is enabled with the configured alert level asinfo
or lower, and a health check status update occurs.
Configure mail servers Jump to heading
You must first configure a mailers
section where you list Message Transfer Agent (MTA) servers. These servers deliver your messages to recipients using the SMTP protocol. The load balancer sends an email to each mail server in the list. You can define multiple mailer
sections.
-
Create a new
mailers
section in your configuration file with a label of your choice, such assmtp_servers
. In the example below, we list two MTA servers:haproxymailers smtp_serversmailer smtp1 192.168.1.10:587mailer smtp2 192.168.1.11:587haproxymailers smtp_serversmailer smtp1 192.168.1.10:587mailer smtp2 192.168.1.11:587A
mailer
line has these arguments:- A label, such as
smtp1
- An IP address and port
- A label, such as
-
Add
email-alert
directives to afrontend
ordefaults
section:haproxydefaultsmode httplog globaloption httplogtimeout connect 10stimeout client 1mtimeout server 1m# email settingsemail-alert mailers smtp_serversemail-alert from alerts@mycompany.comemail-alert to helpdesk@mycompany.comemail-alert level infoemail-alert myhostname LoadBalancer1haproxydefaultsmode httplog globaloption httplogtimeout connect 10stimeout client 1mtimeout server 1m# email settingsemail-alert mailers smtp_serversemail-alert from alerts@mycompany.comemail-alert to helpdesk@mycompany.comemail-alert level infoemail-alert myhostname LoadBalancer1In this example:
email-alert mailers [mailersectionname]
sets themailers
section to use to send emails.email-alert from [emailaddr]
sets the email sender’s address, also known as the From field.email-alert to [emailaddr]
sets the recipient’s address, also known as the To field.email-alert level [level]
sets the maximum log level of messages for which email alerts will go out; The<level>
can be any of these syslog levels:emerg
alert
,crit
,err
,warning
,notice
,info
,debug
.email-alert myhostname [hostname]
sets the hostname to use when communicating with mailers; by default, it is the system’s hostname.
Enable the Lua implementation Jump to heading
Available since
- HAProxy 2.8
- HAProxy Enterprise 2.8r1
- Not available on HAProxy ALOHA
The alerts feature is compiled into the software, making it impossible to customize. If, however, you wish to make changes to the email template, start by enabling the Lua implementation. It is a drop-in replacement for the compiled-in implementation, but allows you to edit the code.
-
Add the
lua-load
directive to yourglobal
section. For HAProxy Enterprise:haproxygloballua-load /opt/hapee-3.0/doc/lua/mailers.luahaproxygloballua-load /opt/hapee-3.0/doc/lua/mailers.luaFor HAProxy, download
mailers.lua
from GitHub: -
Make changes to the Lua file to suit your needs.
-
Reload the load balancer configuration.
See also Jump to heading
Do you have any suggestions on how we can improve the content of this page?