Merge lp:~brad-marshall/charm-helpers/add-nrpe-checks into lp:charm-helpers

Proposed by Brad Marshall
Status: Merged
Merged at revision: 314
Proposed branch: lp:~brad-marshall/charm-helpers/add-nrpe-checks
Merge into: lp:charm-helpers
Diff against target: 147 lines (+117/-0)
4 files modified
charmhelpers/contrib/charmsupport/nrpe.py (+37/-0)
charmhelpers/contrib/openstack/files/__init__.py (+18/-0)
charmhelpers/contrib/openstack/files/check_haproxy.sh (+32/-0)
charmhelpers/contrib/openstack/files/check_haproxy_queue_depth.sh (+30/-0)
To merge this branch: bzr merge lp:~brad-marshall/charm-helpers/add-nrpe-checks
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+250097@code.launchpad.net

Description of the change

Add functions to copy nrpe checks, and add haproxy checks

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/charmsupport/nrpe.py'
2--- charmhelpers/contrib/charmsupport/nrpe.py 2015-02-18 07:48:37 +0000
3+++ charmhelpers/contrib/charmsupport/nrpe.py 2015-02-18 08:02:00 +0000
4@@ -24,6 +24,8 @@
5 import pwd
6 import grp
7 import os
8+import glob
9+import shutil
10 import re
11 import shlex
12 import yaml
13@@ -319,3 +321,38 @@
14 check_cmd='check_status_file.py -f '
15 '/var/lib/nagios/service-check-%s.txt' % svc,
16 )
17+
18+
19+def copy_nrpe_checks():
20+ """
21+ Copy the nrpe checks into place
22+
23+ """
24+ NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
25+ nrpe_files_dir = os.path.join(os.getenv('CHARM_DIR'), 'hooks',
26+ 'charmhelpers', 'contrib', 'openstack',
27+ 'files')
28+
29+ if not os.path.exists(NAGIOS_PLUGINS):
30+ os.makedirs(NAGIOS_PLUGINS)
31+ for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):
32+ if os.path.isfile(fname):
33+ shutil.copy2(fname,
34+ os.path.join(NAGIOS_PLUGINS, os.path.basename(fname)))
35+
36+
37+def add_haproxy_checks(nrpe, unit_name):
38+ """
39+ Add checks for each service in list
40+
41+ :param NRPE nrpe: NRPE object to add check to
42+ :param str unit_name: Unit name to use in check description
43+ """
44+ nrpe.add_check(
45+ shortname='haproxy_servers',
46+ description='Check HAProxy {%s}' % unit_name,
47+ check_cmd='check_haproxy.sh')
48+ nrpe.add_check(
49+ shortname='haproxy_queue',
50+ description='Check HAProxy queue depth {%s}' % unit_name,
51+ check_cmd='check_haproxy_queue_depth.sh')
52
53=== added directory 'charmhelpers/contrib/openstack/files'
54=== added file 'charmhelpers/contrib/openstack/files/__init__.py'
55--- charmhelpers/contrib/openstack/files/__init__.py 1970-01-01 00:00:00 +0000
56+++ charmhelpers/contrib/openstack/files/__init__.py 2015-02-18 08:02:00 +0000
57@@ -0,0 +1,18 @@
58+# Copyright 2014-2015 Canonical Limited.
59+#
60+# This file is part of charm-helpers.
61+#
62+# charm-helpers is free software: you can redistribute it and/or modify
63+# it under the terms of the GNU Lesser General Public License version 3 as
64+# published by the Free Software Foundation.
65+#
66+# charm-helpers is distributed in the hope that it will be useful,
67+# but WITHOUT ANY WARRANTY; without even the implied warranty of
68+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69+# GNU Lesser General Public License for more details.
70+#
71+# You should have received a copy of the GNU Lesser General Public License
72+# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
73+
74+# dummy __init__.py to fool syncer into thinking this is a syncable python
75+# module
76
77=== added file 'charmhelpers/contrib/openstack/files/check_haproxy.sh'
78--- charmhelpers/contrib/openstack/files/check_haproxy.sh 1970-01-01 00:00:00 +0000
79+++ charmhelpers/contrib/openstack/files/check_haproxy.sh 2015-02-18 08:02:00 +0000
80@@ -0,0 +1,32 @@
81+#!/bin/bash
82+#--------------------------------------------
83+# This file is managed by Juju
84+#--------------------------------------------
85+#
86+# Copyright 2009,2012 Canonical Ltd.
87+# Author: Tom Haddon
88+
89+CRITICAL=0
90+NOTACTIVE=''
91+LOGFILE=/var/log/nagios/check_haproxy.log
92+AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}')
93+
94+for appserver in $(grep ' server' /etc/haproxy/haproxy.cfg | awk '{print $2'});
95+do
96+ output=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 --regex="class=\"(active|backup)(2|3).*${appserver}" -e ' 200 OK')
97+ if [ $? != 0 ]; then
98+ date >> $LOGFILE
99+ echo $output >> $LOGFILE
100+ /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 -v | grep $appserver >> $LOGFILE 2>&1
101+ CRITICAL=1
102+ NOTACTIVE="${NOTACTIVE} $appserver"
103+ fi
104+done
105+
106+if [ $CRITICAL = 1 ]; then
107+ echo "CRITICAL:${NOTACTIVE}"
108+ exit 2
109+fi
110+
111+echo "OK: All haproxy instances looking good"
112+exit 0
113
114=== added file 'charmhelpers/contrib/openstack/files/check_haproxy_queue_depth.sh'
115--- charmhelpers/contrib/openstack/files/check_haproxy_queue_depth.sh 1970-01-01 00:00:00 +0000
116+++ charmhelpers/contrib/openstack/files/check_haproxy_queue_depth.sh 2015-02-18 08:02:00 +0000
117@@ -0,0 +1,30 @@
118+#!/bin/bash
119+#--------------------------------------------
120+# This file is managed by Juju
121+#--------------------------------------------
122+#
123+# Copyright 2009,2012 Canonical Ltd.
124+# Author: Tom Haddon
125+
126+# These should be config options at some stage
127+CURRQthrsh=0
128+MAXQthrsh=100
129+
130+AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}')
131+
132+HAPROXYSTATS=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 -u '/;csv' -v)
133+
134+for BACKEND in $(echo $HAPROXYSTATS| xargs -n1 | grep BACKEND | awk -F , '{print $1}')
135+do
136+ CURRQ=$(echo "$HAPROXYSTATS" | grep $BACKEND | grep BACKEND | cut -d , -f 3)
137+ MAXQ=$(echo "$HAPROXYSTATS" | grep $BACKEND | grep BACKEND | cut -d , -f 4)
138+
139+ if [[ $CURRQ -gt $CURRQthrsh || $MAXQ -gt $MAXQthrsh ]] ; then
140+ echo "CRITICAL: queue depth for $BACKEND - CURRENT:$CURRQ MAX:$MAXQ"
141+ exit 2
142+ fi
143+done
144+
145+echo "OK: All haproxy queue depths looking good"
146+exit 0
147+

Subscribers

People subscribed via source and target branches