def update_nrpe_config(): hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() services = [service_name] nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.add_init_service_checks(nrpe_setup, services, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') log('Refreshing nrpe checks') if not os.path.exists(NAGIOS_PLUGINS): mkpath(NAGIOS_PLUGINS) rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master', 'check_swift_storage.py'), os.path.join(NAGIOS_PLUGINS, 'check_swift_storage.py')) rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master', 'check_swift_service'), os.path.join(NAGIOS_PLUGINS, 'check_swift_service')) rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'sudo', 'swift-storage'), os.path.join(SUDOERS_D, 'swift-storage')) # Find out if nrpe set nagios_hostname hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) # check the rings and replication nrpe_setup.add_check( shortname='swift_storage', description='Check swift storage ring hashes and replication' ' {%s}' % current_unit, check_cmd='check_swift_storage.py {}'.format( config('nagios-check-params')) ) nrpe.add_init_service_checks(nrpe_setup, SWIFT_SVCS, current_unit) nrpe_setup.write()
def test_add_init_service_checks(self): def _exists(init_file): files = [ '/etc/init/apache2.conf', '/usr/lib/nagios/plugins/check_upstart_job', '/etc/init.d/haproxy', '/usr/lib/nagios/plugins/check_status_file.py', ] return init_file in files self.patched['exists'].side_effect = _exists bill = nrpe.NRPE() services = ['apache2', 'haproxy'] nrpe.add_init_service_checks(bill, services, 'testunit') expect_cmds = { 'apache2': '/usr/lib/nagios/plugins/check_upstart_job apache2', 'haproxy': '/usr/lib/nagios/plugins/check_status_file.py -f ' '/var/lib/nagios/service-check-haproxy.txt', } self.assertEqual(bill.checks[0].shortname, 'apache2') self.assertEqual(bill.checks[0].check_cmd, expect_cmds['apache2']) self.assertEqual(bill.checks[1].shortname, 'haproxy') self.assertEqual(bill.checks[1].check_cmd, expect_cmds['haproxy'])
def update_nrpe_config(checks_to_remove=None): """ Update the checks for the nagios plugin. :param checks_to_remove: list of short names of nrpe checks to remove. For example, pass ['radosgw'] to remove the check for the default systemd radosgw service, to make way for per host services. :type checks_to_remove: list """ # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() if checks_to_remove is not None: log("Removing the following nrpe checks: {}".format(checks_to_remove), level=DEBUG) for svc in checks_to_remove: nrpe_setup.remove_check(shortname=svc) nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): services = ('snap.kubelet.daemon', 'snap.kube-proxy.daemon') 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()
def render_nrpe_checks(self): """Configure Nagios NRPE checks.""" hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() charm_nrpe = nrpe.NRPE(hostname=hostname) nrpe.add_init_service_checks(charm_nrpe, self.services, current_unit) charm_nrpe.write()
def update_nrpe_config(checks_to_remove=None): """ Update the checks for the nagios plugin. :param checks_to_remove: list of short names of nrpe checks to remove. For example, pass ['radosgw'] to remove the check for the default systemd radosgw service, to make way for per host services. :type checks_to_remove: list """ # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() if checks_to_remove is not None: log("Removing the following nrpe checks: {}".format(checks_to_remove), level=DEBUG) for svc in checks_to_remove: nrpe_setup.remove_check(shortname=svc) nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): services = ('snap.kubelet.daemon', 'snap.kube-proxy.daemon') 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()
def update_nrpe_config(unused=None): services = ('nginx', ) 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()
def update_nrpe_config(unused=None): hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname, primary=True) # Add a check for the snap's systemd service nrpe.add_init_service_checks(nrpe_setup, SNAP_SERVICES, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): services = ('nginx',) 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()
def update_nrpe_config(svc): # python-dbus is used by check_upstart_job fetch.apt_install('python-dbus') 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, SVCNAME, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): services = ('kube-apiserver', 'kube-controller-manager', 'kube-scheduler') 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()
def update_nrpe_config(svc): # python-dbus is used by check_upstart_job fetch.apt_install('python-dbus') 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, SVCNAME, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): services = ('kube-apiserver', 'kube-controller-manager', 'kube-scheduler') 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()
def update_nagios(): ch_core.hookenv.status_set('maintenance', 'configuring Nagios checks') current_unit = nrpe.get_nagios_unit_name() with charm.provide_charm_instance() as charm_instance: services = charm_instance.full_service_list nrpe_instance = nrpe.NRPE() nrpe.add_init_service_checks(nrpe_instance, services, current_unit) nrpe_instance.write() reactive.set_state('octavia.nrpe.configured') ch_core.hookenv.status_set('active', 'Nagios checks configured')
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): # List of systemd services that will be checked services = ('snap.etcd.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) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') 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, ['mysql'], current_unit) nrpe_setup.add_check(shortname='mysql_proc', description='Check MySQL process {%s}' % current_unit, check_cmd='check_procs -c 1:1 -C mysqld') nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe_files_dir = os.path.join( charm_dir(), 'charmhelpers', 'contrib', 'openstack', 'files') nrpe.copy_nrpe_checks(nrpe_files_dir=nrpe_files_dir) nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe_files_dir = os.path.join(charm_dir(), 'charmhelpers', 'contrib', 'openstack', 'files') nrpe.copy_nrpe_checks(nrpe_files_dir=nrpe_files_dir) nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def configure_nrpe(unused=None): hookenv.log('Configuring nrpe checks for services: ' '{}'.format(MONITORED_SERVICES)) # 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, MONITORED_SERVICES, current_unit) nrpe_setup.write() set_state('nrpe-external-master.initial-config')
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') 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, 'mysql', current_unit) nrpe_setup.add_check( shortname='mysql_proc', description='Check MySQL process {%s}' % current_unit, check_cmd='check_procs -c 1:1 -C mysqld' ) nrpe_setup.write()
def update_nrpe_config(): """ :return: None """ # List of systemd services that will be checked. services = ['docker'] # 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) nrpe.add_init_service_checks(nrpe_setup, services, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) monitored_services = services() try: # qemu-kvm is a one-shot service monitored_services.remove('qemu-kvm') except ValueError: pass nrpe.add_init_service_checks(nrpe_setup, monitored_services, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) if service_enabled('api'): nrpe.add_haproxy_checks(nrpe_setup, current_unit) else: nrpe.remove_deprecated_check(nrpe_setup, ["haproxy_servers", "haproxy_queue"]) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) monitored_services = services() try: # qemu-kvm is a one-shot service monitored_services.remove('qemu-kvm') except ValueError: pass nrpe.add_init_service_checks(nrpe_setup, monitored_services, current_unit) nrpe_setup.write()
def render_nrpe(self): """Configure Nagios NRPE checks.""" ch_core.hookenv.log("Rendering NRPE checks.", level=ch_core.hookenv.INFO) hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() # Determine if this is a subordinate unit or not if ch_core.hookenv.principal_unit() == ch_core.hookenv.local_unit(): primary = True else: primary = False charm_nrpe = nrpe.NRPE(hostname=hostname, primary=primary) nrpe.add_init_service_checks(charm_nrpe, self.nrpe_check_services, current_unit) charm_nrpe.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() _services = [] for service in services(): if service.startswith('snap.'): service = service.split('.')[1] _services.append(service) nrpe.add_init_service_checks(nrpe_setup, _services, current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(unused=None): # List of systemd services that will be checked services = ("snap.etcd.etcd", ) # The current nrpe-external 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) # add our first check, to alert on service failure nrpe.add_init_service_checks(nrpe_setup, services, current_unit) # add the cron job to populate the cache for our second check # (we cache the output of 'etcdctl alarm list' to minimise overhead) with open("templates/check_etcd-alarms.cron") as fp: write_file( path="/etc/cron.d/check_etcd-alarms", content=fp.read().encode(), owner="root", perms=0o644, ) # create an empty output file for the above write_file( path="/var/lib/nagios/etcd-alarm-list.txt", content="", owner="root", perms=0o644, ) # install the NRPE script for the above with open("templates/check_etcd-alarms.py") as fp: write_file( path="/usr/lib/nagios/plugins/check_etcd-alarms.py", content=fp.read().encode(), owner="root", perms=0o755, ) # define our second check, to alert on etcd alarm status nrpe_setup.add_check( "etcd-alarms", "Verify etcd has no raised alarms", "/usr/lib/nagios/plugins/check_etcd-alarms.py", ) nrpe_setup.write() set_state("etcd.nrpe.configured")
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) api_port = determine_api_port(config('bind-port'), singlenode_mode=True) nrpe_setup.add_check(shortname="swift-proxy-healthcheck", description="Check Swift Proxy Healthcheck", check_cmd="/usr/lib/nagios/plugins/check_http \ -I localhost -u /healthcheck -p {} \ -e \"OK\"".format(api_port)) nrpe_setup.write()
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) write_file('/usr/lib/nagios/plugins/check_vault_version.py', open('files/nagios/check_vault_version.py', 'rb').read(), perms=0o755) nrpe.add_check( 'vault_version', 'Check running vault server version is same as installed snap', '/usr/lib/nagios/plugins/check_vault_version.py', ) nrpe.write() set_state('vault.nrpe.configured')
def update_nrpe_config(): # python-dbus is used by check_upstart_job log('Updating NRPE configuration') status_set('maintenance', 'Updating NRPE configuration') apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() _services = [] for service in services(): if service.startswith('snap.'): service = service.split('.')[1] _services.append(service) nrpe.add_init_service_checks(nrpe_setup, _services, current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) conf = nrpe_setup.config check_http_params = conf.get('nagios_check_http_params') if check_http_params: nrpe_setup.add_check(shortname='vhost', description='Check Virtual Host {%s}' % current_unit, check_cmd='check_http %s' % check_http_params) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe.copy_nrpe_checks() nrpe.add_init_service_checks(nrpe_setup, services(), current_unit) nrpe.add_haproxy_checks(nrpe_setup, current_unit) conf = nrpe_setup.config check_http_params = conf.get('nagios_check_http_params') if check_http_params: nrpe_setup.add_check( shortname='vhost', description='Check Virtual Host {%s}' % current_unit, check_cmd='check_http %s' % check_http_params ) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') 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) cronpath = '/etc/cron.d/nagios-netns-check' cron_template = ('*/5 * * * * root ' '/usr/local/lib/nagios/plugins/check_netns.sh ' '> /var/lib/nagios/netns-check.txt\n') f = open(cronpath, 'w') f.write(cron_template) f.close() nrpe_setup.add_check( shortname="netns", description='Network Namespace check {%s}' % current_unit, check_cmd='check_status_file.py -f /var/lib/nagios/netns-check.txt') nrpe_setup.write()
def update_nagios(svc): status_set('maintenance', 'configuring Nagios checks') hostname = get_nagios_hostname() current_unit = get_nagios_unit_name() nrpe = NRPE(hostname=hostname) remove_deprecated_check(nrpe, ['vault_version']) add_init_service_checks(nrpe, ['vault'], current_unit) try: os.remove('/usr/lib/nagios/plugins/check_vault_version.py') except FileNotFoundError: pass write_file('/usr/lib/nagios/plugins/check_vault_health.py', open('files/nagios/check_vault_health.py', 'rb').read(), perms=0o755) nrpe.add_check( 'vault_health', 'Check running vault server version and health', '/usr/lib/nagios/plugins/check_vault_health.py', ) nrpe.write() set_state('vault.nrpe.configured')
def test_add_init_service_checks(self, mock_isdir): def _exists(init_file): files = ['/etc/init/apache2.conf', '/usr/lib/nagios/plugins/check_upstart_job', '/etc/init.d/haproxy', '/usr/lib/nagios/plugins/check_status_file.py', '/etc/cron.d/nagios-service-check-haproxy', '/var/lib/nagios/service-check-haproxy.txt', '/usr/lib/nagios/plugins/check_systemd.py' ] return init_file in files self.patched['exists'].side_effect = _exists # Test without systemd and /var/lib/nagios does not exist self.patched['init_is_systemd'].return_value = False mock_isdir.return_value = False bill = nrpe.NRPE() services = ['apache2', 'haproxy'] nrpe.add_init_service_checks(bill, services, 'testunit') mock_isdir.assert_called_with('/var/lib/nagios') self.patched['call'].assert_not_called() expect_cmds = { 'apache2': '/usr/lib/nagios/plugins/check_upstart_job apache2', 'haproxy': '/usr/lib/nagios/plugins/check_status_file.py -f ' '/var/lib/nagios/service-check-haproxy.txt', } self.assertEqual(bill.checks[0].shortname, 'apache2') self.assertEqual(bill.checks[0].check_cmd, expect_cmds['apache2']) self.assertEqual(bill.checks[1].shortname, 'haproxy') self.assertEqual(bill.checks[1].check_cmd, expect_cmds['haproxy']) # without systemd and /var/lib/nagios does exist mock_isdir.return_value = True f = MagicMock() self.patched['open'].return_value = f bill = nrpe.NRPE() services = ['apache2', 'haproxy'] nrpe.add_init_service_checks(bill, services, 'testunit') mock_isdir.assert_called_with('/var/lib/nagios') self.patched['call'].assert_called_with( ['/usr/local/lib/nagios/plugins/check_exit_status.pl', '-e', '-s', '/etc/init.d/haproxy', 'status'], stdout=f, stderr=subprocess.STDOUT) # Test regular services and snap services with systemd services = ['apache2', 'haproxy', 'snap.test.test'] self.patched['init_is_systemd'].return_value = True nrpe.add_init_service_checks(bill, services, 'testunit') expect_cmds = { 'apache2': '/usr/lib/nagios/plugins/check_systemd.py apache2', 'haproxy': '/usr/lib/nagios/plugins/check_systemd.py haproxy', 'snap.test.test': '/usr/lib/nagios/plugins/check_systemd.py snap.test.test', } self.assertEqual(bill.checks[2].shortname, 'apache2') self.assertEqual(bill.checks[2].check_cmd, expect_cmds['apache2']) self.assertEqual(bill.checks[3].shortname, 'haproxy') self.assertEqual(bill.checks[3].check_cmd, expect_cmds['haproxy']) self.assertEqual(bill.checks[4].shortname, 'snap.test.test') self.assertEqual(bill.checks[4].check_cmd, expect_cmds['snap.test.test'])
def update_nrpe_config(): # python-dbus is used by check_upstart_job # python-psutil is used by check_ntpmon fetch.apt_install(['python-dbus', 'python-psutil']) nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks').split(" ") if os.path.isdir(NAGIOS_PLUGINS): host.rsync( os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios', 'check_ntpmon.py'), os.path.join(NAGIOS_PLUGINS, 'check_ntpmon.py')) 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, ['ntp'], current_unit) allchecks = set(['offset', 'peers', 'reachability', 'sync']) # remove any previously-created ntpmon checks nrpe_setup.remove_check(shortname="ntpmon") for c in allchecks: nrpe_setup.remove_check(shortname="ntpmon_%s" % c) # If all checks are specified, combine them into a single check to reduce # Nagios noise. if set(nagios_ntpmon_checks) == allchecks: nrpe_setup.add_check( shortname="ntpmon", description='Check NTPmon {}'.format(current_unit), check_cmd='check_ntpmon.py') else: for nc in nagios_ntpmon_checks: if len(nc) > 0: nrpe_setup.add_check( shortname="ntpmon_%s" % nc, description='Check NTPmon %s {%s}' % (nc, current_unit), check_cmd='check_ntpmon.py --check %s' % nc) nrpe_setup.write()
def update_nrpe_config(): # python-dbus is used by check_upstart_job apt_install('python-dbus') 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) cronpath = '/etc/cron.d/nagios-netns-check' cron_template = ('*/5 * * * * root ' '/usr/local/lib/nagios/plugins/check_netns.sh ' '> /var/lib/nagios/netns-check.txt\n' ) f = open(cronpath, 'w') f.write(cron_template) f.close() nrpe_setup.add_check( shortname="netns", description='Network Namespace check {%s}' % current_unit, check_cmd='check_status_file.py -f /var/lib/nagios/netns-check.txt' ) nrpe_setup.write()
def update_nrpe_config(): services = ["snap.{}.daemon".format(s) for s in worker_services] data = render("nagios_plugin.py", None, {"node_name": get_node_name()}) plugin_path = install_nagios_plugin_from_text(data, "check_k8s_worker.py") hostname = nrpe.get_nagios_hostname() current_unit = nrpe.get_nagios_unit_name() nrpe_setup = nrpe.NRPE(hostname=hostname) nrpe_setup.add_check("node", "Node registered with API Server", str(plugin_path)) nrpe.add_init_service_checks(nrpe_setup, services, current_unit) nrpe_setup.write() creds = db.get("credentials") servers = get_kube_api_servers() if creds and servers: server = servers[get_unit_number() % len(servers)] create_kubeconfig( nrpe_kubeconfig_path, server, ca_crt_path, token=creds["client_token"], user="******", ) # Make sure Nagios dirs are the correct permissions. cmd = ["chown", "-R", "nagios:nagios"] for p in ["/var/lib/nagios/", os.path.dirname(nrpe_kubeconfig_path)]: if os.path.exists(p): check_call(cmd + [p]) remove_state("nrpe-external-master.reconfigure") set_state("nrpe-external-master.initial-config") # request CPU governor check from nrpe relation to be performance rel_settings = { "requested_cpu_governor": "performance", } for rid in hookenv.relation_ids("nrpe-external-master"): hookenv.relation_set(relation_id=rid, relation_settings=rel_settings)