Merge lp:~martin-hilton/charm-haproxy/000-check_haproxy-https-services into lp:charm-haproxy

Proposed by Martin Hilton
Status: Merged
Approved by: Adam Collard
Approved revision: 109
Merged at revision: 106
Proposed branch: lp:~martin-hilton/charm-haproxy/000-check_haproxy-https-services
Merge into: lp:charm-haproxy
Diff against target: 59 lines (+21/-26)
1 file modified
files/nrpe/check_haproxy.sh (+21/-26)
To merge this branch: bzr merge lp:~martin-hilton/charm-haproxy/000-check_haproxy-https-services
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Adam Collard (community) Approve
Free Ekanayaka (community) Needs Information
Review via email: mp+308041@code.launchpad.net

Commit message

Update NRPE check to support Xenial.

Parse CSV from haproxy's HTTP stats interface

Description of the change

This adds support for HTTPS services in the check_haproxy script. The script is courtesy of Canonical IS.

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

A couple of remarks below.

review: Needs Information
107. By Martin Hilton

check_haproxy: Get the "stats socket" from the configuration

Revision history for this message
Adam Collard (adam-collard) wrote :

This will only work if global_stats_socket config option is turned on, which is not true for all deployments.

I think we can keep the CSV parsing but grab it over HTTP.

e.g.

$ curl 'http://localhost:10000/;csv' -u haproxy:haproxy

review: Needs Fixing
108. By Martin Hilton

return to using http, but get csv in stead of html

Revision history for this message
Adam Collard (adam-collard) :
Revision history for this message
Martin Hilton (martin-hilton) :
109. By Martin Hilton

more review updates

Revision history for this message
Adam Collard (adam-collard) wrote :

Looks good, +1

Thanks for the re-work, think it's good to land.

review: Approve
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'files/nrpe/check_haproxy.sh'
--- files/nrpe/check_haproxy.sh 2016-07-07 16:50:53 +0000
+++ files/nrpe/check_haproxy.sh 2016-10-25 11:31:20 +0000
@@ -3,34 +3,29 @@
3# This file is managed by Juju3# This file is managed by Juju
4#--------------------------------------------4#--------------------------------------------
5#5#
6# Copyright 2009,2012 Canonical Ltd.6# Copyright 2009,2012,2016 Canonical Ltd.
7# Author: Tom Haddon7# Author: Tom Haddon, Junien Fridrick, Martin Hilton
88
9CRITICAL=09set -e
10NOTACTIVE=''10set -o pipefail
11LOGFILE=/var/log/nagios/check_haproxy.log11
12export LOGFILE=/var/log/nagios/check_haproxy.log
12AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}')13AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}')
1314
14HAPROXY_VERSION="$(dpkg-query -W --showformat='${Version}\n' haproxy)"15NOTACTIVE=$(curl -s -f -u ${AUTH} "http://localhost:10000/;csv"|awk -F, -v SVNAME=2 -v STATUS=18 '
15if dpkg --compare-versions "$HAPROXY_VERSION" ge 1.5; then16 $1 ~ "^#" { next }
16 CLASS_REGEX='(active_up|backup_up)'17 $SVNAME ~ "(FRONT|BACK)END" { next }
17else18 $STATUS != "UP" {
18 CLASS_REGEX='(active|backup)(2|3)'19 "date"| getline date
19fi20 print date >> ENVIRON["LOGFILE"]
2021 printf("Server %s is in status %s\n", $SVNAME, $STATUS) >> ENVIRON["LOGFILE"]
21for appserver in $(grep ' server' /etc/haproxy/haproxy.cfg | awk '{print $2'});22 print $0 >> ENVIRON["LOGFILE"]
22do23 na[na_count++] = $SVNAME
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 }
24 if [ $? != 0 ]; then25 END { ORS=" "; for (i=0; i < na_count; i++) { print na[i] }}
25 date >> $LOGFILE26')
26 echo $output >> $LOGFILE27
27 /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 10000 -v | grep $appserver >> $LOGFILE 2>&128if [ -n "$NOTACTIVE" ]; then
28 CRITICAL=1
29 NOTACTIVE="${NOTACTIVE} $appserver"
30 fi
31done
32
33if [ $CRITICAL = 1 ]; then
34 echo "CRITICAL:${NOTACTIVE}"29 echo "CRITICAL:${NOTACTIVE}"
35 exit 230 exit 2
36fi31fi

Subscribers

People subscribed via source and target branches

to all changes: