add nrpe-external-master relation to kubernetes-master and kubernetes-worker
For now, the checks are very basic and only check if the systemd services are running properly.
This commit is contained in:
@@ -24,13 +24,14 @@ from socket import gethostname
|
||||
from charms import layer
|
||||
from charms.reactive import hook
|
||||
from charms.reactive import set_state, remove_state
|
||||
from charms.reactive import when, when_not
|
||||
from charms.reactive import when, when_any, when_not
|
||||
from charms.reactive.helpers import data_changed
|
||||
from charms.kubernetes.flagmanager import FlagManager
|
||||
from charms.templating.jinja2 import render
|
||||
|
||||
from charmhelpers.core import hookenv
|
||||
from charmhelpers.core.host import service_stop
|
||||
from charmhelpers.contrib.charmsupport import nrpe
|
||||
|
||||
|
||||
kubeconfig_path = '/srv/kubernetes/config'
|
||||
@@ -447,6 +448,44 @@ def kubectl_manifest(operation, manifest):
|
||||
return kubectl_success(operation, '-f', manifest)
|
||||
|
||||
|
||||
@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('kubernetes-worker.config.created')
|
||||
@when('nrpe-external-master.available')
|
||||
@when_any('config.changed.nagios_context',
|
||||
'config.changed.nagios_servicegroups')
|
||||
def update_nrpe_config(unused=None):
|
||||
services = ('kubelet', 'kube-proxy')
|
||||
|
||||
hostname = nrpe.get_nagios_hostname()
|
||||
current_unit = nrpe.get_nagios_unit_name()
|
||||
nrpe_setup = nrpe.NRPE(hostname=hostname)
|
||||
nrpe.add_init_service_checks(nrpe_setup, services, current_unit)
|
||||
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 = ('kubelet', 'kube-proxy')
|
||||
|
||||
# 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)
|
||||
|
||||
for service in services:
|
||||
nrpe_setup.remove_check(shortname=service)
|
||||
|
||||
|
||||
def _systemctl_is_active(application):
|
||||
''' Poll systemctl to determine if the application is running '''
|
||||
cmd = ['systemctl', 'is-active', application]
|
||||
|
Reference in New Issue
Block a user