Merge lp:~brad-marshall/charms/trusty/nagios/add-livestatus-support into lp:charms/trusty/nagios

Proposed by Brad Marshall
Status: Merged
Merged at revision: 31
Proposed branch: lp:~brad-marshall/charms/trusty/nagios/add-livestatus-support
Merge into: lp:charms/trusty/nagios
Diff against target: 227 lines (+147/-2)
5 files modified
README.md (+4/-0)
config.yaml (+10/-0)
hooks/install (+18/-0)
hooks/upgrade-charm (+72/-2)
tests/23-livestatus-test (+43/-0)
To merge this branch: bzr merge lp:~brad-marshall/charms/trusty/nagios/add-livestatus-support
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review via email: mp+257992@code.launchpad.net

Description of the change

Add livestatus support, which can't be done via the extraconfig since the broker_module needs to be in the main nagios.cfg file.

To post a comment you must log in.
21. By Brad Marshall

[bradm] Merge from upstream, had started with lp:charms/nagios instead of lp:charms/trusty/nagios

22. By Brad Marshall

[bradm] Add test for livestatus config variable

Revision history for this message
Brad Marshall (brad-marshall) wrote :

Added tests for the livestatus path existing, although I'm not sure I did the config-get correctly - it feels like there should be a better way in amulet than a unit.run('config-get <var>') - please let me know if there is.

Revision history for this message
Adam Israel (aisrael) wrote :

Hi!

I'm doing a triage of reviews in the queue, in the spirit of fail-fast. This is a cursory check of the proposed merge to see if there are any "obvious" things that may prevent the review from being accepted.

The goal is to get you feedback sooner, before an in-depth review has been done. I'm happy to see the addition of a unit test for the new functionality. Could you also add something to the README to explains the usage of this new feature?

Thanks!

23. By Brad Marshall

[bradm] Add documentation about livestatus config options, tidy up comments

Revision history for this message
Brad Marshall (brad-marshall) wrote :

I've added some basic documentation about the config variables.

Revision history for this message
Charles Butler (lazypower) wrote :

Greetings Brad,

I took some time to review this and would like to thank you for the contribution. The test coverage + documentation updates.

In response to your earlier question about running config-get, that is one way of doing it or you can read directly from the config dictionary you supply to the charm in the test. However if you did not supply one - your method was correct. To obtain the data from juju-run.

I found some test failures that seem unrelated to your merge. I filed them under this existing bug about tests failing in CI here: https://bugs.launchpad.net/charms/+source/nagios/+bug/1403574

+1 LGTM. Thank you for taking the time to submit this feature for the nagios charm. We appreciate your work. I've merged this branch and it should be available in the charm store after the next ingestion.

If you have any questions/comments/concerns about the review contact us in #juju on irc.freenode.net or email the mailing list <email address hidden>, or ask a question tagged with "juju" on http://askubuntu.com.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.md'
--- README.md 2014-04-11 14:06:48 +0000
+++ README.md 2015-05-07 07:07:58 +0000
@@ -28,6 +28,10 @@
2828
29# Configuration29# Configuration
3030
31- `enable_livestatus` - Setting to enable the [livestatus module](https://mathias-kettner.de/checkmk_livestatus.html). This is an easy interface to get data out of Nagios.
32
33- `livestatus_path` - Configuration of where the livestatus module is stored - defaults to /var/lib/nagios3/livestatus/socket.
34
31### SSL Configuration35### SSL Configuration
3236
33- `ssl` - Determinant configuration for enabling SSL. Valid options are "on", "off", "only". The "only" option disables HTTP traffic on Apache in favor of HTTPS. This setting may cause unexpected behavior with existing nagios charm deployments. 37- `ssl` - Determinant configuration for enabling SSL. Valid options are "on", "off", "only". The "only" option disables HTTP traffic on Apache in favor of HTTPS. This setting may cause unexpected behavior with existing nagios charm deployments.
3438
=== modified file 'config.yaml'
--- config.yaml 2014-03-04 21:33:40 +0000
+++ config.yaml 2015-05-07 07:07:58 +0000
@@ -34,3 +34,13 @@
34 description: |34 description: |
35 base64 encoded chain certificates file. If ssl_cert is35 base64 encoded chain certificates file. If ssl_cert is
36 blank, this will be ignored.36 blank, this will be ignored.
37 enable_livestatus:
38 type: boolean
39 default: false
40 description: |
41 Config variable to enable livestatus module or not.
42 livestatus_path:
43 type: string
44 default: "/var/lib/nagios3/livestatus/socket"
45 description: |
46 Default path to livestatus socket, if enabled via enable_livestatus
3747
=== modified file 'hooks/install'
--- hooks/install 2014-10-13 23:19:09 +0000
+++ hooks/install 2015-05-07 07:07:58 +0000
@@ -37,6 +37,24 @@
37 rm -v /etc/nagios3/conf.d/extinfo_nagios2.cfg37 rm -v /etc/nagios3/conf.d/extinfo_nagios2.cfg
38fi38fi
3939
40enable_livestatus=$(config-get enable_livestatus)
41livestatus_path=$(config-get livestatus_path)
42livestatus_dir=$(dirname $livestatus_path)
43
44if [ "$enable_livestatus" ]; then
45 # install check-mk-livestatus
46 DEBIAN_FRONTEND=noninteractive apt-get -qy install check-mk-livestatus
47 # enable livestatus broker
48 if ! grep '^broker_module=' /etc/nagios3/nagios.cfg ; then
49 echo "broker_module=/usr/lib/check_mk/livestatus.o $livestatus_path" >> /etc/nagios3/nagios.cfg
50 fi
51 # fix permissions on the livestatus directory
52 mkdir -p $livestatus_dir
53 chown nagios:www-data $livestatus_dir
54 chmod g+w $livestatus_dir
55 chmod g+s $livestatus_dir
56fi
57
40if [ -f $CHARM_DIR/files/index.html ]; then58if [ -f $CHARM_DIR/files/index.html ]; then
41 # Replace the default index.html file to redirect to nagios3/59 # Replace the default index.html file to redirect to nagios3/
42 cp -v $CHARM_DIR/files/index.html /var/www/html/index.html60 cp -v $CHARM_DIR/files/index.html /var/www/html/index.html
4361
=== modified file 'hooks/upgrade-charm'
--- hooks/upgrade-charm 2014-10-14 17:18:28 +0000
+++ hooks/upgrade-charm 2015-05-07 07:07:58 +0000
@@ -5,19 +5,28 @@
5import base645import base64
6from jinja2 import Template6from jinja2 import Template
7import os7import os
8import shutil8import re
9import pwd
10import grp
11import stat
12import errno
13# import shutil
9import subprocess14import subprocess
10from charmhelpers.contrib import ssl15from charmhelpers.contrib import ssl
11from charmhelpers.core import hookenv, host16from charmhelpers.core import hookenv, host
17from charmhelpers import fetch
1218
13from common import update_localhost19from common import update_localhost
1420
15# Gather facts21# Gather facts
16legacy_relations = hookenv.config('legacy')22legacy_relations = hookenv.config('legacy')
17extra_config = hookenv.config('extraconfig')23extra_config = hookenv.config('extraconfig')
24enable_livestatus = hookenv.config('enable_livestatus')
25livestatus_path = hookenv.config('livestatus_path')
18ssl_config = hookenv.config('ssl')26ssl_config = hookenv.config('ssl')
19charm_dir = os.environ['CHARM_DIR']27charm_dir = os.environ['CHARM_DIR']
20cert_domain = hookenv.unit_get('public-address')28cert_domain = hookenv.unit_get('public-address')
29nagios_cfg = "/etc/nagios3/nagios.cfg"
2130
2231
23# Checks the charm relations for legacy relations32# Checks the charm relations for legacy relations
@@ -44,6 +53,66 @@
44 host.write_file('/etc/nagios3/conf.d/extra.cfg', extra_config)53 host.write_file('/etc/nagios3/conf.d/extra.cfg', extra_config)
4554
4655
56# Equivalent of mkdir -p, since we can't rely on
57# python 3.2 os.makedirs exist_ok argument
58def mkdir_p(path):
59 try:
60 os.makedirs(path)
61 except OSError as exc: # Python >2.5
62 if exc.errno == errno.EEXIST and os.path.isdir(path):
63 pass
64 else:
65 raise
66
67
68# Fix the path to be world executable
69def fixpath(path):
70 if os.path.isdir(path):
71 st = os.stat(path)
72 os.chmod(path, st.st_mode | stat.S_IXOTH)
73 if path != "/":
74 fixpath(os.path.split(path)[0])
75
76
77def enable_livestatus_config():
78 if enable_livestatus:
79 hookenv.log("Livestatus is enabled")
80 fetch.apt_update()
81 fetch.apt_install('check-mk-livestatus')
82 broker = re.compile("^broker_module=")
83 broker_found = False
84 for line in open(nagios_cfg):
85 if broker.match(line):
86 broker_found = True
87 hookenv.log("broker_module line exists, not adding..")
88 break
89
90 if not broker_found:
91 with open(nagios_cfg, "a") as nagiosfile:
92 broker_str = "broker_module=/usr/lib/check_mk/livestatus.o " . livestatus_path
93 nagiosfile.write(broker_str)
94 nagiosfile.close()
95
96 # Make the directory and fix perms on it
97 hookenv.log("Fixing perms on livestatus_path")
98 livestatus_path = hookenv.config('livestatus_path')
99 livestatus_dir = os.path.dirname(livestatus_path)
100 if not os.path.isdir(livestatus_dir):
101 hookenv.log("Making path for livestatus_dir")
102 mkdir_p(livestatus_dir)
103 fixpath(livestatus_dir)
104
105 # Fix the perms on the socket
106 hookenv.log("Fixing perms on the socket")
107 uid = pwd.getpwnam("nagios").pw_uid
108 gid = grp.getgrnam("www-data").gr_gid
109 os.chown(livestatus_path, uid, gid)
110 os.chown(livestatus_dir, uid, gid)
111 st = os.stat(livestatus_path)
112 os.chmod(livestatus_path, st.st_mode | stat.S_IRGRP)
113 os.chmod(livestatus_dir, st.st_mode | stat.S_IRGRP | stat.S_ISGID)
114
115
47def ssl_configured():116def ssl_configured():
48 allowed_options = ["on", "only"]117 allowed_options = ["on", "only"]
49 if str(ssl_config).lower() in allowed_options:118 if str(ssl_config).lower() in allowed_options:
@@ -89,7 +158,7 @@
89def enable_ssl():158def enable_ssl():
90 # Set the basename of all ssl files159 # Set the basename of all ssl files
91160
92 #Validate that we have configs, and generate a self signed certificate.161 # Validate that we have configs, and generate a self signed certificate.
93 if not hookenv.config('ssl_cert'):162 if not hookenv.config('ssl_cert'):
94 # bail if keys already exist163 # bail if keys already exist
95 if os.path.exists(cert_file):164 if os.path.exists(cert_file):
@@ -143,6 +212,7 @@
143212
144warn_legacy_relations()213warn_legacy_relations()
145write_extra_config()214write_extra_config()
215enable_livestatus_config()
146if ssl_configured():216if ssl_configured():
147 enable_ssl()217 enable_ssl()
148update_apache()218update_apache()
149219
=== added file 'tests/23-livestatus-test'
--- tests/23-livestatus-test 1970-01-01 00:00:00 +0000
+++ tests/23-livestatus-test 2015-05-07 07:07:58 +0000
@@ -0,0 +1,43 @@
1#!/usr/bin/python3
2
3import amulet
4# import requests
5
6seconds = 20000
7
8d = amulet.Deployment(series='trusty')
9
10d.add('nagios')
11
12d.expose('nagios')
13
14try:
15 d.setup(timeout=seconds)
16 d.sentry.wait()
17except amulet.helpers.TimeoutError:
18 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
19except:
20 raise
21
22
23##
24# Set relationship aliases
25##
26nagios_unit = d.sentry.unit['nagios/0']
27
28d.configure('nagios', {
29 'enable_livestatus': True
30})
31
32d.sentry.wait()
33
34
35def test_livestatus_file_exists():
36 livestatus_path = nagios_unit.run('config-get livestatus_path')
37 try:
38 livestatus_file = nagios_unit.file(livestatus_path[0])
39 except OSError:
40 message = "Can't find livestatus file"
41 amulet.raise_status(amulet.FAIL, msg=message)
42
43test_livestatus_file_exists()

Subscribers

People subscribed via source and target branches

to all changes: