Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an nrpe-external-master relation, with a basic check (systemd service is running) #74

Merged
merged 3 commits into from Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions layer.yaml
@@ -1,11 +1,13 @@
repo: https://github.com/juju-solutions/layer-etcd.git
includes:
- 'layer:basic'
- 'layer:tls-client'
- 'layer:leadership'
- 'layer:debug'
- 'layer:leadership'
- 'layer:nagios'
- 'layer:tls-client'
- 'interface:etcd'
- 'interface:etcd-proxy'
- 'interface:nrpe-external-master'
options:
basic:
packages: ['rsync']
Expand Down
42 changes: 42 additions & 0 deletions reactive/etcd.py
Expand Up @@ -25,6 +25,7 @@
from charmhelpers.core import host
from charmhelpers.fetch import apt_update
from charmhelpers.fetch import apt_install
from charmhelpers.contrib.charmsupport import nrpe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this library provided by the nrpe interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's in charmhelpers, which is provided by hmmm the basic layer I think ? I'm not sure I understand your question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is included in charmhelpers


from etcdctl import EtcdCtl
from etcdctl import get_connection_string
Expand Down Expand Up @@ -505,6 +506,47 @@ def read_tls_cert(cert):
return data


@when('nrpe-external-master.available')
@when_not('nrpe-external-master.initial-config')
def initial_nrpe_config(nagios=None):
set_state('nrpe-external-master.initial-config')
update_nrpe_config(nagios)


@when('etcd.installed')
@when('nrpe-external-master.available')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to include logic to remove the nrpe check when the relationship to etcd is removed/destroyed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, working on that.

@when_any('config.changed.nagios_context',
'config.changed.nagios_servicegroups')
def update_nrpe_config(unused=None):
# List of systemd services that will be checked
services = ('etcd',)

# The current nrpe-external-master interface doesn't handle a lot of logic,
# use the charm-helpers code for now.
hostname = nrpe.get_nagios_hostname()
current_unit = nrpe.get_nagios_unit_name()
nrpe_setup = nrpe.NRPE(hostname=hostname, primary=False)
nrpe.add_init_service_checks(nrpe_setup, services, current_unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this method has a very permissive reactive clause. Is this add idempotent? Will multiple adds work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "very permissive reactive clause" ? AIUI, it will only fire when the config option "nagios_context" or "nagios_servicegroups" is changed, which shouldn't happen all that often. Is that not the case ?

nrpe_setup.write()


@when_not('nrpe-external-master.available')
@when('nrpe-external-master.initial-config')
def remove_nrpe_config(nagios=None):
remove_state('nrpe-external-master.initial-config')

# List of systemd services for which the checks will be removed
services = ('etcd',)

# The current nrpe-external-master interface doesn't handle a lot of logic,
# use the charm-helpers code for now.
hostname = nrpe.get_nagios_hostname()
nrpe_setup = nrpe.NRPE(hostname=hostname, primary=False)

for service in services:
nrpe_setup.remove_check(shortname=service)


def volume_is_mounted(volume):
''' Takes a hardware path and returns true/false if it is mounted '''
cmd = ['df', '-t', 'ext4']
Expand Down