5 from monitor import database
9 from HyperText.HTML import A, BR, IMG, TABLE, TR, TH, TD, EM, quote_body
10 from HyperText.Documents import Document
11 print "Content-Type: text/html\r\n"
13 form = cgi.FieldStorage()
16 indexes = path.split("/")
20 values = values[index]
25 def diff_time(timestamp, abstime=True):
31 diff = now - timestamp
34 # return the number of seconds as a difference from current time.
36 if diff < 60: # sec in min.
38 t_str = "%s sec ago" % int(math.ceil(t))
39 elif diff < 60*60: # sec in hour
41 t_str = "%s min ago" % int(math.ceil(t))
42 elif diff < 60*60*24: # sec in day
44 t_str = "%s hrs ago" % int(math.ceil(t))
45 elif diff < 60*60*24*14: # sec in week
47 t_str = "%s days ago" % int(math.ceil(t))
48 elif diff <= 60*60*24*30: # approx sec in month
49 t = diff / (60*60*24*7)
50 t_str = "%s wks ago" % int(math.ceil(t))
51 elif diff > 60*60*24*30: # approx sec in month
52 t = diff / (60*60*24*30)
53 t_str = "%s mnths ago" % int(t)
59 retvalue = form.getvalue(val)
66 vals['ssh'] = get_value('ssh')
67 vals['state'] = get_value('state')
68 vals['nm'] = get_value('nm')
70 vals['readonlyfs'] = None
71 vals['plcnode/last_contact'] = None
72 vals['comonstats/uptime'] = None
73 vals['princeton_comon'] = get_value('princeton_comon')
74 vals['princeton_comon_running'] = get_value('princeton_comon_running')
75 vals['princeton_comon_procs'] = get_value('princeton_comon_procs')
79 fb = database.dbLoad("findbad")
82 for mynode in fb['nodes'].keys():
83 fbnode = fb['nodes'][mynode]['values']
87 if 'readonlyfs' in fbnode:
88 if 'Read-only file system' in fbnode['readonlyfs']:
89 fbnode['readonlyfs'] = 'Y'
91 fbnode['readonlyfs'] = '_'
94 if 'boot.planet-lab.org has address' in fbnode['dns']:
99 for key in ['ssh', 'state', 'plcnode/last_contact', 'readonlyfs', 'dns', 'nm', 'princeton_comon', 'princeton_comon_running', 'princeton_comon_procs', 'comonstats/uptime']:
100 if get(fbnode, key) is None:
103 if vals[key] is not None and vals[key] in get(fbnode, key):
105 elif vals[key] is None:
110 if 'last_contact' in key:
113 diff = ((t - lc) // (60*60*6)) * 6
114 row.append(-int(diff))
116 row.append(get(fbnode,key))
118 packed_values.append(row)
123 for i in range(1,len(x)):
124 if x[i] == y[i]: continue
125 if x[i] < y[i]: return -1
126 if x[i] > y[i]: return 1
129 packed_values.sort(rowcmp)
133 for value in ['num', 'host', 'ssh', 'state', 'last<br>contact', 'readonlyfs', 'dns', 'NM', 'comon<br>dir', 'comon<br>vserver', 'comon<br>procs']:
138 for row in packed_values:
147 #r.append(TD(node_count))