whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [2/2] Commit 52094b4: Merge branch 'master' of github.com:apache/whimsy
Date Mon, 18 Jan 2016 19:20:22 GMT
Commit 52094b45ce474e23e939bc5bd492ed67d6d4a65b:
    Merge branch 'master' of github.com:apache/whimsy


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/status/errors.cgi                                        | +++++++++++++++ 
www/status/index.cgi                                         | + -
www/status/monitors/svn.rb                                   | ++++++++ -----
------------------------------------------------------------
73 changes: 67 additions, 6 deletions.
------------------------------------------------------------


diff --git a/www/status/errors.cgi b/www/status/errors.cgi
new file mode 100755
index 0000000..f98b3f1
--- /dev/null
+++ b/www/status/errors.cgi
@@ -0,0 +1,58 @@
+#!/usr/bin/ruby
+
+#
+# Fetch and parse the Ping My Box error log
+#
+
+require 'wunderbar'
+require 'uri'
+require 'yaml'
+require 'net/http'
+require 'time'
+
+# fetch status
+uri = URI.parse('https://www.pingmybox.com/api.pmb?what=errors&id=470')
+http = Net::HTTP.new(uri.host, uri.port)
+http.use_ssl = true
+request = Net::HTTP::Get.new(uri.request_uri)
+response = http.request(request)
+
+# extract time, pinger, and exception from response
+exceptions = YAML.load(response.body).map do |hash| 
+  exception = hash['debug'][/Caught exception: .*?: (.*)/m, 1].strip
+  [Time.at(hash['time']), hash['pinger'], exception]
+end
+
+# produce table
+_html do
+  _link rel: 'stylesheet', href: 'css/bootstrap.min.css'
+  _h1 'Error Log'
+
+  _table.table do
+    _tr_ do
+      _th 'Time'
+      _th 'Pinger'
+      _th 'Status'
+      _th 'Error'
+    end
+
+    exceptions.sort.reverse.each do |time, pinger, text|
+      color = (text.include?('HTTP/1.1 3') ? 'warning' : 'danger')
+      _tr_ class: color do
+        _td time.iso8601
+        _td align: 'right' do
+          _a pinger, href:
+            "https://www.pingmybox.com/pings?location=470&pinger=#{pinger}"
+        end
+        _td text[/^HTTP\/1.1 (\d+)/, 1] 
+        _td text.sub(/^HTTP\/1.1 \d+/, '')
+      end
+    end
+  end
+
+  _p do
+    _a 'raw log', href: uri.to_s
+  end
+end
+
+
diff --git a/www/status/index.cgi b/www/status/index.cgi
index d7a5e50..b632d88 100755
--- a/www/status/index.cgi
+++ b/www/status/index.cgi
@@ -54,7 +54,7 @@ print <<-EOF
     <p>
       This status is monitored by:
       <a href="https://www.pingmybox.com/dashboard?location=470">Ping My
-      Box</a>.
+      Box</a> (<a href="errors">full log</a>).
     </p>
   </body>
 </html>
diff --git a/www/status/monitors/svn.rb b/www/status/monitors/svn.rb
index c39a805..ab07aeb 100644
--- a/www/status/monitors/svn.rb
+++ b/www/status/monitors/svn.rb
@@ -4,9 +4,9 @@
 
 def Monitor.svn(previous_status)
   # read cron log
-  log = File.expand_path('../../www/logs/svn-update')
-  updates = File.read(log).split("\n/srv/svn/")
-  updates.shift
+  log = File.expand_path('../../../logs/svn-update', __FILE__)
+  data = File.open(log) {|file| file.flock(File::LOCK_EX); file.read}
+  updates = data.split("\n/srv/svn/")[1..-1]
 
   status = {}
 
@@ -30,7 +30,10 @@ def Monitor.svn(previous_status)
     lines.reject! {|line| line =~ /^[ADU]    /}
 
     if lines.empty?
-      if data.length == 1
+      if not data
+        title = "partial response"
+        level = 'warning'
+      elsif data.length == 1
         title = "1 file updated"
       else
         title = "#{data.length} files updated"
@@ -42,7 +45,7 @@ def Monitor.svn(previous_status)
       data = lines.dup
     end
 
-    status[repository] = {level: level, data: data}
+    status[repository] = {level: level, data: data, href: '../logs/svn-update'}
     status[repository][:title] = title if title
   end
 

Mime
View raw message