github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/trusty/haproxy/files/nrpe/check_haproxy.sh (about) 1 #!/bin/bash 2 #-------------------------------------------- 3 # This file is managed by Juju 4 #-------------------------------------------- 5 # 6 # Copyright 2009,2012 Canonical Ltd. 7 # Author: Tom Haddon 8 9 CRITICAL=0 10 NOTACTIVE='' 11 LOGFILE=/var/log/nagios/check_haproxy.log 12 AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}') 13 14 HAPROXY_VERSION="$(dpkg-query -W --showformat='${Version}\n' haproxy)" 15 if dpkg --compare-versions "$HAPROXY_VERSION" ge 1.5; then 16 CLASS_REGEX='(active|backup)(3|4)' 17 else 18 CLASS_REGEX='(active|backup)(2|3)' 19 fi 20 21 for appserver in $(grep ' server' /etc/haproxy/haproxy.cfg | awk '{print $2'}); 22 do 23 output=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 10000 --regex="class=\"$CLASS_REGEX.*${appserver}" -e ' 200 OK') 24 if [ $? != 0 ]; then 25 date >> $LOGFILE 26 echo $output >> $LOGFILE 27 /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 10000 -v | grep $appserver >> $LOGFILE 2>&1 28 CRITICAL=1 29 NOTACTIVE="${NOTACTIVE} $appserver" 30 fi 31 done 32 33 if [ $CRITICAL = 1 ]; then 34 echo "CRITICAL:${NOTACTIVE}" 35 exit 2 36 fi 37 38 echo "OK: All haproxy instances looking good" 39 exit 0