From f15f9cda9b06e8857f23c755632dab8be88027a4 Mon Sep 17 00:00:00 2001 From: Paul Collins Date: Fri, 26 May 2017 11:05:54 +1200 Subject: [PATCH] deploy a simple service check --- config.yaml | 14 ++++++++++++++ layer.yaml | 1 + metadata.yaml | 4 ++++ reactive/vault.py | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/config.yaml b/config.yaml index 5413d7b..8582b8e 100644 --- a/config.yaml +++ b/config.yaml @@ -8,6 +8,20 @@ options: When this option is set, vault will be unable to prevent secrets from being paged out, so use it with extreme caution. + nagios_context: + default: "juju" + type: string + description: | + A string that will be prepended to instance name to set the host name + in nagios. So for instance the hostname would be something like: + juju-myservice-0 + If you're running multiple environments with the same services in them + this allows you to differentiate between them. + nagios_servicegroups: + default: "juju" + type: string + description: | + Comma separated list of nagios servicegroups for the graphite check ssl-cert: type: string default: "" diff --git a/layer.yaml b/layer.yaml index fcbb5d6..db0b838 100644 --- a/layer.yaml +++ b/layer.yaml @@ -1,6 +1,7 @@ includes: - layer:basic - layer:snap + - interface:nrpe-external-master - interface:pgsql options: basic: diff --git a/metadata.yaml b/metadata.yaml index d1e0939..003d544 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -6,3 +6,7 @@ description: seriously, it's just a vault charm requires: db: interface: pgsql +provides: + nrpe-external-master: + interface: nrpe-external-master + scope: container diff --git a/reactive/vault.py b/reactive/vault.py index 12a3654..5a64009 100644 --- a/reactive/vault.py +++ b/reactive/vault.py @@ -1,6 +1,13 @@ import base64 import psycopg2 +from charmhelpers.contrib.charmsupport.nrpe import ( + NRPE, + add_init_service_checks, + get_nagios_hostname, + get_nagios_unit_name, +) + from charmhelpers.core.hookenv import ( config, open_port, @@ -140,3 +147,15 @@ def ssl_chain_changed(): @when('config.changed.ssl-key') def ssl_key_changed(): remove_state('vault.ssl.configured') + + +@when('configured') +@when('nrpe-external-master.available') +def update_nagios(svc): + status_set('maintenance', 'configuring Nagios checks') + hostname = get_nagios_hostname() + current_unit = get_nagios_unit_name() + nrpe = NRPE(hostname=hostname) + add_init_service_checks(nrpe, ['vault'], current_unit) + nrpe.write() + status_set('active', 'Nagios checks configured')