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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
from etcdctl import EtcdCtl | ||
from etcdctl import get_connection_string | ||
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'] | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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