Merge lp:~verterok/charms/trusty/logstash-forwarder/fix-nrpe-check into lp:~tanuki/charms/trusty/logstash-forwarder/trunk

Proposed by Guillermo Gonzalez on 2015-09-25
Status: Merged
Merged at revision: 17
Proposed branch: lp:~verterok/charms/trusty/logstash-forwarder/fix-nrpe-check
Merge into: lp:~tanuki/charms/trusty/logstash-forwarder/trunk
Diff against target: 57 lines (+10/-5)
1 file modified
hooks/hooks.py (+10/-5)
To merge this branch: bzr merge lp:~verterok/charms/trusty/logstash-forwarder/fix-nrpe-check
Reviewer Review Type Date Requested Status
Celso Providelo (community) 2015-09-25 Approve on 2015-09-25
Review via email: mp+272479@code.launchpad.net

Commit message

set hostname from nrpe-external-master relation data in nrpe checks

Description of the change

set hostname from nrpe-external-master relation data in nrpe checks

To post a comment you must log in.
Celso Providelo (cprov) wrote :

Thanks, Guillermo.

Don't forget to propose a MP for logstash-forward upstream, specially because I think IS is actively working on it (ELK devops)

review: Approve
Guillermo Gonzalez (verterok) wrote :

> Thanks, Guillermo.
>
> Don't forget to propose a MP for logstash-forward upstream, specially because
> I think IS is actively working on it (ELK devops)
Done: https://code.launchpad.net/~verterok/charms/trusty/logstash-forwarder/set-nrpe-hostname-from-relation/+merge/272614

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2015-08-31 16:22:46 +0000
3+++ hooks/hooks.py 2015-09-25 20:25:34 +0000
4@@ -11,7 +11,7 @@
5 import base64
6 import shutil
7 sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
8-from charmhelpers.core.hookenv import Hooks, log, charm_dir
9+from charmhelpers.core.hookenv import Hooks, log, charm_dir, relations_of_type
10 from charmhelpers.core.host import mkdir, service_start, service_stop, service_restart
11 from charmhelpers.fetch import apt_install, apt_update, add_source
12 from Cheetah.Template import Template
13@@ -139,10 +139,14 @@
14 os.rename('/tmp/new_hosts', '/etc/hosts')
15
16
17-
18 @hooks.hook('nrpe-external-master-relation-changed')
19 def update_nrpe_checks():
20- nrpe_compat = nrpe.NRPE()
21+ rels = relations_of_type('nrpe-external-master')
22+ if not rels:
23+ log("No nrpe-external-master relations found, skipping update_nrpe_checks")
24+ return
25+ # only use the first relation in the list...we should have a single nrpe
26+ nrpe_compat = nrpe.NRPE(hostname=rels[0]['nagios_hostname'])
27 conf = nrpe_compat.config
28 check_procs_params = conf.get('nagios_check_procs_params')
29 if check_procs_params:
30@@ -154,14 +158,14 @@
31 nrpe_compat.add_check(
32 shortname='logstashforwarder_sending',
33 description='Check logstash-forwarder is sending by tailing logfile',
34- check_cmd = "/usr/local/lib/nagios/plugins/check-logstashforwarder-sending.sh"
35+ check_cmd="/usr/local/lib/nagios/plugins/check-logstashforwarder-sending.sh"
36 )
37 nrpe_compat.write()
38 copy_check_files()
39
40
41 def copy_check_files():
42- script_dir="/usr/local/lib/nagios/plugins"
43+ script_dir = "/usr/local/lib/nagios/plugins"
44 mkdir(script_dir)
45 for script in ["check-logstashforwarder-sending.sh"]:
46 src = os.path.join(charm_dir(), "files", script)
47@@ -192,6 +196,7 @@
48 writeEtcHosts()
49 writeConfig()
50 service_restart("logstash-forwarder")
51+ update_nrpe_checks()
52
53
54 @hooks.hook("start")
55
56=== added symlink 'hooks/nrpe-external-master-relation-changed'
57=== target is u'hooks.py'

Subscribers

People subscribed via source and target branches