Merge lp:~pponnuvel/charm-haproxy/charm-haproxy into lp:charm-haproxy

Proposed by Ponnuvel Palaniyappan
Status: Merged
Approved by: Tom Haddon
Approved revision: 145
Merged at revision: 142
Proposed branch: lp:~pponnuvel/charm-haproxy/charm-haproxy
Merge into: lp:charm-haproxy
Diff against target: 99 lines (+37/-15)
3 files modified
files/nrpe/check_haproxy.sh (+1/-1)
files/nrpe/check_haproxy_queue_depth.sh (+2/-2)
hooks/hooks.py (+34/-12)
To merge this branch: bzr merge lp:~pponnuvel/charm-haproxy/charm-haproxy
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+388506@code.launchpad.net

Commit message

Don't include haproxy check scripts if monitoring is disabled.

Description of the change

Don't include haproxy check scripts if monitoring is disabled.

If monitoring isn't enabled (via 'enable_monitoring'), stats/metrics aren't
enabled. So, don't include the haproxy check scripts as these would be
useless in that case and can causes confusion.

Fixes launchpad bug 1866408.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

Some comments inline, but also see the `update_nrpe_config` function, which will likely need some updates as well.

review: Needs Fixing
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Looking at `update_nrpe_config`, I think the whole thing can be simplified with a check there..
`
def update_nrpe_config():
    config_data = config_get()
    if config_data['enable_monitoring'] is False:
        return
     ...
`
Testing this shows it works as well. Does this sound ok?

Revision history for this message
Tom Haddon (mthaddon) wrote :

> Looking at `update_nrpe_config`, I think the whole thing can be simplified
> with a check there..
> `
> def update_nrpe_config():
> config_data = config_get()
> if config_data['enable_monitoring'] is False:
> return
> ...
> `
> Testing this shows it works as well. Does this sound ok?

This won't quite deal with the case of monitoring having been enabled at one point and then disabled. I think you'd need to explicitly remove checks in that case (there's a `remove_check` method to the NRPE object as well). I'm not sure if it's safe to run those if the checks already don't exist, or you'd need to check the existence of the files on disk before running that - `hooks/charmhelpers/contrib/charmsupport/nrpe.py` should have the details.

143. By Ponnuvel Palaniyappan

Handle cases when config may be enabled and then later disabled.
When 'enable_monitoring' is set to True, the scripts are copied and
wnenever it's set to False, the scripts are removed.

Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Modified to handle cases when 'enable_monitoring' can be enabled/disabled in any order.

Although, `remove_check` didn't fail when the scripts don't exist, it did produce a couple of "INFO" complaining that the scripts don't exist. Just to not distract with that, I have added the check to call `remove_check` only they exist.

Revision history for this message
Tom Haddon (mthaddon) :
review: Needs Fixing
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Hi Tom, I don't see any review/diff comments?

Revision history for this message
Tom Haddon (mthaddon) wrote :

Hmm, sorry, not quite sure what happened there. Re-adding.

144. By Ponnuvel Palaniyappan

Tidy up code changes based on review comments.

Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Thanks, modified as suggested with one slight change because `remove_check` looks at parameter names: https://bazaar.launchpad.net/~haproxy-team/charm-haproxy/trunk/view/head:/hooks/charmhelpers/contrib/charmsupport/nrpe.py#L283

Please have another look.

145. By Ponnuvel Palaniyappan

Remove unnecessary calls use of 'head' command.

The change is functionally equivalent but uses fewer processes.

Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Commit #145 is a minor improvement (that's totally equivalent); not related to any bugs or issues.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 142

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 2019-06-06 13:01:59 +0000
+++ files/nrpe/check_haproxy.sh 2020-08-10 18:21:15 +0000
@@ -11,7 +11,7 @@
1111
12export LOGFILE=/var/log/nagios/check_haproxy.log12export LOGFILE=/var/log/nagios/check_haproxy.log
13# Exclude files starting with a dot - LP#182852913# Exclude files starting with a dot - LP#1828529
14AUTH=$(grep -r --exclude ".*" "stats auth" /etc/haproxy | head -1 | awk '{print $4}')14AUTH=$(grep -r --exclude ".*" "stats auth" /etc/haproxy | awk '{print $4; exit}')
1515
16if [ -z "$AUTH" ]; then16if [ -z "$AUTH" ]; then
17 echo "CRITICAL: unable to find credentials to query the haproxy statistics page"17 echo "CRITICAL: unable to find credentials to query the haproxy statistics page"
1818
=== modified file 'files/nrpe/check_haproxy_queue_depth.sh'
--- files/nrpe/check_haproxy_queue_depth.sh 2020-04-02 13:17:59 +0000
+++ files/nrpe/check_haproxy_queue_depth.sh 2020-08-10 18:21:15 +0000
@@ -2,7 +2,7 @@
2#--------------------------------------------2#--------------------------------------------
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 Canonical Ltd.
7# Author: Tom Haddon7# Author: Tom Haddon
88
@@ -11,7 +11,7 @@
11MAXQthrsh=10011MAXQthrsh=100
1212
13# Exclude files starting with a dot - LP#182852913# Exclude files starting with a dot - LP#1828529
14AUTH=$(grep -r --exclude ".*" "stats auth" /etc/haproxy | head -1 | awk '{print $4}')14AUTH=$(grep -r --exclude ".*" "stats auth" /etc/haproxy | awk '{print $4; exit}')
1515
16if [ -z "$AUTH" ]; then16if [ -z "$AUTH" ]; then
17 echo "CRITICAL: unable to find credentials to query the haproxy statistics page"17 echo "CRITICAL: unable to find credentials to query the haproxy statistics page"
1818
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2020-02-20 14:18:10 +0000
+++ hooks/hooks.py 2020-08-10 18:21:15 +0000
@@ -59,7 +59,7 @@
59 "deb http://archive.ubuntu.com/ubuntu %(release)s-backports "59 "deb http://archive.ubuntu.com/ubuntu %(release)s-backports "
60 "main restricted universe multiverse")60 "main restricted universe multiverse")
61haproxy_preferences_path = "/etc/apt/preferences.d/haproxy"61haproxy_preferences_path = "/etc/apt/preferences.d/haproxy"
6262nrpe_scripts_dest = "/usr/lib/nagios/plugins"
6363
64dupe_options = [64dupe_options = [
65 "mode tcp",65 "mode tcp",
@@ -1173,20 +1173,42 @@
1173def install_nrpe_scripts():1173def install_nrpe_scripts():
1174 scripts_src = os.path.join(os.environ["CHARM_DIR"], "files",1174 scripts_src = os.path.join(os.environ["CHARM_DIR"], "files",
1175 "nrpe")1175 "nrpe")
1176 scripts_dst = "/usr/lib/nagios/plugins"1176 if not os.path.exists(nrpe_scripts_dest):
1177 if not os.path.exists(scripts_dst):1177 os.makedirs(nrpe_scripts_dest)
1178 os.makedirs(scripts_dst)
1179 for fname in glob.glob(os.path.join(scripts_src, "*.sh")):1178 for fname in glob.glob(os.path.join(scripts_src, "*.sh")):
1180 shutil.copy2(fname,1179 shutil.copy2(fname,
1181 os.path.join(scripts_dst, os.path.basename(fname)))1180 os.path.join(nrpe_scripts_dest, os.path.basename(fname)))
11821181
11831182
1184def update_nrpe_config():1183def remove_nrpe_scripts():
1185 install_nrpe_scripts()1184 scripts_src = os.path.join(os.environ["CHARM_DIR"], "files",
1185 "nrpe")
1186 for fname in glob.glob(os.path.join(scripts_src, "*.sh")):
1187 try:
1188 os.remove(os.path.join(nrpe_scripts_dest,
1189 os.path.basename(fname)))
1190 except OSError:
1191 pass
1192
1193
1194def update_nrpe_config():
1195 config_data = config_get()
1186 nrpe_compat = nrpe.NRPE()1196 nrpe_compat = nrpe.NRPE()
1187 nrpe_compat.add_check('haproxy', 'Check HAProxy', 'check_haproxy.sh')1197 checks_args = [
1188 nrpe_compat.add_check('haproxy_queue', 'Check HAProxy queue depth',1198 ('haproxy', 'Check HAProxy', 'check_haproxy.sh'),
1189 'check_haproxy_queue_depth.sh')1199 ('haproxy_queue', 'Check HAProxy queue depth', 'check_haproxy_queue_depth.sh'),
1200 ]
1201 if config_data['enable_monitoring'] is True:
1202 install_nrpe_scripts()
1203 for check_args in checks_args:
1204 nrpe_compat.add_check(*check_args)
1205 else:
1206 for check_args in checks_args:
1207 if os.path.isfile(nrpe_scripts_dest + '/' + check_args[2]):
1208 nrpe_compat.remove_check(shortname=check_args[0],
1209 description=check_args[1],
1210 check_cmd=check_args[2])
1211 remove_nrpe_scripts()
1190 nrpe_compat.write()1212 nrpe_compat.write()
11911213
11921214

Subscribers

People subscribed via source and target branches