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')
69 vals['plcnode/last_contact'] = None
70 vals['comonstats/uptime'] = None
71 vals['princeton_comon'] = get_value('princeton_comon')
72 vals['princeton_comon_running'] = get_value('princeton_comon_running')
73 vals['princeton_comon_procs'] = get_value('princeton_comon_procs')
77 fb = database.dbLoad("findbad")
80 for mynode in fb['nodes'].keys():
81 fbnode = fb['nodes'][mynode]['values']
85 for key in ['ssh', 'state', 'plcnode/last_contact', 'nm', 'princeton_comon', 'princeton_comon_running', 'princeton_comon_procs', 'comonstats/uptime']:
86 if get(fbnode, key) is None:
89 if vals[key] is not None and vals[key] in get(fbnode, key):
91 elif vals[key] is None:
96 if 'last_contact' in key:
99 diff = ((t - lc) // (60*60*6)) * 6
100 row.append(-int(diff))
102 row.append(get(fbnode,key))
104 packed_values.append(row)
109 for i in range(1,len(x)):
110 if x[i] == y[i]: continue
111 if x[i] < y[i]: return -1
112 if x[i] > y[i]: return 1
115 packed_values.sort(rowcmp)
119 for value in ['num', 'host', 'ssh', 'state', 'last<br>contact', 'NM', 'comon<br>dir', 'comon<br>vserver', 'comon<br>procs']:
124 for row in packed_values:
133 #r.append(TD(node_count))