6 def recent(q, val, length):
7 return [val] + q[:length-1]
12 d[path] = recent(d[path], v, 6)
28 recent_node_states = {}
31 print "ts,host,status,pcustatus,model,length"
34 line = sys.stdin.readline()
38 # NOTE assumes ts are ordered.
40 (ts, host, state, pcu, pcumodel) = line.split(',')
42 print >>sys.stderr, "EXCEPTION:", line
44 line = sys.stdin.readline()
54 add(recent_node_states, host, state)
55 add(recent_node_ts, host, ts)
57 if host not in last_node_state:
58 last_node_state[host] = "UNKNOWN"
59 last_node_ts[host] = ts
61 if ( (in_hard_state(recent_node_states[host]) and stateof(recent_node_states[host]) == "DOWN") or \
62 not in_hard_state(recent_node_states[host]) ) and \
63 last_node_state[host] != stateof(recent_node_states[host]):
65 if stateof(recent_node_states[host]) == "DOWN":
66 ts = recent_node_ts[host][-1] # get earliest time down
67 print "%s,%s,%s,%s,%s,%s" % (ts, host, stateof(recent_node_states[host]), pcu, pcumodel, ts-last_node_ts[host] )
68 last_node_state[host] = stateof(recent_node_states[host])
69 last_node_ts[host] = ts