Add basic, running services only, NRPE support to the charm
Change-Id: Ib4b0dc8c47b77ec80845bd8987ebba11388604ab Closes-Bug: #1871655
This commit is contained in:
parent
18e2e4dadf
commit
283521f62a
|
@ -142,3 +142,17 @@ options:
|
|||
named by amp-ssh-key-name. Note that once the key is created it cannot be
|
||||
modified and the only way to do so is to delete it and have the charm
|
||||
create a new one.
|
||||
nagios_context:
|
||||
default: "juju"
|
||||
type: string
|
||||
description: |
|
||||
A string that will be prepended to instance name to set the host name
|
||||
in nagios. So for instance the hostname would be something like:
|
||||
juju-myservice-0
|
||||
If you're running multiple environments with the same services in them
|
||||
this allows you to differentiate between them.
|
||||
nagios_servicegroups:
|
||||
default: "juju"
|
||||
type: string
|
||||
description: |
|
||||
Comma separated list of nagios servicegroups for the graphite check
|
||||
|
|
|
@ -8,6 +8,7 @@ includes:
|
|||
- interface:neutron-plugin
|
||||
- interface:ovsdb-subordinate
|
||||
- interface:ovsdb-cms
|
||||
- interface:nrpe-external-master
|
||||
options:
|
||||
basic:
|
||||
use_venv: True
|
||||
|
|
|
@ -22,6 +22,10 @@ series:
|
|||
- eoan
|
||||
- focal
|
||||
subordinate: false
|
||||
provides:
|
||||
nrpe-external-master:
|
||||
interface: nrpe-external-master
|
||||
scope: container
|
||||
requires:
|
||||
neutron-api:
|
||||
interface: neutron-load-balancer
|
||||
|
|
|
@ -24,6 +24,8 @@ import charms_openstack.ip as os_ip
|
|||
|
||||
import charmhelpers.core as ch_core
|
||||
|
||||
from charmhelpers.contrib.charmsupport import nrpe
|
||||
|
||||
import charm.openstack.api_crud as api_crud
|
||||
import charm.openstack.octavia as octavia
|
||||
|
||||
|
@ -214,3 +216,29 @@ def cluster_connected(hacluster):
|
|||
with charm.provide_charm_instance() as octavia_charm:
|
||||
octavia_charm.configure_ha_resources(hacluster)
|
||||
octavia_charm.assess_status()
|
||||
|
||||
|
||||
@reactive.when('charm.installed')
|
||||
@reactive.when('nrpe-external-master.available')
|
||||
@reactive.when_not('octavia.nrpe.configured')
|
||||
def update_nagios():
|
||||
ch_core.hookenv.status_set('maintenance', 'configuring Nagios checks')
|
||||
current_unit = nrpe.get_nagios_unit_name()
|
||||
with charm.provide_charm_instance() as charm_instance:
|
||||
services = charm_instance.full_service_list
|
||||
nrpe_instance = nrpe.NRPE()
|
||||
nrpe.add_init_service_checks(nrpe_instance, services, current_unit)
|
||||
nrpe_instance.write()
|
||||
reactive.set_state('octavia.nrpe.configured')
|
||||
ch_core.hookenv.status_set('active', 'Nagios checks configured')
|
||||
|
||||
|
||||
@reactive.when_any('config.changed.nagios_context',
|
||||
'config.changed.nagios_servicegroups')
|
||||
def nagios_config_changed():
|
||||
reactive.remove_state('octavia.nrpe.configured')
|
||||
|
||||
|
||||
@reactive.hook('upgrade-charm')
|
||||
def upgrade_charm():
|
||||
reactive.remove_state('octavia.nrpe.configured')
|
||||
|
|
|
@ -62,10 +62,16 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|||
'identity-service.connected',),
|
||||
'maybe_enable_ovn_driver': (
|
||||
'ovsdb-subordinate.available',),
|
||||
'update_nagios': (
|
||||
'charm.installed',
|
||||
'nrpe-external-master.available',),
|
||||
},
|
||||
'when_any': {
|
||||
'sdn_joined': ('neutron-openvswitch.connected',
|
||||
'ovsdb-subordinate.available'),
|
||||
'nagios_config_changed': (
|
||||
'config.changed.nagios_context',
|
||||
'config.changed.nagios_servicegroups'),
|
||||
},
|
||||
'when_none': {
|
||||
'sdn_broken': ('neutron-openvswitch.connected',
|
||||
|
@ -76,6 +82,10 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|||
'cluster_connected': ('ha.available',),
|
||||
'generate_heartbeat_key': ('leadership.set.heartbeat-key',),
|
||||
'disable_ovn_driver': ('ovsdb-subordinate.available',),
|
||||
'update_nagios': ('octavia.nrpe.configured',),
|
||||
},
|
||||
'hook': {
|
||||
'upgrade_charm': ('upgrade-charm',),
|
||||
},
|
||||
}
|
||||
# test that the hooks were registered via the
|
||||
|
@ -216,3 +226,22 @@ class TestOctaviaHandlers(test_utils.PatchHelper):
|
|||
'charm.octavia.enable-ovn-driver')
|
||||
self.octavia_charm.install.assert_called_once_with()
|
||||
self.octavia_charm.assess_status.assert_called_once_with()
|
||||
|
||||
def test_update_nagios(self):
|
||||
self.patch_object(handlers.nrpe, 'get_nagios_unit_name',
|
||||
return_value=mock.sentinel.unit_name)
|
||||
nrpe_instance = mock.MagicMock()
|
||||
self.patch_object(handlers.nrpe, 'NRPE', return_value=nrpe_instance)
|
||||
self.patch_object(handlers.nrpe, 'add_init_service_checks')
|
||||
self.patch('charms.reactive.set_state')
|
||||
handlers.update_nagios()
|
||||
self.add_init_service_checks.assert_called_once_with(
|
||||
nrpe_instance, self.octavia_charm.full_service_list,
|
||||
mock.sentinel.unit_name)
|
||||
nrpe_instance.write.assert_called_once()
|
||||
self.set_state.assert_called_once_with('octavia.nrpe.configured')
|
||||
|
||||
def test_nagios_config_changed(self):
|
||||
self.patch('charms.reactive.remove_state')
|
||||
handlers.nagios_config_changed()
|
||||
self.remove_state.assert_called_once_with('octavia.nrpe.configured')
|
||||
|
|
Loading…
Reference in New Issue