Update bradms branch to add nrpe support

This commit is contained in:
Liam Young 2015-01-26 08:00:21 +00:00
parent e021803cb6
commit 0a5b435f3c
3 changed files with 12 additions and 49 deletions

View File

@ -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__':

Binary file not shown.

View File

@ -22,7 +22,8 @@ TO_PATCH = [
'CONFIGS',
'relation_set',
'openstack_upgrade_available',
'do_openstack_upgrade'
'do_openstack_upgrade',
'update_nrpe_config',
]
@ -53,6 +54,7 @@ class CeilometerHooksTest(CharmTestCase):
def test_ceilometer_changed(self, mock_config):
hooks.hooks.execute(['hooks/ceilometer-service-relation-changed'])
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.update_nrpe_config.called)
@patch('charmhelpers.core.hookenv.config')
def test_nova_ceilometer_joined(self, mock_config):
@ -68,6 +70,7 @@ class CeilometerHooksTest(CharmTestCase):
assert_called_with('ceilometer-common')
self.assertFalse(self.do_openstack_upgrade.called)
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.update_nrpe_config.called)
@patch('charmhelpers.core.hookenv.config')
def test_config_changed_upgrade(self, mock_config):
@ -77,3 +80,4 @@ class CeilometerHooksTest(CharmTestCase):
assert_called_with('ceilometer-common')
self.assertTrue(self.do_openstack_upgrade.called)
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.update_nrpe_config.called)