You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2017/06/12 21:13:37 UTC

[whimsy] branch master updated: Check the freshness of the hermes mail jobs

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 46dc7ee  Check the freshness of the hermes mail jobs
46dc7ee is described below

commit 46dc7ee72d84666b346fa78d01fa7611e22c33a8
Author: Sebb <se...@apache.org>
AuthorDate: Mon Jun 12 22:13:35 2017 +0100

    Check the freshness of the hermes mail jobs
---
 www/status/monitors/mail_jobs.rb | 81 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/www/status/monitors/mail_jobs.rb b/www/status/monitors/mail_jobs.rb
new file mode 100644
index 0000000..24faee6
--- /dev/null
+++ b/www/status/monitors/mail_jobs.rb
@@ -0,0 +1,81 @@
+#
+# Monitor status of public json directory
+#
+
+=begin
+
+Checks log files with names 'public-*' for relevant output.
+
+Possible status level output:
+Success - only DEBUG or INFO messages seen
+Info - diff -u output detected
+Warning - WARN log messages seen or file more than 1.5 hours old
+Danger - File more than 24 hours old or Exception while processing
+
+=end
+
+require 'fileutils'
+require 'time'
+
+def Monitor.mail_jobs(previous_status)
+  danger_period = 86_400 # one day
+
+  warning_hours = 7 # cron job should run every 6 hours
+  warning_period = warning_hours * 3600
+
+  logdir = '/srv/subscriptions'
+  logs = File.join(logdir, '*')
+
+  status = {}
+
+  Dir[logs].each do |log|
+    name = File.basename(log).to_sym
+    next if name == :'incubator-mods' # obsolete
+
+    begin
+      status[name] = {
+        href: "../logs/#{File.basename(log)}",
+        mtime: File.mtime(log).gmtime.iso8601, # to agree with normalise
+        level: 'success' # to agree with normalise
+      }
+
+      # Check to see if the log has been updated recently
+      if Time.now - File.mtime(log) > warning_period
+        status[name].merge! level: 'warning',
+          data: "Last updated: #{File.mtime(log).to_s} (more than #{warning_hours} hours old)"
+      end
+
+      # Check to see if the log has been updated recently
+      if Time.now - File.mtime(log) > danger_period
+        status[name].merge! level: 'danger',
+          data: "Last updated: #{File.mtime(log).to_s} (more than 24 hours old)"
+      end
+
+      # monitor.rb ignores data if title is set
+      # TODO: is this a bug in monitor.rb ?
+      if status[name][:data]
+        status[name].delete_if { |k, v| k.eql? :title}
+      end
+
+    rescue Exception => e
+      status[name] = {
+        level: 'danger',
+        data: {
+          exception: {
+            level: 'danger',
+            text: e.inspect,
+            data: e.backtrace
+          }
+        }
+      }
+    end
+  end
+
+  {data: status}
+end
+
+# for debugging purposes
+if __FILE__ == $0
+  require_relative 'unit_test'
+  runtest('mail_jobs') # must agree with method name above
+end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].