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
1=== modified file 'files/nrpe/check_haproxy.sh'
2--- files/nrpe/check_haproxy.sh 2016-07-07 16:50:53 +0000
3+++ files/nrpe/check_haproxy.sh 2016-10-25 11:31:20 +0000
4@@ -3,34 +3,29 @@
5 # This file is managed by Juju
6 #--------------------------------------------
7 #
8-# Copyright 2009,2012 Canonical Ltd.
9-# Author: Tom Haddon
10-
11-CRITICAL=0
12-NOTACTIVE=''
13-LOGFILE=/var/log/nagios/check_haproxy.log
14+# Copyright 2009,2012,2016 Canonical Ltd.
15+# Author: Tom Haddon, Junien Fridrick, Martin Hilton
16+
17+set -e
18+set -o pipefail
19+
20+export LOGFILE=/var/log/nagios/check_haproxy.log
21 AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}')
22
23-HAPROXY_VERSION="$(dpkg-query -W --showformat='${Version}\n' haproxy)"
24-if dpkg --compare-versions "$HAPROXY_VERSION" ge 1.5; then
25- CLASS_REGEX='(active_up|backup_up)'
26-else
27- CLASS_REGEX='(active|backup)(2|3)'
28-fi
29-
30-for appserver in $(grep ' server' /etc/haproxy/haproxy.cfg | awk '{print $2'});
31-do
32- output=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 10000 --regex="class=\"$CLASS_REGEX.*${appserver}" -e ' 200 OK')
33- if [ $? != 0 ]; then
34- date >> $LOGFILE
35- echo $output >> $LOGFILE
36- /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 10000 -v | grep $appserver >> $LOGFILE 2>&1
37- CRITICAL=1
38- NOTACTIVE="${NOTACTIVE} $appserver"
39- fi
40-done
41-
42-if [ $CRITICAL = 1 ]; then
43+NOTACTIVE=$(curl -s -f -u ${AUTH} "http://localhost:10000/;csv"|awk -F, -v SVNAME=2 -v STATUS=18 '
44+ $1 ~ "^#" { next }
45+ $SVNAME ~ "(FRONT|BACK)END" { next }
46+ $STATUS != "UP" {
47+ "date"| getline date
48+ print date >> ENVIRON["LOGFILE"]
49+ printf("Server %s is in status %s\n", $SVNAME, $STATUS) >> ENVIRON["LOGFILE"]
50+ print $0 >> ENVIRON["LOGFILE"]
51+ na[na_count++] = $SVNAME
52+ }
53+ END { ORS=" "; for (i=0; i < na_count; i++) { print na[i] }}
54+')
55+
56+if [ -n "$NOTACTIVE" ]; then
57 echo "CRITICAL:${NOTACTIVE}"
58 exit 2
59 fi

Subscribers

People subscribed via source and target branches

to all changes: