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 pf = database.dbLoad("node_persistflags")
114 t = TABLE(border="0", cellspacing="0", cellpadding="0")
117 if loginbase not in lb2hn:
118 value = ("""Select 'Edit settings' to enter your Site's loginbase.<br><br>
119 The loginbase is the unchangable portion of your slicename.
120 For instance, your slice follows the pattern loginbase_slicename.<br><br>
121 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>""", "")
125 for value in ['Hostname', 'Since']:
128 nodes = lb2hn[loginbase]
129 hostnames = [ n['hostname'] for n in nodes ]
132 for host in hostnames:
134 color = state_to_color(fb['nodes'][host]['values']['state'])
135 url = 'http://www.planet-lab.org/db/nodes/index.php?nodepattern=%s' % host
136 td = TD(A(host, target='_blank', href=url), bgcolor=color)
138 lc = pf[host].last_changed
139 td = TD(diff_time(lc))
146 if __name__ == "__main__":