[bradm] Added support to get nagios hostname from nrpe relation
This commit is contained in:
@@ -129,6 +129,7 @@ define service {{
|
||||
os.path.join(os.environ['CHARM_DIR'],
|
||||
'files/nrpe-external-master'),
|
||||
'/usr/lib/nagios/plugins',
|
||||
'/usr/local/lib/nagios/plugins',
|
||||
)
|
||||
parts = shlex.split(check_cmd)
|
||||
for path in search_path:
|
||||
@@ -181,12 +182,15 @@ class NRPE(object):
|
||||
nagios_exportdir = '/var/lib/nagios/export'
|
||||
nrpe_confdir = '/etc/nagios/nrpe.d'
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, hostname=None):
|
||||
super(NRPE, self).__init__()
|
||||
self.config = config()
|
||||
self.nagios_context = self.config['nagios_context']
|
||||
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 = []
|
||||
|
||||
def add_check(self, *args, **kwargs):
|
||||
|
||||
@@ -10,6 +10,7 @@ from charmhelpers.core.hookenv import (
|
||||
relation_set,
|
||||
relation_get,
|
||||
relation_ids,
|
||||
relations_of_type,
|
||||
unit_get
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
@@ -193,7 +194,14 @@ def website_relation_joined():
|
||||
|
||||
@hooks.hook('nrpe-external-master-relation-joined', 'nrpe-external-master-relation-changed')
|
||||
def update_nrpe_config():
|
||||
nrpe_compat = nrpe.NRPE()
|
||||
# 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
|
||||
nrpe_compat = nrpe.NRPE(hostname=hostname)
|
||||
|
||||
conf = nrpe_compat.config
|
||||
check_http_params = conf.get('nagios_check_http_params')
|
||||
if check_http_params:
|
||||
|
||||
Reference in New Issue
Block a user