Merge lp:~mbruzek/charms/trusty/apache2/nagios_extra_check_https into lp:charms/trusty/apache2

Proposed by Matt Bruzek
Status: Work in progress
Proposed branch: lp:~mbruzek/charms/trusty/apache2/nagios_extra_check_https
Merge into: lp:charms/trusty/apache2
Diff against target: 169 lines (+89/-6)
6 files modified
README.md (+34/-3)
config.yaml (+13/-0)
hooks/hooks.py (+9/-0)
hooks/tests/test_nrpe_hooks.py (+28/-1)
tests/00-setup (+4/-1)
tests/20-mpm-test.py (+1/-1)
To merge this branch: bzr merge lp:~mbruzek/charms/trusty/apache2/nagios_extra_check_https
Reviewer Review Type Date Requested Status
Samuele Pedroni (community) Approve
Review via email: mp+275095@code.launchpad.net

Description of the change

@pedronis

I took the time to make some of the changes I suggested to your branch.
lp:~pedronis/charms/trusty/apache2/nagios_extra_check_https

Added a section to the readme. This could use some more specific examples and perhaps more description on how to use the nagios configuration options (I am not an expert). Any more information that you could give the users would be great here.

I also fixed up the amulet tests, they needed more time to deploy and install the prerequisites.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

thanks for improving on my branch, I was a bit clueless about the amulet tests, they were failing already

a typical params is something like this:

-S -H svc.example.com -I 127.0.0.1 -e '"200 OK"' --url=/

or so

if we want to give an example

review: Approve
Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hey @mbruzek and @pedronis,

The new monitoring section of the README is fantastic. Excellent job!

However, I'm curious if we could implement this extra_http_checks differently. Rather than create a new config opt that takes yaml (which is difficult to type into the cli and juju-gui), could we make the existing nagios_check_http_params take multiple args? If so, it seems like the functionality from this MP could be achieved with:

juju set apache2 nagios_check_http_params="-H hostA -e '200 OK'; -H hostB -e '200 OK'"

The update_nrpe_checks() in hooks.py would then split nagios_check_http_params on a semicolon (or whatever delimiter makes sense) and call check_http on each of the splits. The README would also need to be updated to let users know that nagios_check_http_params could take multiple check params.

To me this is less confusing than having 2 config opts that are both passed on to check_http. Thoughts?

As an aside, when working through this review, I noticed 'make test' failed. I know you didn't introduce this failure, but I opened a bug in case you're interested in fixing :)

https://bugs.launchpad.net/charms/+source/apache2/+bug/1511474

Revision history for this message
Samuele Pedroni (pedronis) wrote :

we went with a full new config because when you have many checks you really
care about being able to set sane descriptions for them, and finding a
format for that in one string I think would get unwieldy. Honestly we need
keep the original one for backward compatible/the simple case

On Thu, Oct 29, 2015 at 6:30 PM, Kevin W Monroe <email address hidden>
wrote:

> Hey @mbruzek and @pedronis,
>
> The new monitoring section of the README is fantastic. Excellent job!
>
> However, I'm curious if we could implement this extra_http_checks
> differently. Rather than create a new config opt that takes yaml (which is
> difficult to type into the cli and juju-gui), could we make the existing
> nagios_check_http_params take multiple args? If so, it seems like the
> functionality from this MP could be achieved with:
>
> juju set apache2 nagios_check_http_params="-H hostA -e '200 OK'; -H hostB
> -e '200 OK'"
>
> The update_nrpe_checks() in hooks.py would then split
> nagios_check_http_params on a semicolon (or whatever delimiter makes sense)
> and call check_http on each of the splits. The README would also need to be
> updated to let users know that nagios_check_http_params could take multiple
> check params.
>
> To me this is less confusing than having 2 config opts that are both
> passed on to check_http. Thoughts?
>
> As an aside, when working through this review, I noticed 'make test'
> failed. I know you didn't introduce this failure, but I opened a bug in
> case you're interested in fixing :)
>
> https://bugs.launchpad.net/charms/+source/apache2/+bug/1511474
> --
>
> https://code.launchpad.net/~mbruzek/charms/trusty/apache2/nagios_extra_check_https/+merge/275095
> You are reviewing the proposed merge of
> lp:~mbruzek/charms/trusty/apache2/nagios_extra_check_https into
> lp:charms/trusty/apache2.
>

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hey Samuele, I get your point about multiple host checks becoming unwieldy in 1 string, but I'm still off-put by having 2 config opts for this. How do you feel about testing nagios_check_http_params for "yamlness", and looping over the yaml if true, or treating it as a string if false? Something like:

--- hooks/hooks.py 2015-04-15 20:23:01 +0000
+++ hooks/hooks.py 2015-10-29 18:27:20 +0000
@@ -432,11 +432,21 @@
     conf = nrpe_compat.config
     check_http_params = conf.get('nagios_check_http_params')
     if check_http_params:
- nrpe_compat.add_check(
- shortname='vhost',
- description='Check Virtual Host',
- check_cmd='check_http %s' % check_http_params
- )
+ for check_http in yaml.safe_load(check_http_params):
+ try:
+ name = check_http['name']
+ nrpe_compat.add_check(
+ shortname=name,
+ description=check_http.get('description', name),
+ check_cmd='check_http %s' % check_http['params']
+ )
+ except TypeError:
+ nrpe_compat.add_check(
+ shortname='vhost',
+ description='Check Virtual Host',
+ check_cmd='check_http %s' % check_http_params
+ )
+ break
     nrpe_compat.write()

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Ouch on that formatting.. how about this: http://paste.ubuntu.com/13001287/

Revision history for this message
Samuele Pedroni (pedronis) wrote :

> Ouch on that formatting.. how about this: http://paste.ubuntu.com/13001287/

sorry been busy with other things, I'm not against if the ecosys team thinks is not too strange,

about that code, in the case of a simple string this works because the for check_http will be one char strings and so we get the TypeError, defensively I would put the try except just around

name = check_http['name']

or even be more explicit separating cases

Unmerged revisions

70. By Matt Bruzek

Updating readme with monitoring section and updating amulet tests.

69. By Samuele Pedroni

the spelling was confusing, rename

68. By Samuele Pedroni

support new config nagios_extra_check_https to specify extra nrpe check_http checks, useful when fronting more than one backend

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2015-04-15 22:59:59 +0000
3+++ README.md 2015-10-20 20:08:17 +0000
4@@ -296,13 +296,44 @@
5 Space separated list of modules to be enabled or disabled. If a module to
6 be enabled cannot be found then the charm will attempt to install it.
7
8-## OpenId
9+## OpenId
10
11-The openid_provider option takes a comma seperated list of OpenID
12+The openid_provider option takes a comma separated list of OpenID
13 providers and places them in /etc/apache2/security/allowed-ops.txt. That
14-file can then be refernced by the allowed-op-list-url option when using
15+file can then be referenced by the allowed-op-list-url option when using
16 apache_openid
17
18+## Monitoring
19+
20+This charm can be configured for monitoring with Nagios. This charm can be
21+related to the `nrpe` subordinate and then nrpe can relate to a nagios charm.
22+This charm can also use the `nrpe-external-master` charm for Nagios systems
23+outside of Juju.
24+
25+The following is a description of the nagios configuration options:
26+
27+`nagios_context` Used by the nrpe-external-master subordinate charm.
28+ A string that will be prepended to instance name to set the host name
29+ in nagios. So for instance the hostname would be something like:
30+ juju-postgresql-0
31+ If you're running multiple environments with the same services in them
32+ this allows you to differentiate between them.
33+
34+`nagios_servicegroups` A comma-separated list of nagios servicegroups.
35+ If left empty, the nagios_context will be used as the servicegroup
36+
37+`nagios_check_http_params` The parameters to pass to the nrpe plugin check_http.
38+
39+`nagios_extra_http_checks` Extra nrpe plugin check_http checks. Useful when
40+fronting more than one backend. A string with a YAML sequence of mappings with
41+keys name, params (like nagios_check_http_params) and optionally a description:
42+
43+ - name: backend1
44+ params: -H ...
45+ - name: backend2
46+ description: Check backend2 endpoint
47+ params: -H ...
48+
49 ## TODO:
50
51 * Document the use of balancer, nrpe, logging and website-cache
52
53=== modified file 'config.yaml'
54--- config.yaml 2015-08-11 19:06:25 +0000
55+++ config.yaml 2015-10-20 20:08:17 +0000
56@@ -118,6 +118,19 @@
57 default: ""
58 type: string
59 description: The parameters to pass to the nrpe plugin check_http.
60+ nagios_extra_http_checks:
61+ default: ""
62+ type: string
63+ description: |
64+ Extra nrpe plugin check_http checks. Useful when fronting more than
65+ one backend. A string with a YAML sequence of mappings with keys
66+ name, params (like nagios_check_http_params) and optionally
67+ description:
68+ - name: backend1
69+ params: -H ...
70+ - name: backend2
71+ description: Check backend2 endpoint
72+ params: -H ...
73 logrotate_rotate:
74 type: string
75 description: daily, weekly, monthly, or yearly?
76
77=== modified file 'hooks/hooks.py'
78--- hooks/hooks.py 2015-04-15 20:23:01 +0000
79+++ hooks/hooks.py 2015-10-20 20:08:17 +0000
80@@ -437,6 +437,15 @@
81 description='Check Virtual Host',
82 check_cmd='check_http %s' % check_http_params
83 )
84+ extra_http_checks = conf.get('nagios_extra_http_checks')
85+ if extra_http_checks:
86+ for check_http in yaml.safe_load(extra_http_checks):
87+ name = check_http['name']
88+ nrpe_compat.add_check(
89+ shortname=name,
90+ description=check_http.get('description', 'Check %s' % name),
91+ check_cmd='check_http %s' % check_http['params']
92+ )
93 nrpe_compat.write()
94
95
96
97=== modified file 'hooks/tests/test_nrpe_hooks.py'
98--- hooks/tests/test_nrpe_hooks.py 2015-03-09 16:32:43 +0000
99+++ hooks/tests/test_nrpe_hooks.py 2015-10-20 20:08:17 +0000
100@@ -1,5 +1,5 @@
101 from testtools import TestCase
102-from mock import patch
103+from mock import call, patch
104
105 import hooks
106
107@@ -28,3 +28,30 @@
108 hooks.update_nrpe_checks()
109 self.assertFalse(nrpe.add_check.called)
110 nrpe.write.assert_called_once_with()
111+
112+ @patch('hooks.nrpe.NRPE')
113+ def test_update_nrpe_with_extra_http_checks(self, mock_nrpe):
114+ nrpe = mock_nrpe.return_value
115+ nrpe.config = {
116+ 'nagios_extra_http_checks': """
117+- name: backend1
118+ params: -H bar1
119+- name: backend2
120+ description: Check backend2 endpoint
121+ params: -H bar2
122+""",
123+ }
124+ hooks.update_nrpe_checks()
125+ add_check_calls = nrpe.add_check.mock_calls
126+ self.assertEqual(len(add_check_calls), 2)
127+ self.assertEqual(add_check_calls[0], call(
128+ shortname='backend1',
129+ description='Check backend1',
130+ check_cmd='check_http -H bar1'
131+ ))
132+ self.assertEqual(add_check_calls[1], call(
133+ shortname='backend2',
134+ description='Check backend2 endpoint',
135+ check_cmd='check_http -H bar2'
136+ ))
137+ nrpe.write.assert_called_once_with()
138
139=== modified file 'tests/00-setup'
140--- tests/00-setup 2014-10-29 00:10:14 +0000
141+++ tests/00-setup 2015-10-20 20:08:17 +0000
142@@ -1,6 +1,6 @@
143 #!/bin/bash
144
145-set -x
146+set -x
147
148 # Check if amulet is installed before adding repository and updating apt-get.
149 dpkg -s amulet
150@@ -11,3 +11,6 @@
151 fi
152
153 # Install any additional python packages or software here.
154+sudo apt-get install -y python-software-properties python-flake8 python-nose \
155+python-coverage python-testtools python-pyasn1 python-pyasn1-modules \
156+python-openssl python-apt python-virtualenv python-jinja2
157
158=== modified file 'tests/20-mpm-test.py'
159--- tests/20-mpm-test.py 2015-03-10 10:56:19 +0000
160+++ tests/20-mpm-test.py 2015-10-20 20:08:17 +0000
161@@ -12,7 +12,7 @@
162 """ Set up an amulet deployment using the bundle. """
163 d = amulet.Deployment(series='trusty')
164 d.add('apache2', os.path.join(os.path.dirname(__file__), os.pardir))
165- d.setup(180)
166+ d.setup(600)
167 cls.d = d
168 cls.unit = d.sentry.unit['apache2/0']
169 output, code = cls.unit.run('curl localhost')

Subscribers

People subscribed via source and target branches

to all changes: