You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sebastian Bazley <se...@apache.org> on 2016/04/01 20:44:36 UTC

[whimsy.git] [1/1] Commit 62df2de: Initial code for system-related status checks

Commit 62df2de2682ab99e11ca7797f2f714beab1c7368:
    Initial code for system-related status checks


Branch: refs/heads/master
Author: Sebb <se...@apache.org>
Committer: Sebb <se...@apache.org>
Pusher: sebb <se...@apache.org>

------------------------------------------------------------
www/status/monitors/system.rb                                | ++++++++++ 
------------------------------------------------------------
39 changes: 39 additions, 0 deletions.
------------------------------------------------------------


diff --git a/www/status/monitors/system.rb b/www/status/monitors/system.rb
new file mode 100644
index 0000000..029da34
--- /dev/null
+++ b/www/status/monitors/system.rb
@@ -0,0 +1,39 @@
+#
+# Monitor status of system
+# Currently only checks puppet
+#
+
+require 'time'
+
+def Monitor.system(previous_status)
+  name='puppet'
+  status = {}
+  status[name] = {
+    mtime: Time.now.gmtime.iso8601,
+    command: 'service puppet status'
+  }
+  begin
+    puppet = `service puppet status`.strip
+    if puppet.include? ' * agent is running'
+      status[name].merge! level: 'warning', title: puppet
+    end
+    rescue Exception => e
+      status[name] = {
+        level: 'danger',
+        data: {
+          exception: {
+            level: 'danger',
+            text: e.inspect,
+            data: e.backtrace
+          }
+        }
+      }
+  end
+  {data: status}
+end
+
+# for debugging purposes
+if __FILE__ == $0
+  require 'json'
+  puts JSON.pretty_generate(Monitor.system(nil))
+end