5 api = plc.PLC(auth.auth, auth.plc)
8 fb = soltesz.dbLoad("findbad")
9 act_all = soltesz.dbLoad("act_all")
16 from config import config
17 from optparse import OptionParser
19 parser = OptionParser()
20 parser.set_defaults(node=None, endrecord=False)
21 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
22 help="A single node name to add to the nodegroup")
23 parser.add_option("", "--endrecord", dest="endrecord", action="store_true",
24 help="Force an end to the action record; to prompt Montior to start messaging again.")
25 config = config(parser)
28 def diff_time(timestamp):
30 diff = now - timestamp
31 # return the number of seconds as a difference from current time.
33 if diff < 60: # sec in min.
35 t_str = "%s sec ago" % t
36 elif diff < 60*60: # sec in hour
38 t_str = "%s min ago" % int(t)
39 elif diff < 60*60*24: # sec in day
41 t_str = "%s hours ago" % int(t)
42 elif diff < 60*60*24*7: # sec in week
43 t = diff // (60*60*24)
44 t_str = "%s days ago" % int(t)
45 elif diff < 60*60*24*30: # approx sec in month
46 t = diff // (60*60*24*7)
47 t_str = "%s weeks ago" % int(t)
48 elif diff > 60*60*24*30: # approx sec in month
49 t = diff // (60*60*24*7*30)
50 t_str = "%s months ago" % int(t)
53 def plc_print_nodeinfo(plcnode):
54 url = "https://www.planet-lab.org/db/nodes/index.php?nodepattern="
55 plcnode['url'] = url + plcnode['hostname']
57 print "%(hostname)s %(url)s" % plcnode
58 print " Checked: %s" % time.ctime()
60 print "\t boot_state | created | updated | last_contact"
61 print "\t %10.10s | %11.11s | %11.11s | %12s" % \
62 (plcnode['boot_state'], diff_time(plcnode['date_created']),
63 diff_time(plcnode['last_updated']),
64 diff_time(plcnode['last_contact']))
66 def fb_print_nodeinfo(fbnode):
68 if 'checked' in fbnode:
69 print "%11.11s " % diff_time(fbnode['checked'])
72 print "\t state | ssh | pcu | bootcd | category | kernel"
74 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
76 fbnode['bootcd'] = "unknown"
77 fbnode['kernel'] = fbnode['kernel'].split()[2]
78 print "\t %(state)10.10s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
80 def act_print_nodeinfo(actnode, header):
82 print " Created: %11.11s" % diff_time(actnode['date_created'])
83 print " LastTime %11.11s" % diff_time(actnode['time'])
84 print "\t RT | category | action | msg"
88 print "\t %5.5s %5.5s | %8.8s | %15.15s | %s" % \
89 (actnode['rt']['Status'], actnode['rt']['id'][7:],
90 actnode['category'], actnode['action'][0],
91 actnode['msg_format'][:-1])
93 if type(actnode['action']) == type([]):
94 action = actnode['action'][0]
96 action = actnode['action']
97 if 'category' in actnode:
98 category = actnode['category']
102 print "\t %5.5s | %8.8s | %15.15s | %s" % \
103 (actnode['ticket_id'],
105 actnode['msg_format'][:-1])
107 def pcu_print_info(pcuinfo, hostname):
109 if 'checked' in pcuinfo:
110 print "%11.11s " % diff_time(pcuinfo['checked'])
114 print "\t user | password | port | hostname "
115 print "\t %17s | %17s | %4s | %30s | %s" % \
116 (pcuinfo['username'], pcuinfo['password'],
117 pcuinfo[hostname], reboot.pcu_name(pcuinfo), pcuinfo['model'])
119 if pcuinfo['portstatus']['22'] == "open":
120 print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo))
121 if pcuinfo['portstatus']['23'] == "open":
122 print "\t telnet %s" % (reboot.pcu_name(pcuinfo))
123 if pcuinfo['portstatus']['80'] == "open" or \
124 pcuinfo['portstatus']['443'] == "open":
125 print "\t http://%s" % (reboot.pcu_name(pcuinfo))
126 if pcuinfo['portstatus']['443'] == "open":
127 print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password'])
128 print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p %s | grep MESSAGE" % \
129 (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
131 for node in config.args:
134 plc_nodeinfo = api.GetNodes({'hostname': config.node}, None)[0]
135 fb_nodeinfo = fb['nodes'][config.node]['values']
137 plc_print_nodeinfo(plc_nodeinfo)
138 fb_print_nodeinfo(fb_nodeinfo)
140 if fb_nodeinfo['pcu'] == "PCU":
141 pcu = reboot.get_pcu_values(fb_nodeinfo['plcnode']['pcu_ids'][0])
142 pcu_print_info(pcu, config.node)
144 if config.node in act_all and len(act_all[config.node]) > 0:
148 a = Action(config.node, act_all[config.node][0])
150 a.delField('second-mail-at-oneweek')
151 a.delField('second-mail-at-twoweeks')
152 a.delField('first-found')
154 rec['action'] = ["close_rt"]
155 rec['category'] = "UNKNOWN"
156 rec['stage'] = "monitor-end-record"
157 rec['time'] = time.time() - 7*60*60*24
158 act_all[config.node].insert(0,rec)
160 for act_nodeinfo in act_all[config.node]:
161 act_print_nodeinfo(act_nodeinfo, header)
162 else: act_nodeinfo = None