Add NRPE checks for services

Adds the nrpe-external-master layer and checks for services managed by
this charm.

func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/436

Change-Id: Ice5eada838626059f8cb2c427f7b9b0884317660
Closes-Bug: #1897809
Related-Bug: #1933643
Co-authored-by: Aurelien Lourot <aurelien.lourot@canonical.com>
This commit is contained in:
Xav Paice 2020-10-02 13:13:22 +13:00 committed by Aurelien Lourot
parent fa48d3d7cf
commit 3ae0be599b
23 changed files with 149 additions and 14 deletions

View File

@ -128,3 +128,18 @@ options:
description: | description: |
Default for how old deleted zones should be (deleted_at) to be Default for how old deleted zones should be (deleted_at) to be
purged, in seconds. purged, in seconds.
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: ""
type: string
description: |
A comma-separated list of nagios servicegroups. If left empty, the
nagios_context will be used as the servicegroup.

View File

@ -1,4 +1,4 @@
includes: ['layer:openstack-api', 'layer:leadership', 'interface:bind-rndc', 'interface:hacluster', 'interface:openstack-ha', 'interface:memcache', 'interface:designate'] includes: ['layer:openstack-api', 'layer:leadership', 'interface:bind-rndc', 'interface:hacluster', 'interface:openstack-ha', 'interface:memcache', 'interface:designate', 'interface:nrpe-external-master']
options: options:
basic: basic:
use_venv: True use_venv: True

View File

@ -19,6 +19,7 @@ import subprocess
import uuid import uuid
import charmhelpers.contrib.openstack.utils as ch_utils import charmhelpers.contrib.openstack.utils as ch_utils
import charmhelpers.contrib.charmsupport.nrpe as nrpe
import charms_openstack.adapters as openstack_adapters import charms_openstack.adapters as openstack_adapters
import charms_openstack.charm as openstack_charm import charms_openstack.charm as openstack_charm
import charms_openstack.ip as os_ip import charms_openstack.ip as os_ip
@ -613,6 +614,15 @@ class DesignateCharm(ch_plugins.PolicydOverridePlugin,
hookenv.leader_set({'pool-manager-cache-sync-done': True}) hookenv.leader_set({'pool-manager-cache-sync-done': True})
self.restart_all() self.restart_all()
def render_nrpe(self):
"""Configure Nagios NRPE checks."""
hostname = nrpe.get_nagios_hostname()
current_unit = nrpe.get_nagios_unit_name()
charm_nrpe = nrpe.NRPE(hostname=hostname)
nrpe.add_init_service_checks(
charm_nrpe, self.services, current_unit)
charm_nrpe.write()
class DesignateCharmQueens(DesignateCharm): class DesignateCharmQueens(DesignateCharm):

View File

@ -24,6 +24,9 @@ provides:
interface: designate interface: designate
nova-designate: nova-designate:
interface: nova-designate interface: nova-designate
nrpe-external-master:
interface: nrpe-external-master
scope: container
requires: requires:
dns-backend: dns-backend:
interface: bind-rndc interface: bind-rndc

View File

@ -254,3 +254,15 @@ def reset_shared_db():
""" """
reactive.remove_state('shared-db.setup') reactive.remove_state('shared-db.setup')
reactive.remove_state('db.synched') reactive.remove_state('db.synched')
@reactive.when_not('is-update-status-hook')
@reactive.when('base-config.rendered')
@reactive.when_any('config.changed.nagios_context',
'config.changed.nagios_servicegroups',
'endpoint.nrpe-external-master.changed',
'nrpe-external-master.available')
def configure_nrpe():
"""Handle config-changed for NRPE options."""
with charm.provide_charm_instance() as charm_instance:
charm_instance.render_nrpe()

View File

@ -48,6 +48,8 @@ applications:
nameservers: 'ns1.amuletexample.com. ns2.amuletexample.com.' nameservers: 'ns1.amuletexample.com. ns2.amuletexample.com.'
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -69,4 +71,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:bionic-rocky openstack-origin: cloud:bionic-rocky
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:bionic-stein openstack-origin: cloud:bionic-stein
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:bionic-train openstack-origin: cloud:bionic-train
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -54,6 +54,8 @@ applications:
openstack-origin: cloud:bionic-ussuri openstack-origin: cloud:bionic-ussuri
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -76,3 +78,5 @@ relations:
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -74,7 +74,7 @@ applications:
memcached: memcached:
charm: cs:~memcached-team/memcached charm: cs:~memcached-team/memcached
num_units: 1 num_units: 1
# holding charm at bionic as it isn't available for focal yet # holding charm at bionic as it isn't available for focal+ yet
series: bionic series: bionic
to: to:
- '7' - '7'
@ -88,6 +88,9 @@ applications:
to: to:
- '8' - '8'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'keystone:shared-db' - - 'keystone:shared-db'
- 'keystone-mysql-router:shared-db' - 'keystone-mysql-router:shared-db'
@ -124,3 +127,6 @@ relations:
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -74,7 +74,7 @@ applications:
memcached: memcached:
charm: cs:~memcached-team/memcached charm: cs:~memcached-team/memcached
num_units: 1 num_units: 1
# holding charm at bionic as it isn't available for focal yet # holding charm at bionic as it isn't available for focal+ yet
series: bionic series: bionic
to: to:
- '7' - '7'
@ -88,6 +88,9 @@ applications:
to: to:
- '8' - '8'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'keystone:shared-db' - - 'keystone:shared-db'
- 'keystone-mysql-router:shared-db' - 'keystone-mysql-router:shared-db'
@ -124,3 +127,6 @@ relations:
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -74,7 +74,7 @@ applications:
memcached: memcached:
charm: cs:~memcached-team/memcached charm: cs:~memcached-team/memcached
num_units: 1 num_units: 1
# holding charm at bionic as it isn't available for focal yet # holding charm at bionic as it isn't available for focal+ yet
series: bionic series: bionic
to: to:
- '7' - '7'
@ -88,6 +88,9 @@ applications:
to: to:
- '8' - '8'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'keystone:shared-db' - - 'keystone:shared-db'
- 'keystone-mysql-router:shared-db' - 'keystone-mysql-router:shared-db'
@ -124,3 +127,6 @@ relations:
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -74,7 +74,7 @@ applications:
memcached: memcached:
charm: cs:~memcached-team/memcached charm: cs:~memcached-team/memcached
num_units: 1 num_units: 1
# holding charm at bionic as it isn't available for focal/groovy yet # holding charm at bionic as it isn't available for focal+ yet
series: bionic series: bionic
to: to:
- '7' - '7'
@ -88,6 +88,9 @@ applications:
to: to:
- '8' - '8'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'keystone:shared-db' - - 'keystone:shared-db'
- 'keystone-mysql-router:shared-db' - 'keystone-mysql-router:shared-db'
@ -124,3 +127,6 @@ relations:
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -74,7 +74,7 @@ applications:
memcached: memcached:
charm: cs:~memcached-team/memcached charm: cs:~memcached-team/memcached
num_units: 1 num_units: 1
# holding charm at bionic as it isn't available for focal/groovy yet # holding charm at bionic as it isn't available for focal+ yet
series: bionic series: bionic
to: to:
- '7' - '7'
@ -88,6 +88,9 @@ applications:
to: to:
- '8' - '8'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'keystone:shared-db' - - 'keystone:shared-db'
- 'keystone-mysql-router:shared-db' - 'keystone-mysql-router:shared-db'
@ -124,3 +127,6 @@ relations:
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -48,6 +48,8 @@ applications:
nameservers: 'ns1.amuletexample.com. ns2.amuletexample.com.' nameservers: 'ns1.amuletexample.com. ns2.amuletexample.com.'
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -69,4 +71,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:xenial-ocata openstack-origin: cloud:xenial-ocata
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:xenial-pike openstack-origin: cloud:xenial-pike
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -53,6 +53,8 @@ applications:
openstack-origin: cloud:xenial-queens openstack-origin: cloud:xenial-queens
to: to:
- '5' - '5'
nrpe:
charm: cs:nrpe
relations: relations:
- - 'designate:shared-db' - - 'designate:shared-db'
@ -74,4 +76,6 @@ relations:
- - 'neutron-api:shared-db' - - 'neutron-api:shared-db'
- 'percona-cluster:shared-db' - 'percona-cluster:shared-db'
- - 'neutron-api:amqp' - - 'neutron-api:amqp'
- 'rabbitmq-server:amqp' - 'rabbitmq-server:amqp'
- - 'designate:nrpe-external-master'
- 'nrpe:nrpe-external-master'

View File

@ -25,6 +25,14 @@ dev_bundles:
tests: tests:
- zaza.openstack.charm_tests.designate.tests.DesignateTests - zaza.openstack.charm_tests.designate.tests.DesignateTests
target_deploy_status:
nrpe:
workload-status: blocked
workload-status-message: "Nagios server not configured or related"
tests_options: tests_options:
force_deploy: force_deploy:
# NOTE(lourot): this is needed because the NRPE charm isn't available on
# non-LTS Ubuntu series. See lp:1933643
- groovy-victoria
- hirsute-wallaby - hirsute-wallaby

View File

@ -23,6 +23,7 @@ import charms_openstack.test_mocks # noqa
charms_openstack.test_mocks.mock_charmhelpers() charms_openstack.test_mocks.mock_charmhelpers()
sys.modules['charmhelpers.core.decorators'] = ( sys.modules['charmhelpers.core.decorators'] = (
charms_openstack.test_mocks.charmhelpers.core.decorators) charms_openstack.test_mocks.charmhelpers.core.decorators)
sys.modules['charmhelpers.contrib.charmsupport.nrpe'] = mock.MagicMock()
def _fake_retry(num_retries, base_delay=0, exc_type=Exception): def _fake_retry(num_retries, base_delay=0, exc_type=Exception):

View File

@ -40,6 +40,7 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'remote_pools_updated': ( 'remote_pools_updated': (
'leadership.changed.pool-yaml-hash', ), 'leadership.changed.pool-yaml-hash', ),
'reset_shared_db': ('shared-db.setup', ), 'reset_shared_db': ('shared-db.setup', ),
'configure_nrpe': ('base-config.rendered', ),
}, },
'when_not': { 'when_not': {
'setup_amqp_req': ('amqp.requested-access', ), 'setup_amqp_req': ('amqp.requested-access', ),
@ -52,10 +53,17 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'run_assess_status_on_every_hook': ( 'run_assess_status_on_every_hook': (
'dont-set-assess-status', ), 'dont-set-assess-status', ),
'reset_shared_db': ('shared-db.connected', ), 'reset_shared_db': ('shared-db.connected', ),
'configure_nrpe': ('is-update-status-hook', ),
}, },
'when_any': { 'when_any': {
'set_dns_config_available': ( 'set_dns_config_available': (
'dns-slaves-config-valid', 'dns-backend.available', ), 'dns-slaves-config-valid', 'dns-backend.available', ),
'configure_nrpe': (
'config.changed.nagios_context',
'config.changed.nagios_servicegroups',
'endpoint.nrpe-external-master.changed',
'nrpe-external-master.available',
),
}, },
'when_none': { 'when_none': {
'clear_dns_config_available': ( 'clear_dns_config_available': (

View File

@ -363,6 +363,18 @@ class TestDesignateCharm(Helper):
pass pass
self.assertFalse(self.leader_set.called) self.assertFalse(self.leader_set.called)
def test_render_nrpe(self):
self.patch_object(designate.nrpe, 'add_init_service_checks')
charm_instance = designate.DesignateCharm(release='queens')
charm_instance.render_nrpe()
self.add_init_service_checks.assert_has_calls([
mock.call().add_init_service_checks(
mock.ANY,
charm_instance.services,
mock.ANY
),
])
class TestDesignateQueensCharm(Helper): class TestDesignateQueensCharm(Helper):