Commit f261dd76d4a86cbb0d7252d19bc9080e4bff7d52:
format error log
Branch: refs/heads/master
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>
------------------------------------------------------------
www/status/errors.cgi | +++++++++++++++
www/status/index.cgi | + -
------------------------------------------------------------
60 changes: 59 additions, 1 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>