nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #00774
[Merge] ~peppepetra86/thruk-agent-charm:lp1838548 into thruk-agent-charm:master
Giuseppe Petralia has proposed merging ~peppepetra86/thruk-agent-charm:lp1838548 into thruk-agent-charm:master.
Commit message:
Not restart thruk when update-status runs
Requested reviews:
Canonical IS Reviewers (canonical-is-reviewers)
Nagios Charm developers (nagios-charmers)
For more details, see:
https://code.launchpad.net/~peppepetra86/thruk-agent-charm/+git/thruk-agent-charm/+merge/378127
--
Your team Nagios Charm developers is requested to review the proposed merge of ~peppepetra86/thruk-agent-charm:lp1838548 into thruk-agent-charm:master.
diff --git a/hooks/config-changed b/hooks/config-changed
deleted file mode 100755
index 5028988..0000000
--- a/hooks/config-changed
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/python
-import services
-services.manage()
diff --git a/hooks/config-changed b/hooks/config-changed
new file mode 120000
index 0000000..9416ca6
--- /dev/null
+++ b/hooks/config-changed
@@ -0,0 +1 @@
+hooks.py
\ No newline at end of file
diff --git a/hooks/hook.template b/hooks/hook.template
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/hooks/hook.template
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.')
+
+ # 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))
diff --git a/hooks/services.py b/hooks/services.py
deleted file mode 100644
index b21febe..0000000
--- a/hooks/services.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/python
-
-from charmhelpers.core.services.base import ServiceManager
-from charmhelpers.core.services import helpers
-from charmhelpers.core import hookenv
-
-import actions
-import thruk_helpers
-
-
-def manage():
- config = hookenv.config()
- 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()
diff --git a/hooks/start b/hooks/start
deleted file mode 100755
index 5028988..0000000
--- a/hooks/start
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/python
-import services
-services.manage()
diff --git a/hooks/start b/hooks/start
new file mode 120000
index 0000000..9416ca6
--- /dev/null
+++ b/hooks/start
@@ -0,0 +1 @@
+hooks.py
\ No newline at end of file
diff --git a/hooks/stop b/hooks/stop
deleted file mode 100755
index 5028988..0000000
--- a/hooks/stop
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/python
-import services
-services.manage()
diff --git a/hooks/stop b/hooks/stop
new file mode 120000
index 0000000..9416ca6
--- /dev/null
+++ b/hooks/stop
@@ -0,0 +1 @@
+hooks.py
\ No newline at end of file
diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
deleted file mode 100755
index 5028988..0000000
--- a/hooks/upgrade-charm
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/python
-import services
-services.manage()
diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
new file mode 120000
index 0000000..9416ca6
--- /dev/null
+++ b/hooks/upgrade-charm
@@ -0,0 +1 @@
+hooks.py
\ No newline at end of file
References