Monitoring HAProxy Status Page

A local check to login to a local HAproxy status page and check site status for each site listed.
nano /usr/lib/check_mk_agent/local/check-haproxy

#!/bin/bash

# Set environment variables (New line is the only separator)
IFS=$’\n’
set -f

# Login to haproxy and retrieve site list
for i in $(curl -u admin:password -Ls http://localhost/admin?stats | grep “td class=”ac””)
do

# Skip false pages
if [[ $i == *”end”* ]]; then
:
else
n=$(echo $i | awk -F’a name=”‘ ‘{print $2}’ | sed ‘s/ *\”.*//’)
ss=$(echo $i | awk -F’tr class=”active_’ ‘{print $2}’ | sed ‘s/ *\”.*//’ | sed ‘/^$/d’)

# Check result to determine of site is up or down
if [[ $ss == *”up”* ]]; then
s=0
st=”Site $n is Up”
else
s=2
st=”Site $n is Down”
fi
echo “$s haproxy_$n varname=2;crit $st”
fi
done

chmod +x /usr/lib/check_mk_agent/local/check-haproxy

Now simply re-inventory your server to pick up the new checks.

Any comments or questions? Get in touch here or Email me at [email protected]