Merge lp:~pedronis/charms/trusty/apache2/nagios_extra_check_https into lp:~tanuki/charms/trusty/apache2/trunk

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 69
Merged at revision: 68
Proposed branch: lp:~pedronis/charms/trusty/apache2/nagios_extra_check_https
Merge into: lp:~tanuki/charms/trusty/apache2/trunk
Diff against target: 85 lines (+50/-1)
3 files modified
config.yaml (+13/-0)
hooks/hooks.py (+9/-0)
hooks/tests/test_nrpe_hooks.py (+28/-1)
To merge this branch: bzr merge lp:~pedronis/charms/trusty/apache2/nagios_extra_check_https
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+269489@code.launchpad.net

Commit message

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

Description of the change

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

at least here not all the preexisting tests pass :/

To post a comment you must log in.
69. By Samuele Pedroni

the spelling was confusing, rename

Revision history for this message
Celso Providelo (cprov) wrote :

Samuele,

Thanks for the changes, as discussed on IRC, test failure were there pre-fork (FAILED (errors=4, failures=2)), so don't worry (much).

I think we will probably need to pass a proper "description" for each extra check (as part of our guided-alerts story), but let's do it when we need.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-08-11 19:06:25 +0000
+++ config.yaml 2015-08-28 12:49:12 +0000
@@ -118,6 +118,19 @@
118 default: ""118 default: ""
119 type: string119 type: string
120 description: The parameters to pass to the nrpe plugin check_http.120 description: The parameters to pass to the nrpe plugin check_http.
121 nagios_extra_http_checks:
122 default: ""
123 type: string
124 description: |
125 Extra nrpe plugin check_http checks. Useful when fronting more than
126 one backend. A string with a YAML sequence of mappings with keys
127 name, params (like nagios_check_http_params) and optionally
128 description:
129 - name: backend1
130 params: -H ...
131 - name: backend2
132 description: Check backend2 endpoint
133 params: -H ...
121 logrotate_rotate:134 logrotate_rotate:
122 type: string135 type: string
123 description: daily, weekly, monthly, or yearly?136 description: daily, weekly, monthly, or yearly?
124137
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-04-15 20:23:01 +0000
+++ hooks/hooks.py 2015-08-28 12:49:12 +0000
@@ -437,6 +437,15 @@
437 description='Check Virtual Host',437 description='Check Virtual Host',
438 check_cmd='check_http %s' % check_http_params438 check_cmd='check_http %s' % check_http_params
439 )439 )
440 extra_http_checks = conf.get('nagios_extra_http_checks')
441 if extra_http_checks:
442 for check_http in yaml.safe_load(extra_http_checks):
443 name = check_http['name']
444 nrpe_compat.add_check(
445 shortname=name,
446 description=check_http.get('description', 'Check %s' % name),
447 check_cmd='check_http %s' % check_http['params']
448 )
440 nrpe_compat.write()449 nrpe_compat.write()
441450
442451
443452
=== modified file 'hooks/tests/test_nrpe_hooks.py'
--- hooks/tests/test_nrpe_hooks.py 2015-03-09 16:32:43 +0000
+++ hooks/tests/test_nrpe_hooks.py 2015-08-28 12:49:12 +0000
@@ -1,5 +1,5 @@
1from testtools import TestCase1from testtools import TestCase
2from mock import patch2from mock import call, patch
33
4import hooks4import hooks
55
@@ -28,3 +28,30 @@
28 hooks.update_nrpe_checks()28 hooks.update_nrpe_checks()
29 self.assertFalse(nrpe.add_check.called)29 self.assertFalse(nrpe.add_check.called)
30 nrpe.write.assert_called_once_with()30 nrpe.write.assert_called_once_with()
31
32 @patch('hooks.nrpe.NRPE')
33 def test_update_nrpe_with_extra_http_checks(self, mock_nrpe):
34 nrpe = mock_nrpe.return_value
35 nrpe.config = {
36 'nagios_extra_http_checks': """
37- name: backend1
38 params: -H bar1
39- name: backend2
40 description: Check backend2 endpoint
41 params: -H bar2
42""",
43 }
44 hooks.update_nrpe_checks()
45 add_check_calls = nrpe.add_check.mock_calls
46 self.assertEqual(len(add_check_calls), 2)
47 self.assertEqual(add_check_calls[0], call(
48 shortname='backend1',
49 description='Check backend1',
50 check_cmd='check_http -H bar1'
51 ))
52 self.assertEqual(add_check_calls[1], call(
53 shortname='backend2',
54 description='Check backend2 endpoint',
55 check_cmd='check_http -H bar2'
56 ))
57 nrpe.write.assert_called_once_with()

Subscribers

People subscribed via source and target branches

to all changes: