def get_tinc_block(log_file): """ returns an iterateable block from the given log file (syslog) This function became obsolete with the introduction of tincctl """ from BackwardsReader import BackwardsReader tinc_block = [] in_block = False bf = BackwardsReader(log_file) BOL = re.compile(".*tinc.%s\[[0-9]+\]: " % TINC_NETWORK) while True: line = bf.readline() if not line: raise Exception("end of file at log file? This should not happen!") line = BOL.sub('',line).strip() if END_SUBNET in line: in_block = True if not in_block: continue tinc_block.append(line) if BEGIN_NODES in line: break return reversed(tinc_block)
def get_tinc_block(log_file): """ returns an iterateable block from the given log file (syslog) This function became obsolete with the introduction of tincctl """ from BackwardsReader import BackwardsReader tinc_block = [] in_block = False bf = BackwardsReader(log_file) BOL = re.compile(".*tinc.%s\[[0-9]+\]: " % TINC_NETWORK) while True: line = bf.readline() if not line: raise Exception("end of file at log file? This should not happen!") line = BOL.sub('', line).strip() if END_SUBNET in line: in_block = True if not in_block: continue tinc_block.append(line) if BEGIN_NODES in line: break return reversed(tinc_block)
def generate_stats(nodes): """ Generates some statistics of the network and nodes """ jlines = [] try: f = BackwardsReader(DUMP_FILE) lines_to_use = 1000 while True: if lines_to_use == 0: break line = f.readline() if not line: break jline = json.loads(line) if not jline['nodes']: continue jlines.append(jline) lines_to_use -=1 except Exception,e: sys.stderr.write(str(e))
def generate_availability_stats(nodes): """ generates stats of from availability """ jlines = [] try: f = BackwardsReader(DUMP_FILE) lines_to_use = 1000 while True: if lines_to_use == 0: break line = f.readline() if not line: break jline = json.loads(line) if not jline['nodes']: continue jlines.append(jline) lines_to_use -=1 except Exception,e: sys.stderr.write(str(e)) for k,v in nodes.iteritems(): v['availability'] = get_node_availability(k,jlines) sys.stderr.write( "%s -> %f\n" %(k ,v['availability']))
def generate_availability_stats(nodes): """ generates stats of from availability """ jlines = [] try: f = BackwardsReader(DUMP_FILE) lines_to_use = 1000 while True: if lines_to_use == 0: break line = f.readline() if not line: break jline = json.loads(line) if not jline["nodes"]: continue jlines.append(jline) lines_to_use -= 1 except Exception, e: sys.stderr.write(str(e))
def get_tinc_block(log_file): """ returns an iterateable block from the given log file (syslog) """ tinc_block = [] in_block = False bf = BackwardsReader(log_file) BOL = re.compile(".*tinc.retiolum\[[0-9]+\]: ") while True: line = bf.readline() if not line: raise Exception("end of file at log file? This should not happen!") line = BOL.sub("", line).strip() if END_SUBNET in line: in_block = True if not in_block: continue tinc_block.append(line) if BEGIN_NODES in line: break return reversed(tinc_block)