Add support for optional nagios_hostname set by nrpe-external-master
This commit is contained in:
parent
f5e46b121f
commit
9183ec3a72
|
@ -0,0 +1 @@
|
||||||
|
revision
|
|
@ -179,12 +179,15 @@ class NRPE(object):
|
||||||
nagios_exportdir = '/var/lib/nagios/export'
|
nagios_exportdir = '/var/lib/nagios/export'
|
||||||
nrpe_confdir = '/etc/nagios/nrpe.d'
|
nrpe_confdir = '/etc/nagios/nrpe.d'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, hostname=None):
|
||||||
super(NRPE, self).__init__()
|
super(NRPE, self).__init__()
|
||||||
self.config = config()
|
self.config = config()
|
||||||
self.nagios_context = self.config['nagios_context']
|
self.nagios_context = self.config['nagios_context']
|
||||||
self.unit_name = local_unit().replace('/', '-')
|
self.unit_name = local_unit().replace('/', '-')
|
||||||
self.hostname = "{}-{}".format(self.nagios_context, self.unit_name)
|
if hostname:
|
||||||
|
self.hostname = hostname
|
||||||
|
else:
|
||||||
|
self.hostname = "{}-{}".format(self.nagios_context, self.unit_name)
|
||||||
self.checks = []
|
self.checks = []
|
||||||
|
|
||||||
def add_check(self, *args, **kwargs):
|
def add_check(self, *args, **kwargs):
|
||||||
|
|
|
@ -33,6 +33,7 @@ from charmhelpers.core.hookenv import (
|
||||||
related_units,
|
related_units,
|
||||||
service_name,
|
service_name,
|
||||||
local_unit,
|
local_unit,
|
||||||
|
relations_of_type,
|
||||||
config,
|
config,
|
||||||
unit_get,
|
unit_get,
|
||||||
is_relation_made,
|
is_relation_made,
|
||||||
|
@ -360,6 +361,12 @@ def update_nrpe_checks():
|
||||||
'check_rabbitmq.py'),
|
'check_rabbitmq.py'),
|
||||||
os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq.py'))
|
os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq.py'))
|
||||||
|
|
||||||
|
# Find out if nrpe set nagios_hostname
|
||||||
|
hostname=None
|
||||||
|
for rel in relations_of_type('nrpe-external-master'):
|
||||||
|
if 'nagios_hostname' in rel:
|
||||||
|
hostname = rel['nagios_hostname']
|
||||||
|
break
|
||||||
# create unique user and vhost for each unit
|
# create unique user and vhost for each unit
|
||||||
current_unit = local_unit().replace('/', '-')
|
current_unit = local_unit().replace('/', '-')
|
||||||
user = 'nagios-%s' % current_unit
|
user = 'nagios-%s' % current_unit
|
||||||
|
@ -370,7 +377,7 @@ def update_nrpe_checks():
|
||||||
rabbit.create_user(user, password)
|
rabbit.create_user(user, password)
|
||||||
rabbit.grant_permissions(user, vhost)
|
rabbit.grant_permissions(user, vhost)
|
||||||
|
|
||||||
nrpe_compat = NRPE()
|
nrpe_compat = NRPE(hostname=hostname)
|
||||||
nrpe_compat.add_check(
|
nrpe_compat.add_check(
|
||||||
shortname=rabbit.RABBIT_USER,
|
shortname=rabbit.RABBIT_USER,
|
||||||
description='Check RabbitMQ',
|
description='Check RabbitMQ',
|
||||||
|
|
Loading…
Reference in New Issue