← Back to team overview

nagios-charmers team mailing list archive

[Merge] ~shaner/thruk-agent-charm:master into thruk-agent-charm:master

 

Shane Peters has proposed merging ~shaner/thruk-agent-charm:master into thruk-agent-charm:master.

Commit message:
enable status updates

Requested reviews:
  Nagios Charm developers (nagios-charmers)

For more details, see:
https://code.launchpad.net/~shaner/thruk-agent-charm/+git/thruk-agent-charm/+merge/361690
-- 
Your team Nagios Charm developers is requested to review the proposed merge of ~shaner/thruk-agent-charm:master into thruk-agent-charm:master.
diff --git a/hooks/actions.py b/hooks/actions.py
index d75affd..a72e9a6 100644
--- a/hooks/actions.py
+++ b/hooks/actions.py
@@ -98,3 +98,7 @@ def update_ppa(service_name):
     apt_update(fatal=True)
     package_list = ["thruk", "pwgen", "apache2-utils"]
     apt_install(packages=package_list, fatal=True)
+
+
+def update_status(service_name):
+   hookenv.status_set('active', 'ready')
diff --git a/hooks/services.py b/hooks/services.py
index 36b9a17..b21febe 100644
--- a/hooks/services.py
+++ b/hooks/services.py
@@ -16,7 +16,10 @@ def manage():
             'provided_data': [
                 thruk_helpers.ThrukAgentRelation()
             ],
-            'required_data': [thruk_helpers.ThrukInfo()],
+            'required_data': [
+                thruk_helpers.ThrukInfo(),
+                thruk_helpers.CheckLivestatusSocket(),
+            ],
             'data_ready': [
                 helpers.render_template(
                     source='thruk_local.conf',
@@ -26,6 +29,7 @@ def manage():
                 actions.fix_livestatus_perms,
                 actions.thruk_set_password,
                 actions.notify_thrukmaster_relation,
+                actions.update_status,
             ],
         },
         {
diff --git a/hooks/thruk_helpers.py b/hooks/thruk_helpers.py
index df208e5..70619ce 100644
--- a/hooks/thruk_helpers.py
+++ b/hooks/thruk_helpers.py
@@ -3,6 +3,8 @@
 from charmhelpers.core import hookenv
 from charmhelpers.core.services import helpers
 
+import os
+import sys
 import hashlib
 
 
@@ -45,6 +47,18 @@ class ThrukInfo(dict):
         self['thruk_id'] = m.hexdigest()
 
 
+class CheckLivestatusSocket(dict):
+    def __bool__(self):
+        if not os.path.exists(hookenv.config('livestatus_path')):
+            hookenv.status_set('blocked',
+                               'nagios livestatus socket missing')
+            return False
+        return True
+
+    def __nonzero__(self):
+        return self.__bool__()
+
+
 class NEMRelation(helpers.RelationContext):
     name = 'nrpe-external-master'
     interface = 'nrpe-external-master'
@@ -58,4 +72,3 @@ class NEMRelation(helpers.RelationContext):
         if not hookenv.relation_ids(self.name):
             return
         self['nrpe_external_master'] = self[self.name]
-
diff --git a/hooks/update-status b/hooks/update-status
new file mode 120000
index 0000000..9416ca6
--- /dev/null
+++ b/hooks/update-status
@@ -0,0 +1 @@
+hooks.py
\ No newline at end of file

Follow ups