Merge lp:~gnuoy/charm-helpers/add-nrpe-gethostname into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 282
Proposed branch: lp:~gnuoy/charm-helpers/add-nrpe-gethostname
Merge into: lp:charm-helpers
Diff against target: 43 lines (+22/-0)
2 files modified
charmhelpers/contrib/charmsupport/nrpe.py (+11/-0)
tests/contrib/charmsupport/test_nrpe.py (+11/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/add-nrpe-gethostname
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+246110@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/charmsupport/nrpe.py'
2--- charmhelpers/contrib/charmsupport/nrpe.py 2015-01-12 10:11:00 +0000
3+++ charmhelpers/contrib/charmsupport/nrpe.py 2015-01-12 11:19:22 +0000
4@@ -247,6 +247,17 @@
5 return rel['nagios_host_context']
6
7
8+def get_nagios_hostname(relation_name='nrpe-external-master'):
9+ """
10+ Query relation with nrpe subordinate, return the nagios_hostname
11+
12+ :param str relation_name: Name of relation nrpe sub joined to
13+ """
14+ for rel in relations_of_type(relation_name):
15+ if 'nagios_hostname' in rel:
16+ return rel['nagios_hostname']
17+
18+
19 def get_nagios_unit_name(relation_name='nrpe-external-master'):
20 """
21 Return the nagios unit name prepended with host_context if needed
22
23=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
24--- tests/contrib/charmsupport/test_nrpe.py 2015-01-12 09:58:18 +0000
25+++ tests/contrib/charmsupport/test_nrpe.py 2015-01-12 11:19:22 +0000
26@@ -256,6 +256,17 @@
27 self.patched['relations_of_type'].return_value = [rel_info]
28 self.assertEqual(nrpe.get_nagios_hostcontext(), 'bob')
29
30+ def test_get_nagios_hostname(self):
31+ rel_info = {
32+ 'nagios_hostname': 'bob-openstack-dashboard-0',
33+ 'private-address': '10.5.3.103',
34+ '__unit__': u'dashboard-nrpe/1',
35+ '__relid__': u'nrpe-external-master:2',
36+ 'nagios_host_context': u'bob',
37+ }
38+ self.patched['relations_of_type'].return_value = [rel_info]
39+ self.assertEqual(nrpe.get_nagios_hostname(), 'bob-openstack-dashboard-0')
40+
41 def test_get_nagios_unit_name(self):
42 rel_info = {
43 'nagios_hostname': 'bob-openstack-dashboard-0',

Subscribers

People subscribed via source and target branches