Skip to content

Commit

Permalink
Fix directory /etc/nagios/nrpe.d/ issue (#492)
Browse files Browse the repository at this point in the history
* Fix directory /etc/nagios/nrpe.d/  issue

Under certain deployment conditions, the charm can attempt to write to
the /etc/nagios/nrpe.d/ directory before it exists.  This directory is
created by the nrpe charm, but if the hacluster gets installed first,
then it can be triggered to attempt to set up the nrpe entries before
the directory can be created by nrpe.  This change (and the associated
charm-helpers change) ensures that the charm will delay the nrpe config
until the directory is available (and thus, the nrpe charm is fully
installed)

Related Bug: LP: #1882557

* Simplify the check so it doesn't do the write.

Co-authored-by: David Ames <david.ames@canonical.com>
  • Loading branch information
ajkavanagh and thedac committed Jul 16, 2020
1 parent b6cb715 commit 9e20a38
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions charmhelpers/contrib/charmsupport/nrpe.py
Expand Up @@ -18,14 +18,14 @@
# Authors:
# Matthew Wedgwood <matthew.wedgwood@canonical.com>

import subprocess
import pwd
import glob
import grp
import os
import glob
import shutil
import pwd
import re
import shlex
import shutil
import subprocess
import yaml

from charmhelpers.core.hookenv import (
Expand Down Expand Up @@ -265,6 +265,11 @@ def __init__(self, hostname=None, primary=True):
relation_set(relation_id=rid, relation_settings={'primary': self.primary})
self.remove_check_queue = set()

@classmethod
def does_nrpe_conf_dir_exist(cls):
"""Return True if th nrpe_confdif directory exists."""
return os.path.isdir(cls.nrpe_confdir)

def add_check(self, *args, **kwargs):
shortname = None
if kwargs.get('shortname') is None:
Expand Down Expand Up @@ -310,6 +315,12 @@ def write(self):

nrpe_monitors = {}
monitors = {"monitors": {"remote": {"nrpe": nrpe_monitors}}}

# check that the charm can write to the conf dir. If not, then nagios
# probably isn't installed, and we can defer.
if not self.does_nrpe_conf_dir_exist():
return

for nrpecheck in self.checks:
nrpecheck.write(self.nagios_context, self.hostname,
self.nagios_servicegroups)
Expand Down

0 comments on commit 9e20a38

Please sign in to comment.