X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=comon.py;h=8d96e1697665920b38ffc1ea79405e1192113b1a;hb=refs%2Fheads%2F1.0;hp=58e49e70d75fbcea21087ef20498c1c0b26273d4;hpb=34a4c8387ad2e397f46a03d9476096f1cd5abfc6;p=monitor.git diff --git a/comon.py b/comon.py index 58e49e7..8d96e16 100755 --- a/comon.py +++ b/comon.py @@ -3,7 +3,7 @@ # # Faiyaz Ahmed # -# $Id: comon.py,v 1.5 2007/05/16 01:53:46 faiyaza Exp $ +# $Id: comon.py,v 1.7 2007/07/03 19:59:02 soltesz Exp $ # # Get CoMon data, unsorted, in CSV, and create a huge hash. # @@ -40,6 +40,40 @@ COMONURL = "http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_node # 3 == rins # 4 == ins +def _tohash(rawdata): + # First line Comon returns is list of keys with respect to index + try: + keys = rawdata.readline().rstrip().split(", ") + l_host = [] + hash = {} + i_ignored = 0 + for line in rawdata.readlines(): + l_host = line.rstrip().split(", ") # split the line on ', ' + hostname = l_host[0] + hash[hostname] = {} + for i in range(1,len(keys)): + hash[hostname][keys[i]]=l_host[i] + + except Exception, err: + logger.debug("No hosts retrieved") + return {} + return hash + +def comonget(url): + rawdata = None + print "Getting: %s" % url + try: + coserv = urllib2.Request(url) + coserv.add_header('User-Agent', 'PL_Monitor +http://monitor.planet-lab.org/') + opener = urllib2.build_opener() + # Initial web get from summer.cs in CSV + rawdata = opener.open(coserv) + except urllib2.URLError, (err): + print "Attempting %s" %COMONURL + print "URL error (%s)" % (err) + rawdata = None + return _tohash(rawdata) + class Comon(Thread): """ @@ -47,7 +81,15 @@ class Comon(Thread): all buckets is a queue of all problem nodes. This gets sent to rt to find tickets open for host. """ - def __init__(self, cdb, d_allplc_nodes, q_allbuckets): + def __init__(self, cdb=None, d_allplc_nodes=None, q_allbuckets=None): + + self.accept_all_nodes = False + + if cdb == None: + cdb = {} + if d_allplc_nodes == None: + self.accept_all_nodes = True # TODO :get from plc. + self.codata = cdb self.d_allplc_nodes = d_allplc_nodes self.updated = time.time() @@ -59,12 +101,13 @@ class Comon(Thread): # "filerw": "filerw%3E0", # "dbg" : "keyok==0"} self.comon_buckets = { - #"down" : "resptime==0 && keyok==null", + #"down" : "resptime==0&&keyok==null", #"ssh": "sshstatus > 2h", #"clock_drift": "drift > 1m", #"dns": "dns1udp>80 && dns2udp>80", #"filerw": "filerw > 0", - "dbg" : "keyok==0" + #"all" : "" + "dbg" : "keyok==0", } Thread.__init__(self) @@ -78,7 +121,14 @@ class Comon(Thread): for line in rawdata.readlines(): l_host = line.rstrip().split(", ") # split the line on ', ' hostname = l_host[0] - if hostname in self.d_allplc_nodes: # then we'll track it + add = False + if self.accept_all_nodes: + add=True + else: + if hostname in self.d_allplc_nodes: # then we'll track it + add = True + + if add: hash[hostname] = {} for i in range(1,len(keys)): hash[hostname][keys[i]]=l_host[i] @@ -149,6 +199,7 @@ class Comon(Thread): diag_node['message'] = None diag_node['bucket'] = [bucket] diag_node['stage'] = "" + #diag_node['ticket_id'] = "" diag_node['args'] = None diag_node['info'] = None diag_node['time'] = time.time() @@ -194,12 +245,6 @@ def main(): print("%-40s \t Bootstate %s nodetype %s kernver %s keyok %s" % ( host, cdb[host]['bootstate'], cdb[host]['nodetype'], cdb[host]['kernver'], cdb[host]['keyok'])) - #ssh = soltesz.SSH('root', host) - #try: - # val = ssh.run("uname -r") - # print "%s == %s" % (host, val), - #except: - # pass # else: # print("key mismatch at: %s" % host) #print a.codata['michelangelo.ani.univie.ac.at']