4 esc = struct.pack('i', 27)
7 YELLOW = esc + "[1;33m"
9 NORMAL = esc + "[0;39m"
12 return RED + str + NORMAL
15 return YELLOW + str + NORMAL
18 return GREEN + str + NORMAL
21 return BLUE + str + NORMAL
23 def get_current_state(fbnode):
25 state = fbnode['state']
29 if l == "debug": l = 'dbg '
32 def color_pcu_state(fbnode):
35 if 'plcnode' in fbnode and 'pcu_ids' in fbnode['plcnode'] and len(fbnode['plcnode']['pcu_ids']) > 0 :
36 values = reboot.get_pcu_values(fbnode['plcnode']['pcu_ids'][0])
42 if 'reboot' in values:
44 if rb == 0 or rb == "0":
45 return fbnode['pcu'] + "OK "
46 #return green(fbnode['pcu'])
47 elif "NetDown" == rb or "Not_Run" == rb:
48 return fbnode['pcu'] + "DOWN"
49 #return yellow(fbnode['pcu'])
51 return fbnode['pcu'] + "BAD "
52 #return red(fbnode['pcu'])
54 #return red(fbnode['pcu'])
55 return fbnode['pcu'] + "BAD "
57 def color_boot_state(l):
58 if l == "dbg": return yellow("dbg ")
59 elif l == "dbg ": return yellow(l)
60 elif l == "down": return red(l)
61 elif l == "boot": return green(l)
62 elif l == "rins": return blue(l)
66 def diff_time(timestamp):
70 diff = now - timestamp
71 # return the number of seconds as a difference from current time.
73 if diff < 60: # sec in min.
75 t_str = "%s sec ago" % t
76 elif diff < 60*60: # sec in hour
78 t_str = "%s min ago" % int(t)
79 elif diff < 60*60*24: # sec in day
81 t_str = "%s hrs ago" % int(t)
82 elif diff < 60*60*24*7: # sec in week
83 t = diff // (60*60*24)
84 t_str = "%s days ago" % int(t)
85 elif diff < 60*60*24*30: # approx sec in month
86 t = diff // (60*60*24*7)
87 t_str = "%s wks ago" % int(t)
88 elif diff > 60*60*24*30: # approx sec in month
89 t = diff // (60*60*24*7*30)
90 t_str = "%s mnths ago" % int(t)
93 def nodegroup_display(node, fb):
94 if node['hostname'] in fb['nodes']:
95 node['current'] = get_current_state(fb['nodes'][node['hostname']]['values'])
97 node['current'] = 'none'
99 if fb['nodes'][node['hostname']]['values'] == []:
102 s = fb['nodes'][node['hostname']]['values']['kernel'].split()
104 node['kernel'] = s[2]
106 node['kernel'] = fb['nodes'][node['hostname']]['values']['kernel']
108 if '2.6' not in node['kernel']: node['kernel'] = ""
109 node['boot_state'] = color_boot_state(node['boot_state'])
110 node['current'] = color_boot_state(node['current'])
111 #node['boot_state'] = node['boot_state']
112 #node['current'] = node['current']
113 node['pcu'] = fb['nodes'][node['hostname']]['values']['pcu']
114 node['lastupdate'] = diff_time(node['last_contact'])
116 return "%(hostname)-38s %(boot_state)5s %(current)5s %(pcu)6s %(key)45s %(kernel)32s %(lastupdate)12s " % node
121 def node_end_record(node):
122 act_all = soltesz.dbLoad("act_all")
123 if node not in act_all:
127 if len(act_all[node]) == 0:
131 a = Action(node, act_all[node][0])
133 a.delField('found_rt_ticket')
134 a.delField('second-mail-at-oneweek')
135 a.delField('second-mail-at-twoweeks')
136 a.delField('first-found')
138 rec['action'] = ["close_rt"]
139 rec['category'] = "UNKNOWN"
140 rec['stage'] = "monitor-end-record"
141 rec['time'] = time.time() - 7*60*60*24
142 act_all[node].insert(0,rec)
143 soltesz.dbDump("act_all", act_all)