In this guide I show a very simple solution to get HAProxy email alerts configured using Logwatch. While the first part is aimed at users of our V7 appliance I think anyone wanting to get email alerts for HAProxy will also find this a good example.
First from the WUI :
1. Set the external relay(Smart Host) under Edit Configuration > Physical – Advanced Configuration.
2. Enable HAProxy Logging under Edit Configuration > Layer 7 – Advanced Configuration.
Then from the CLI :
1. Install the logwatch package using yum like so :
[root@lbmaster ~]# yum --disableexcludes=all install logwatch
2. Create the following file and set your To/From email addresses : /etc/logwatch/conf/logwatch.conf
MailTo = myemailaddress@example.com MailFrom = LBMaster@example.com |
At this point you’ll have a standard Logwatch install which will send an email once per day (you may want to disable this).
*To disable the daily logwatch email execute : chmod -x /etc/cron.daily/0logwatch
3. Create a custom Layer 7 check
a. Create the following file adding the contents below : /etc/logwatch/conf/logfiles/layer7.conf
LogFile = /var/log/haproxy.log *OnlyHost *ApplyStdDate |
b. Next create the script : /etc/logwatch/scripts/services/layer7
use strict; my $find = "is UP|is DOWN"; my @lines = |
c. Finally create the following file : /etc/logwatch/conf/services/layer7.conf
Title = "Layer 7 Errors" LogFile = layer7 |
4. Enable the Logwatch job to run every minute with Cron
a. Edit crontab with the following command :
[root@lbmaster ~]# crontab -e
b. Add the following new line to root’s crontab :
*/01 * * * * /bin/nice -n 19 /usr/sbin/logwatch --service layer7 --range '-1 minutes for that minute' |
Once this is complete you’ll now receive an email in the event of a real server failure. The way this works is that logwatch will run every minute and search the previous minutes log entries for servers that are taken down or brought up during that time.
You Can Learn More About the LoadBalancer.org’s Product Line By Going to www.LoadBalancerSolutions.com/LoadBalancer-org
The original article/video can be found at HAProxy Email Alerts Guide