monitor: move static files into a static directory (and removed external jquery)
[slapos.git] / stack / monitor / webfile-directory / status-history.cgi.in
1 #!{{ python_executable }}
2
3 import cgi
4 import datetime
5 import os
6 import sqlite3
7
8 db_path = '{{ monitor_db_path }}'
9
10 status_history_length = '{{ status_history_length }}'
11
12 db = sqlite3.connect(db_path)
13
14 print """<html><head>
15   <link rel="stylesheet" href="static/pure-min.css">
16   <link rel="stylesheet" href="static/style.css">
17   </head><body>
18   <h1>Monitor Status History :</h1>"""
19
20
21 def get_date_from_timestamp(timestamp):
22   return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
23
24 def print_individual_status(timestamp):
25   print "<div><h3>Failure on %s</h3><ul>" % get_date_from_timestamp(timestamp)
26   rows = db.execute("select status, element, output from individual_status where timestamp=?", (timestamp,))
27   for row in rows:
28     status, element, output = row
29     print "<li>%s , %s :</br><pre>%s</pre></li>" % (status, cgi.escape(element), cgi.escape(output))
30   print "</ul></div>"
31
32
33
34 if not os.path.exists(db_path):
35   print """No status history found</p></body></html>"""
36   exit(0)
37
38 failure_row_list = db.execute("select timestamp from status where status='FAILURE' order by timestamp desc limit ?", status_history_length )
39
40 for failure_row in failure_row_list:
41   timestamp, = failure_row
42   print_individual_status(timestamp)
43
44 print "</body></html>"