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
1=== modified file 'config.yaml'
2--- config.yaml 2015-08-11 19:06:25 +0000
3+++ config.yaml 2015-08-28 12:49:12 +0000
4@@ -118,6 +118,19 @@
5 default: ""
6 type: string
7 description: The parameters to pass to the nrpe plugin check_http.
8+ nagios_extra_http_checks:
9+ default: ""
10+ type: string
11+ description: |
12+ Extra nrpe plugin check_http checks. Useful when fronting more than
13+ one backend. A string with a YAML sequence of mappings with keys
14+ name, params (like nagios_check_http_params) and optionally
15+ description:
16+ - name: backend1
17+ params: -H ...
18+ - name: backend2
19+ description: Check backend2 endpoint
20+ params: -H ...
21 logrotate_rotate:
22 type: string
23 description: daily, weekly, monthly, or yearly?
24
25=== modified file 'hooks/hooks.py'
26--- hooks/hooks.py 2015-04-15 20:23:01 +0000
27+++ hooks/hooks.py 2015-08-28 12:49:12 +0000
28@@ -437,6 +437,15 @@
29 description='Check Virtual Host',
30 check_cmd='check_http %s' % check_http_params
31 )
32+ extra_http_checks = conf.get('nagios_extra_http_checks')
33+ if extra_http_checks:
34+ for check_http in yaml.safe_load(extra_http_checks):
35+ name = check_http['name']
36+ nrpe_compat.add_check(
37+ shortname=name,
38+ description=check_http.get('description', 'Check %s' % name),
39+ check_cmd='check_http %s' % check_http['params']
40+ )
41 nrpe_compat.write()
42
43
44
45=== modified file 'hooks/tests/test_nrpe_hooks.py'
46--- hooks/tests/test_nrpe_hooks.py 2015-03-09 16:32:43 +0000
47+++ hooks/tests/test_nrpe_hooks.py 2015-08-28 12:49:12 +0000
48@@ -1,5 +1,5 @@
49 from testtools import TestCase
50-from mock import patch
51+from mock import call, patch
52
53 import hooks
54
55@@ -28,3 +28,30 @@
56 hooks.update_nrpe_checks()
57 self.assertFalse(nrpe.add_check.called)
58 nrpe.write.assert_called_once_with()
59+
60+ @patch('hooks.nrpe.NRPE')
61+ def test_update_nrpe_with_extra_http_checks(self, mock_nrpe):
62+ nrpe = mock_nrpe.return_value
63+ nrpe.config = {
64+ 'nagios_extra_http_checks': """
65+- name: backend1
66+ params: -H bar1
67+- name: backend2
68+ description: Check backend2 endpoint
69+ params: -H bar2
70+""",
71+ }
72+ hooks.update_nrpe_checks()
73+ add_check_calls = nrpe.add_check.mock_calls
74+ self.assertEqual(len(add_check_calls), 2)
75+ self.assertEqual(add_check_calls[0], call(
76+ shortname='backend1',
77+ description='Check backend1',
78+ check_cmd='check_http -H bar1'
79+ ))
80+ self.assertEqual(add_check_calls[1], call(
81+ shortname='backend2',
82+ description='Check backend2 endpoint',
83+ check_cmd='check_http -H bar2'
84+ ))
85+ nrpe.write.assert_called_once_with()

Subscribers

People subscribed via source and target branches

to all changes: