From 0a5b435f3cc076b5a2e6cf070fbd7cd98bb6df00 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 26 Jan 2015 08:00:21 +0000 Subject: [PATCH] Update bradms branch to add nrpe support --- hooks/ceilometer_hooks.py | 55 ++++------------------------ hooks/charmhelpers/__init__.pyc | Bin 612 -> 612 bytes unit_tests/test_ceilometer_hooks.py | 6 ++- 3 files changed, 12 insertions(+), 49 deletions(-) diff --git a/hooks/ceilometer_hooks.py b/hooks/ceilometer_hooks.py index ceb83d9..38b2add 100755 --- a/hooks/ceilometer_hooks.py +++ b/hooks/ceilometer_hooks.py @@ -1,7 +1,6 @@ #!/usr/bin/python import sys -import os import json from charmhelpers.fetch import ( apt_install, filter_installed_packages, @@ -11,9 +10,7 @@ from charmhelpers.core.hookenv import ( config, Hooks, UnregisteredHookError, log, - local_unit, relation_set, - relations_of_type, ) from charmhelpers.core.host import ( restart_on_change, @@ -31,8 +28,7 @@ from ceilometer_utils import ( NOVA_SETTINGS, do_openstack_upgrade ) - -from charmhelpers.contrib.charmsupport.nrpe import NRPE +from charmhelpers.contrib.charmsupport import nrpe hooks = Hooks() CONFIGS = register_configs() @@ -76,50 +72,13 @@ def config_changed(): @hooks.hook('nrpe-external-master-relation-joined', 'nrpe-external-master-relation-changed') def update_nrpe_config(): - # Find out if nrpe set nagios_hostname - hostname = None - host_context = None - for rel in relations_of_type('nrpe-external-master'): - if 'nagios_hostname' in rel: - hostname = rel['nagios_hostname'] - host_context = rel['nagios_host_context'] - break - nrpe = NRPE(hostname=hostname) + # python-dbus is used by check_upstart_job apt_install('python-dbus') - - if host_context: - current_unit = "%s:%s" % (host_context, local_unit()) - else: - current_unit = local_unit() - - services_to_monitor = services() - - for service in services_to_monitor: - upstart_init = '/etc/init/%s.conf' % service - sysv_init = '/etc/init.d/%s' % service - - if os.path.exists(upstart_init): - nrpe.add_check( - shortname=service, - description='process check {%s}' % current_unit, - check_cmd='check_upstart_job %s' % service, - ) - elif os.path.exists(sysv_init): - cronpath = '/etc/cron.d/nagios-service-check-%s' % service - cron_template = '*/5 * * * * root \ -/usr/local/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/%s \ -status > /var/lib/nagios/service-check-%s.txt\n' % (service, service) - f = open(cronpath, 'w') - f.write(cron_template) - f.close() - nrpe.add_check( - shortname=service, - description='process check {%s}' % current_unit, - check_cmd='check_status_file.py -f \ - /var/lib/nagios/service-check-%s.txt' % service, - ) - - nrpe.write() + hostname = nrpe.get_nagios_hostname() + current_unit = nrpe.get_nagios_unit_name() + nrpe_setup = nrpe.NRPE(hostname=hostname) + nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) + nrpe_setup.write() if __name__ == '__main__': diff --git a/hooks/charmhelpers/__init__.pyc b/hooks/charmhelpers/__init__.pyc index a8a8e88dc9209f04c5c5ebdd3d557f6450ed9a82..56ced77a4f29fd3e1d873ac425ec203518698c32 100644 GIT binary patch delta 22 ecmaFD@`Qz*`7