Commit c8fed9c8d0be2ee5c24303ca6d79e2a11eb9bfe2:
localize times
Branch: refs/heads/master
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>
------------------------------------------------------------
www/status/README.md | ++++
www/status/js/status.js | +++++++++++
www/status/monitor.rb | ++++++++ ---
www/status/monitors/board_minutes.rb | + -
www/status/monitors/public_json.rb | + -
www/status/monitors/secmail.rb | + -
------------------------------------------------------------
32 changes: 26 additions, 6 deletions.
------------------------------------------------------------
diff --git a/www/status/README.md b/www/status/README.md
index a24d6e7..c37e42d 100644
--- a/www/status/README.md
+++ b/www/status/README.md
@@ -69,6 +69,10 @@ Anchors and the top of each major branch emanating from the
root have an
*mtime* value which indicates when that data was last updated. This is
described below in the control flow section below.
+Leaf nodes can have a mtime value in place of data. Such values will be
+converted to local time and displayed as the last update value. Hovering over
+such items will show the GMT value of the time specified in ISO-8601 format.
+
Control Flow
============
diff --git a/www/status/js/status.js b/www/status/js/status.js
index c0d5c77..2abb1bf 100644
--- a/www/status/js/status.js
+++ b/www/status/js/status.js
@@ -25,6 +25,12 @@ $(function() {
var div = $('<div>').addClass('list-group').addClass('collapse').
attr('id', prefix + item);
+ // default data to mtime, if present
+ if (!value.data && value.mtime) {
+ value.data = "Last updated " +
+ new Date(Date.parse(value.mtime)).toLocaleString()
+ }
+
// build nested content (recursively if value.data is an object)
if (!value.data) {
div.append($('<a>').addClass('list-group-item').
@@ -46,6 +52,11 @@ $(function() {
div.children('a:not(.data-toggle)').attr('href', value.href);
}
+ // provide ISO-8601 formatted GMT time as a tooltip
+ if (value.mtime) {
+ div.children('a:not(.data-toggle)').attr('title', value.mtime);
+ }
+
// append each to the container
container.append(anchor);
container.append(div);
diff --git a/www/status/monitor.rb b/www/status/monitor.rb
index f58fb21..781d997 100644
--- a/www/status/monitor.rb
+++ b/www/status/monitor.rb
@@ -37,7 +37,7 @@ def initialize(args = [])
# invoke method to determine current status
begin
- previous = baseline[method] || {mtime: Time.at(0).gmtime.iso8601}
+ previous = baseline[method] || {mtime: Time.at(0)}
status = Monitor.send(method, previous) || previous
# convert non-hashes in proper statuses
@@ -62,7 +62,7 @@ def initialize(args = [])
end
# default mtime to now
- status['mtime'] ||= Time.now.gmtime.iso8601 if status.instance_of? Hash
+ status['mtime'] ||= Time.now if status.instance_of? Hash
# update baseline
newstatus[method] = status
@@ -104,12 +104,17 @@ def normalize(status)
if status['data'].instance_of? Hash
# recursively normalize the data structure
status['data'].values.each {|value| normalize(value)}
- elsif not status['data']
+ elsif not status['data'] and not status['mtime']
# default data
status['data'] = 'missing'
status['level'] ||= 'danger'
end
+ # normalize time
+ if status['mtime'].instance_of? Time
+ status['mtime'] = status['mtime'].gmtime.iso8601
+ end
+
# normalize level (filling in title when this occurs)
if status['level']
if not LEVELS.include? status['level']
diff --git a/www/status/monitors/board_minutes.rb
b/www/status/monitors/board_minutes.rb
index a6781c9..9289ca4 100644
--- a/www/status/monitors/board_minutes.rb
+++ b/www/status/monitors/board_minutes.rb
@@ -19,6 +19,6 @@ def Monitor.board_minutes(previous_status)
href: '../logs/collate_minutes'
}
else
- "Last updated: #{File.mtime(index)}"
+ {mtime: File.mtime(index)}
end
end
diff --git a/www/status/monitors/public_json.rb
b/www/status/monitors/public_json.rb
index 90466fb..3e65185 100644
--- a/www/status/monitors/public_json.rb
+++ b/www/status/monitors/public_json.rb
@@ -11,7 +11,7 @@ def Monitor.public_json(previous_status)
name = File.basename(log).sub('public-', '')
if File.size(log) == 0
- status[name] = {data: "Last updated #{File.mtime(log)}"}
+ status[name] = {mtime: File.mtime(log)}
else
status[name] = {level: 'danger', data: File.readlines(log)}
end
diff --git a/www/status/monitors/secmail.rb b/www/status/monitors/secmail.rb
index 587c07c..e465e5e 100644
--- a/www/status/monitors/secmail.rb
+++ b/www/status/monitors/secmail.rb
@@ -5,5 +5,5 @@
def Monitor.secmail(previous_status)
log = '/srv/mail/procmail.log'
- "Last updated: #{File.mtime(log)}"
+ {mtime: File.mtime(log)}
end