Point nrpe helper at nrpe files

The glance charm has a slightly different layout compared to other
OpenStack charms so nrpe.copy_nrpe_checks() needs to be pointed
at an alternative location for the nrpe checks the charm provides.

Change-Id: I3c7ce63069379008754bcba9201a3fc9c568853d
Closes-Bug: #1779155
This commit is contained in:
Liam Young 2018-06-28 17:02:31 +00:00
parent f9d8444009
commit 4f935e3900
4 changed files with 42 additions and 6 deletions

View File

@ -410,16 +410,21 @@ def add_init_service_checks(nrpe, services, unit_name, immediate_check=True):
os.chmod(checkpath, 0o644) os.chmod(checkpath, 0o644)
def copy_nrpe_checks(): def copy_nrpe_checks(nrpe_files_dir=None):
""" """
Copy the nrpe checks into place Copy the nrpe checks into place
""" """
NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins' NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
nrpe_files_dir = os.path.join(os.getenv('CHARM_DIR'), 'hooks', default_nrpe_files_dir = os.path.join(
'charmhelpers', 'contrib', 'openstack', os.getenv('CHARM_DIR'),
'files') 'hooks',
'charmhelpers',
'contrib',
'openstack',
'files')
if not nrpe_files_dir:
nrpe_files_dir = default_nrpe_files_dir
if not os.path.exists(NAGIOS_PLUGINS): if not os.path.exists(NAGIOS_PLUGINS):
os.makedirs(NAGIOS_PLUGINS) os.makedirs(NAGIOS_PLUGINS)
for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")): for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):

View File

@ -972,6 +972,20 @@ def is_container():
def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH): def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH):
"""Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list.
This method has no effect if the path specified by updatedb_path does not
exist or is not a file.
@param path: string the path to add to the updatedb.conf PRUNEPATHS value
@param updatedb_path: the path the updatedb.conf file
"""
if not os.path.exists(updatedb_path) or os.path.isdir(updatedb_path):
# If the updatedb.conf file doesn't exist then don't attempt to update
# the file as the package providing mlocate may not be installed on
# the local system
return
with open(updatedb_path, 'r+') as f_id: with open(updatedb_path, 'r+') as f_id:
updatedb_text = f_id.read() updatedb_text = f_id.read()
output = updatedb(updatedb_text, path) output = updatedb(updatedb_text, path)

View File

@ -56,6 +56,7 @@ from glance_utils import (
update_image_location_policy, update_image_location_policy,
) )
from charmhelpers.core.hookenv import ( from charmhelpers.core.hookenv import (
charm_dir,
config, config,
Hooks, Hooks,
log as juju_log, log as juju_log,
@ -563,7 +564,9 @@ def update_nrpe_config():
hostname = nrpe.get_nagios_hostname() hostname = nrpe.get_nagios_hostname()
current_unit = nrpe.get_nagios_unit_name() current_unit = nrpe.get_nagios_unit_name()
nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe_setup = nrpe.NRPE(hostname=hostname)
nrpe.copy_nrpe_checks() nrpe_files_dir = os.path.join(
charm_dir(), 'charmhelpers', 'contrib', 'openstack', 'files')
nrpe.copy_nrpe_checks(nrpe_files_dir=nrpe_files_dir)
nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit)
nrpe_setup.write() nrpe_setup.write()

View File

@ -972,6 +972,20 @@ def is_container():
def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH): def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH):
"""Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list.
This method has no effect if the path specified by updatedb_path does not
exist or is not a file.
@param path: string the path to add to the updatedb.conf PRUNEPATHS value
@param updatedb_path: the path the updatedb.conf file
"""
if not os.path.exists(updatedb_path) or os.path.isdir(updatedb_path):
# If the updatedb.conf file doesn't exist then don't attempt to update
# the file as the package providing mlocate may not be installed on
# the local system
return
with open(updatedb_path, 'r+') as f_id: with open(updatedb_path, 'r+') as f_id:
updatedb_text = f_id.read() updatedb_text = f_id.read()
output = updatedb(updatedb_text, path) output = updatedb(updatedb_text, path)