HAProxy Alerts (for V7 Loadbalancer.org Appliance)

In this Blog I show a very simple solution to get Layer 7 (HAProxy) alerts configured using Logwatch.

First from the WUI :

1. Set the external relay(Smart Host) under Edit Configuration > Physical – Advanced Configuration.

phys-adv-shot

2. Enable HAProxy Logging under Edit Configuration > Layer 7 – Advanced Configuration.

l7-adv

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@mydomain.comMailFrom = 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).

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 = ;print "Lines that matched $findn";for (@lines)      if ($_ =~ /$find/)          print "$_n";      }

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 :

*/01 * * * * nice -n 19 /usr/sbin/logwatch --service layer7 --range '-1 minutes for that minute'

c. Restart crond with :

[root@lbmaster ~]# service crond restart

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 Alerts (for V7 Loadbalancer.org Appliance)

Leave a Reply

Your email address will not be published. Required fields are marked *