Add option to check extra vhosts with nrpe

Adds monitoring options to allow us to check for vhosts in addition to
the host specific one made by default, when using the nrpe subordinate.

Change-Id: I10715e8ab8c83fdd7d5c08736ee89472acfe3933
Related-Bug: 1730507
This commit is contained in:
Xav Paice 2017-11-07 21:01:53 +13:00
parent 38015e5c79
commit 5558e21ea8
3 changed files with 50 additions and 35 deletions

View File

@ -298,3 +298,10 @@ options:
1 hour, but can be tuned up or down depending on deployment requirements.
This ensures that any un-consumed notifications don't build up over
time, causing disk capacity issues.
check-vhosts:
type: string
default:
description: |
When using nrpe to monitor the Rabbitmq host, we monitor functionality on
one vhost. This option configures additional vhost name(s) to check.
Space separated list.

View File

@ -676,41 +676,45 @@ def update_nrpe_checks():
# create unique user and vhost for each unit
current_unit = local_unit().replace('/', '-')
user = 'nagios-%s' % current_unit
vhost = 'nagios-%s' % current_unit
user = 'nagios-{}'.format(current_unit)
vhosts = [{'vhost': user, 'shortname': rabbit.RABBIT_USER}]
password = rabbit.get_rabbit_password(user, local=True)
rabbit.create_vhost(vhost)
rabbit.create_user(user, password, ['monitoring'])
rabbit.grant_permissions(user, vhost)
nrpe_compat = nrpe.NRPE(hostname=hostname)
if config('ssl') in ['off', 'on']:
cmd = ('{plugins_dir}/check_rabbitmq.py --user {user} '
'--password {password} --vhost {vhost}')
cmd = cmd.format(plugins_dir=NAGIOS_PLUGINS, user=user,
password=password, vhost=vhost)
nrpe_compat.add_check(
shortname=rabbit.RABBIT_USER,
description='Check RabbitMQ {%s}' % myunit,
check_cmd=cmd
)
if config('ssl') in ['only', 'on']:
log('Adding rabbitmq SSL check', level=DEBUG)
cmd = ('{plugins_dir}/check_rabbitmq.py --user {user} '
'--password {password} --vhost {vhost} '
'--ssl --ssl-ca {ssl_ca} --port {port}')
cmd = cmd.format(plugins_dir=NAGIOS_PLUGINS,
user=user,
password=password,
port=int(config('ssl_port')),
vhost=vhost,
ssl_ca=SSL_CA_FILE)
nrpe_compat.add_check(
shortname=rabbit.RABBIT_USER + "_ssl",
description='Check RabbitMQ (SSL) {%s}' % myunit,
check_cmd=cmd
)
rabbit.create_user(user, password, ['monitoring'])
if config('check-vhosts'):
for other_vhost in config('check-vhosts').split(' '):
if other_vhost:
item = {'vhost': other_vhost,
'shortname': 'rabbit_{}'.format(other_vhost)}
vhosts.append(item)
for vhost in vhosts:
rabbit.create_vhost(vhost['vhost'])
rabbit.grant_permissions(user, vhost['vhost'])
if config('ssl') in ['off', 'on']:
cmd = ('{}/check_rabbitmq.py --user {} --password {} '
'--vhost {}'.format(NAGIOS_PLUGINS, user,
password, vhost['vhost']))
log('Adding rabbitmq non-SSL check for {}'.format(vhost['vhost']), level=DEBUG)
description = 'Check RabbitMQ {} {}'.format(myunit, vhost['vhost'])
nrpe_compat.add_check(
shortname=vhost['shortname'],
description=description,
check_cmd=cmd)
if config('ssl') in ['only', 'on']:
cmd = ('{}/check_rabbitmq.py --user {} --password {} '
'--vhost {} --ssl --ssl-ca {} --port {}'.format(
NAGIOS_PLUGINS, user, password, vhost['vhost'],
SSL_CA_FILE, int(config('ssl_port'))))
log('Adding rabbitmq SSL check for {}'.format(vhost['vhost']), level=DEBUG)
description = 'Check RabbitMQ (SSL) {} {}'.format(myunit, vhost['vhost'])
nrpe_compat.add_check(
shortname=vhost['shortname'] + "_ssl",
description=description,
check_cmd=cmd)
if config('queue_thresholds'):
cmd = ""
@ -962,6 +966,7 @@ def update_status():
log('Updating status.')
if __name__ == '__main__':
try:
hooks.execute(sys.argv)

View File

@ -346,7 +346,6 @@ class RelationUtil(CharmTestCase):
mock_local_unit.return_value = 'unit/0'
rabbitmq_server_relations.update_nrpe_checks()
mock_check_output.assert_any_call(
['/usr/bin/rsync', '-r', '--delete', '--executability',
'%s/files/collect_rabbitmq_stats.sh' % self.tmp_dir,
@ -362,7 +361,9 @@ class RelationUtil(CharmTestCase):
mock_add_check.assert_any_call(
shortname=rabbit_utils.RABBIT_USER,
description='Check RabbitMQ {%s}' % 'bar-0', check_cmd=cmd)
description='Check RabbitMQ {} {}'.format('bar-0',
'nagios-unit-0'),
check_cmd=cmd)
# check on ssl port 5671
cmd = ('{plugins_dir}/check_rabbitmq.py --user {user} '
@ -376,4 +377,6 @@ class RelationUtil(CharmTestCase):
ssl_ca=rabbitmq_server_relations.SSL_CA_FILE)
mock_add_check.assert_any_call(
shortname=rabbit_utils.RABBIT_USER + "_ssl",
description='Check RabbitMQ (SSL) {%s}' % 'bar-0', check_cmd=cmd)
description='Check RabbitMQ (SSL) {} {}'.format('bar-0',
'nagios-unit-0'),
check_cmd=cmd)