6 print "Content-Type: text/html\r\n"
9 from monitor.model import *
10 from monitor import database
11 from HyperText.HTML import A, BR, IMG, TABLE, TR, TH, TD, EM, quote_body, CENTER
12 from HyperText.Documents import Document
14 form = cgi.FieldStorage()
21 border-width: 0 0 1px 1px;
26 border-width: 1px 1px 1px 1px;
33 border-width: 1px 1px 0 0;
42 indexes = path.split("/")
46 values = values[index]
51 def diff_time(timestamp, abstime=True):
57 diff = now - timestamp
60 # return the number of seconds as a difference from current time.
62 if diff < 60: # sec in min.
64 t_str = "%s sec ago" % int(math.ceil(t))
65 elif diff < 60*60: # sec in hour
67 t_str = "%s min ago" % int(math.ceil(t))
68 elif diff < 60*60*24: # sec in day
70 t_str = "%s hrs ago" % int(math.ceil(t))
71 elif diff < 60*60*24*14: # sec in week
73 t_str = "%s days ago" % int(math.ceil(t))
74 elif diff <= 60*60*24*30: # approx sec in month
75 t = diff / (60*60*24*7)
76 t_str = "%s weeks ago" % int(math.ceil(t))
77 elif diff > 60*60*24*30: # approx sec in month
78 t = diff / (60*60*24*30)
79 t_str = "%s months ago" % int(t)
85 retvalue = form.getvalue(val)
91 def state_to_color(state):
94 elif state == "DEBUG":
103 if form.has_key('loginbase'):
104 loginbase = form.getvalue('loginbase')
105 loginbase = loginbase.rstrip("_")
107 loginbase = "undefined"
109 fb = database.dbLoad("findbad")
110 lb2hn = database.dbLoad("plcdb_lb2hn")
111 # todo: pull from HistoryNodeRecord table instead
112 #pf = database.dbLoad("node_persistflags")
115 t = TABLE(border="0", cellspacing="0", cellpadding="0")
118 if loginbase not in lb2hn:
119 value = ("""Select 'Edit settings' to enter your Site's loginbase.<br><br>
120 The loginbase is the unchangable portion of your slicename.
121 For instance, your slice follows the pattern loginbase_slicename.<br><br>
122 If this hint is unclear, then you can find your loginbase by visiting 'My Site' at <a target=_blank href=http://www.planet-lab.org>'PlanetLab.org'</a>""", "")
126 for value in ['Hostname', 'Since']:
129 nodes = lb2hn[loginbase]
130 hostnames = [ n['hostname'] for n in nodes ]
133 for host in hostnames:
135 color = state_to_color(fb['nodes'][host]['values']['state'])
136 url = 'http://www.planet-lab.org/db/nodes/index.php?nodepattern=%s' % host
137 td = TD(A(host, target='_blank', href=url), bgcolor=color)
139 #lc = pf[host].last_changed
141 td = TD(diff_time(lc))
148 if __name__ == "__main__":