nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #00813
Re: [Merge] ~peppepetra86/thruk-agent-charm:lp1838548 into thruk-agent-charm:master
Diff comments:
> diff --git a/hooks/hooks.py b/hooks/hooks.py
> index 5028988..3623e46 100755
> --- a/hooks/hooks.py
> +++ b/hooks/hooks.py
> @@ -1,3 +1,86 @@
> #!/usr/bin/python
> -import services
> -services.manage()
> +
> +import sys
> +
> +from charmhelpers.core.services.base import ServiceManager
> +from charmhelpers.core.services import helpers
> +from charmhelpers.core import hookenv, host
> +
> +import actions
> +import thruk_helpers
> +
> +config = hookenv.config()
> +hooks = hookenv.Hooks()
> +
> +
> +@hooks.hook('nrpe-external-master-relation-{joined,changed,broken,departed}')
> +@hooks.hook('thruk-agent-relation-{joined,changed,broken,departed}')
> +@hooks.hook('config-changed')
> +@hooks.hook('start')
> +@hooks.hook('stop')
> +def config_changed():
> + manager = ServiceManager([
> + {
> + 'service': 'thruk',
> + 'provided_data': [
> + thruk_helpers.ThrukAgentRelation()
> + ],
> + 'required_data': [
> + thruk_helpers.ThrukInfo(),
> + thruk_helpers.CheckLivestatusSocket(),
> + ],
> + 'data_ready': [
> + helpers.render_template(
> + source='thruk_local.conf',
> + target='/etc/thruk/thruk_local.conf'),
> + actions.log_start,
> + actions.update_ppa,
> + actions.fix_livestatus_perms,
> + actions.thruk_set_password,
> + actions.notify_thrukmaster_relation,
> + actions.update_status,
> + ],
> + },
> + {
> + 'service': 'thruk-monitoring',
> + 'required_data': [
> + thruk_helpers.NEMRelation(),
> + helpers.RequiredConfig(),
> + ],
> + 'data_ready': [
> + helpers.render_template(
> + source='thruk-nrpe.j2',
> + target='/etc/nagios/nrpe.d/check_{}.cfg'.format(
> + hookenv.local_unit().replace('/', '-'),
> + )
> + ),
> + helpers.render_template(
> + source='thruk-nagios.j2',
> + target='/var/lib/nagios/export/service__{}-{}.cfg'.format(
> + config['nagios_context'],
> + hookenv.local_unit().replace('/', '-'),
> + )
> + ),
> + ],
> + },
> + ])
> + manager.manage()
> +
> +
> +@hooks.hook('update-status')
> +def update_status():
> + if host.service_running('thruk'):
> + hookenv.status_set('active', 'ready')
> + else:
> + hookenv.status_set('blocked', '"thruk" service is not running.')
thruk_helpers.CheckLivestatusSocket() set the status to blocked if livestatus is not enable and will update unit status with a message that suggests to the operator to check if livestatus is enabled on nagios.
Using the proposed approach, the final status will be 'blocked', '"thruk" service is not running.'
> +
> + # Reconfigure service if nagios has enabled livestatus
> + if thruk_helpers.CheckLivestatusSocket():
> + config_changed()
> +
> +
> +if __name__ == '__main__':
> + try:
> + hooks.execute(sys.argv)
> + except hookenv.UnregisteredHookError as e:
> + hookenv.log('Unknown hook {} - skipping.'.format(e))
--
https://code.launchpad.net/~peppepetra86/thruk-agent-charm/+git/thruk-agent-charm/+merge/378127
Your team Nagios Charm developers is subscribed to branch thruk-agent-charm:master.
References