+ except:
+ print traceback.print_exc()
+ sys.exit(1)
+
+ return values
+
+ def collectPLC(self, nodename, cohash):
+ values = {}
+ ### GET PLC NODE ######################
+ d_node = plccache.GetNodeByName(nodename)
+ values['plc_node_stats'] = d_node
+
+ ### GET PLC PCU ######################
+ site_id = -1
+ d_pcu = None
+ if d_node and len(d_node['pcu_ids']) > 0:
+ d_pcu = d_node['pcu_ids'][0]
+
+ site_id = d_node['site_id']
+
+ values['plc_pcuid'] = d_pcu
+
+ ### GET PLC SITE ######################
+ print "SITEID: %s" % site_id
+ d_site = plccache.GetSitesById([ site_id ])[0]
+ values['loginbase'] = d_site['login_base']
+ values['plc_site_stats'] = d_site
+
+ return values
+
+ def evaluate(self, nodename, values):
+ # TODO: this section can probably be reduced to a policy statement
+ # using patterns and values collected so far.
+ # NOTE: A node is "DOWN" if
+ # * cannot ssh into it.
+ # * all ports are not open for a 'BOOT' node
+ # * dns for hostname does not exist.
+ b_getbootcd_id = True
+
+ oval = values['kernel_version']
+ values['ssh_status'] = True
+ if "2.6.17" in oval or "2.6.2" in oval:
+ values['observed_category'] = 'PROD'
+ if "bm.log" in values['bmlog'] or "BootManager" in values['bmlog']:
+ values['observed_status'] = 'DEBUG'
+ else:
+ values['observed_status'] = 'BOOT'
+ elif "2.6.12" in oval or "2.6.10" in oval:
+ values['observed_category'] = 'OLDPROD'
+ if "bm.log" in values['bmlog']:
+ values['observed_status'] = 'DEBUG'
+ else:
+ values['observed_status'] = 'BOOT'
+
+ # NOTE: on 2.6.8 kernels, with 4.2 bootstrapfs, the chroot
+ # command fails. I have no idea why.
+ elif "2.4" in oval or "2.6.8" in oval:
+ b_getbootcd_id = False
+ values['observed_category'] = 'OLDBOOTCD'
+ values['observed_status'] = 'DEBUG'
+ elif oval != "":
+ values['observed_category'] = 'UNKNOWN'
+ if "bm.log" in values['bmlog']:
+ values['observed_status'] = 'DEBUG'
+ else:
+ values['observed_status'] = 'BOOT'
+ else:
+ # An error occurred.
+ b_getbootcd_id = False
+ values['ssh_status'] = False
+ values['observed_category'] = 'ERROR'
+ values['observed_status'] = 'DOWN'
+ values['kernel_version'] = ""
+
+ values['firewall'] = False
+
+ #print "BEFORE:%s" % values
+ # NOTE: A node is down if some of the public ports are not open
+ if values['observed_status'] == "BOOT":
+ # verify that all ports are open. Else, report node as down.
+ if not ( values['port_status']['22'] == "open" and \
+ values['port_status']['80'] == "open" and \
+ values['port_status']['806'] == "open") :
+ #email_exception(nodename, "%s FILTERED HOST" % nodename)
+ values['observed_status'] = 'DOWN'
+ values['firewall'] = True
+
+ #if values['port_status']['22'] == "open" and \
+ # values['port_status']['80'] == "closed" and \
+ # values['port_status']['806'] == "open" :
+ # email_exception("%s port 80 blocked" % nodename, "possible VSERVER ref blocked")
+
+ #if not values['external_dns_status']:
+ # email_exception("%s DNS down" % nodename)
+
+ if b_getbootcd_id:
+ # try to get BootCD for all nodes that are not 2.4 nor inaccessible
+ oval = values['bootcd_version']
+ if "BootCD" in oval:
+ values['bootcd_version'] = oval
+ if "v2" in oval and \
+ ( nodename is not "planetlab1.cs.unc.edu" and \
+ nodename is not "planetlab2.cs.unc.edu" ):
+ values['observed_category'] = 'OLDBOOTCD'
+ else:
+ values['bootcd_version'] = ""
+ else:
+ values['bootcd_version'] = ""
+
+ return values
+
+ def collectDNS(self, nodename, cohash):
+ values = {}
+ try:
+ ipaddr = socket.gethostbyname(nodename)
+ # TODO: check that IP returned matches IP in plc db.
+ values['external_dns_status'] = True
+ except Exception, err:
+ values['external_dns_status'] = False
+
+ return values
+
+ def collectInternal(self, nodename, cohash):
+ try:
+ values = {}
+
+ v = self.collectPING(nodename, cohash)
+ values.update(v)
+
+ v = self.collectPorts(nodename)
+ values.update(v)
+
+ v = self.collectSSH(nodename, cohash)
+ values.update(v)
+
+ v = self.collectDNS(nodename, cohash)
+ values.update(v)
+
+ v = self.collectTRACEROUTE(nodename, cohash)
+ values.update(v)
+
+ v = self.collectPLC(nodename, cohash)
+ values.update(v)