From b28bedc524b1a0f90a1b760ac29fb2d49d7970b3 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 24 Jun 2013 19:19:46 +0200 Subject: fix symlink --- retiolum/bin/nodes-to-json | 37 +++++ retiolum/bin/nodes-to-json.py | 37 ----- retiolum/bin/tinc2json | 1 + retiolum/bin/tinc_stats2json | 1 - retiolum/scripts/adv_graphgen/parse_tinc_anon.py | 93 ------------- retiolum/scripts/adv_graphgen/parse_tinc_stats.py | 157 ---------------------- 6 files changed, 38 insertions(+), 288 deletions(-) create mode 100644 retiolum/bin/nodes-to-json delete mode 100644 retiolum/bin/nodes-to-json.py create mode 120000 retiolum/bin/tinc2json delete mode 120000 retiolum/bin/tinc_stats2json delete mode 100755 retiolum/scripts/adv_graphgen/parse_tinc_anon.py delete mode 100755 retiolum/scripts/adv_graphgen/parse_tinc_stats.py diff --git a/retiolum/bin/nodes-to-json b/retiolum/bin/nodes-to-json new file mode 100644 index 00000000..ca9d3c8c --- /dev/null +++ b/retiolum/bin/nodes-to-json @@ -0,0 +1,37 @@ +#!/usr/bin/python + +def parse_hosts_path(path="/etc/tinc/retiolum/hosts"): + import os + import re + + needle_addr = re.compile("Subnet\s*=\s*(.*)/[0-9]+") + needle_port = re.compile("Port\s*=\s*(.*)") + for f in os.listdir(path): + with open(path+"/"+f) as of: + addrs = [] + port = "655" + + for line in of.readlines(): + + addr_found = needle_addr.match(line) + if addr_found: + addrs.append(addr_found.group(1)) + + port_found = needle_port.match(line) + if port_found: + port = port_found.group(1) + + if addrs : yield (f ,[(addr ,int(port)) for addr in addrs]) + + + +if __name__ == "__main__": + """ + usage + """ + import json + import sys + db={} + for host,addrs in parse_hosts_path(sys.argv[1] if len(sys.argv) > 2 else "/etc/tinc/retiolum/hosts"): + db[host] = addrs + print(json.dumps(db)) diff --git a/retiolum/bin/nodes-to-json.py b/retiolum/bin/nodes-to-json.py deleted file mode 100644 index ca9d3c8c..00000000 --- a/retiolum/bin/nodes-to-json.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -def parse_hosts_path(path="/etc/tinc/retiolum/hosts"): - import os - import re - - needle_addr = re.compile("Subnet\s*=\s*(.*)/[0-9]+") - needle_port = re.compile("Port\s*=\s*(.*)") - for f in os.listdir(path): - with open(path+"/"+f) as of: - addrs = [] - port = "655" - - for line in of.readlines(): - - addr_found = needle_addr.match(line) - if addr_found: - addrs.append(addr_found.group(1)) - - port_found = needle_port.match(line) - if port_found: - port = port_found.group(1) - - if addrs : yield (f ,[(addr ,int(port)) for addr in addrs]) - - - -if __name__ == "__main__": - """ - usage - """ - import json - import sys - db={} - for host,addrs in parse_hosts_path(sys.argv[1] if len(sys.argv) > 2 else "/etc/tinc/retiolum/hosts"): - db[host] = addrs - print(json.dumps(db)) diff --git a/retiolum/bin/tinc2json b/retiolum/bin/tinc2json new file mode 120000 index 00000000..31bd0775 --- /dev/null +++ b/retiolum/bin/tinc2json @@ -0,0 +1 @@ +../scripts/adv_graphgen/tinc_stats/Log2JSON.py \ No newline at end of file diff --git a/retiolum/bin/tinc_stats2json b/retiolum/bin/tinc_stats2json deleted file mode 120000 index 413b778c..00000000 --- a/retiolum/bin/tinc_stats2json +++ /dev/null @@ -1 +0,0 @@ -../scripts/adv_graphgen/tinc_stats2json \ No newline at end of file diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_anon.py b/retiolum/scripts/adv_graphgen/parse_tinc_anon.py deleted file mode 100755 index 05b82828..00000000 --- a/retiolum/scripts/adv_graphgen/parse_tinc_anon.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf8 -*- -from tinc_stats.Graphite import GraphiteSender -from time import time - -try: - import os - gr = GraphiteSender(os.environ.get("GRAPHITE_HOST","localhost")) - begin = time() -except Exception as e: - sys.stderr.write( "Cannot connect to graphite: " + str(e)) - - -def write_digraph(nodes): - """ - writes the complete digraph in dot format - """ - print ('digraph retiolum {') - #print (' graph [center rankdir=LR packMode="clust"]') - print (' graph [center packMode="clust"]') - print (' node[shape=circle,style=filled,fillcolor=grey]') - print (' overlap=false') - generate_stats(nodes) - merge_edges(nodes) - nodes = anon_nodes(nodes) - for k,v in nodes.iteritems(): - write_node(k,v) - write_stat_node(nodes) - print ('}') - -def anon_nodes(nodes): - #anonymizes all nodes - i = "0" - newnodes = {} - for k,v in nodes.iteritems(): - for nodek,node in nodes.iteritems(): - for to in node['to']: - if to['name'] == k: - to['name'] = i - newnodes[i] = v - i = str(int(i)+1) - return newnodes - -def write_stat_node(nodes): - ''' Write a `stats` node in the corner - This node contains infos about the current number of active nodes and connections inside the network - ''' - from time import localtime,strftime - num_conns = 0 - num_nodes = len(nodes) - for k,v in nodes.iteritems(): - num_conns+= len(v['to']) - node_text = " stats_node [shape=box,label=\"Statistics\\l" - node_text += "Build Date : %s\\l" % strftime("%Y-%m-%d %H:%M:%S",localtime()) - node_text += "Active Nodes: %s\\l" % num_nodes - node_text += "Connections : %s\\l" % num_conns - node_text += "\"" - node_text += ",fillcolor=green" - node_text += "]" - print(node_text) - - - -def write_node(k,v): - """ writes a single node and its edges - edges are weightet with the informations inside the nodes provided by - tinc - """ - - node = " "+k #+"[label=\"" - print node - - for con in v.get('to',[]): - label = con['weight'] - w = int(con['weight']) - weight = str(1000 - (((w - 150) * (1000 - 0)) / (1000 -150 )) + 0) - - length = str(float(w)/1500) - if float(weight) < 0 : - weight= "1" - - edge = " "+k+ " -> " +con['name'] + " [label="+label + " weight="+weight - if con.get('bidirectional',False): - edge += ",dir=both" - edge += "]" - print edge - -if __name__ == "__main__": - nodes = delete_unused_nodes(json.load(sys.stdin)) - write_digraph(nodes) - try: - gr.send("graph.anon_build_time",(time()-begin)*1000) - except Exception as e: pass diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py deleted file mode 100755 index c23e348d..00000000 --- a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf8 -*- -from tinc_stats.BackwardsReader import BackwardsReader -from tinc_stats.Graph import generate_stats,delete_unused_nodes,merge_edges,get_node_avg_weight -from tinc_stats.Supernodes import check_all_the_super -from tinc_stats.Availability import get_node_availability -import sys,json -from tinc_stats.Graphite import GraphiteSender -from time import time - -try: - import os - gr = GraphiteSender(os.environ.get("GRAPHITE_HOST","localhost")) - begin = time() -except Exception as e: - sys.stderr.write( "Cannot connect to graphite: " + str(e)) - -supernodes= [ ] - -DUMP_FILE = "/krebs/db/availability" - -def write_digraph(nodes): - """ - writes the complete digraph in dot format - """ - print ('digraph retiolum {') - #print (' graph [center rankdir=LR packMode="clust"]') - print (' graph [center packMode="clust"]') - print (' node[shape=box,style=filled,fillcolor=grey]') - print (' overlap=false') - generate_stats(nodes) - merge_edges(nodes) - write_stat_node(nodes) - for k,v in nodes.iteritems(): - write_node(k,v) - print ('}') - -def dump_graph(nodes): - from time import time - graph = {} - graph['nodes'] = nodes - graph['timestamp'] = time() - f = open(DUMP_FILE,'a') - json.dump(graph,f) - f.write('\n') - f.close() - -def write_stat_node(nodes): - ''' Write a `stats` node in the corner - This node contains infos about the current number of active nodes and connections inside the network - ''' - from time import localtime,strftime - num_conns = 0 - num_nodes = len(nodes) - try: - msg = '%s.num_nodes %d %d\r\n' %(g_path,num_nodes,begin) - s.send(msg) - except Exception as e: pass - #except: pass - for k,v in nodes.iteritems(): - num_conns+= len(v['to']) - node_text = " stats_node [label=\"Statistics\\l" - node_text += "Build Date : %s\\l" % strftime("%Y-%m-%d %H:%M:%S",localtime()) - node_text += "Active Nodes: %s\\l" % num_nodes - node_text += "Connections : %s\\l" % num_conns - node_text += "\"" - node_text += ",fillcolor=green" - node_text += "]" - print(node_text) - -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)) - for k,v in nodes.iteritems(): - conns = v.get('to',[]) - for c in conns: #sanitize weights - if float(c['weight']) > 9000: c['weight'] = str(9001) - elif float(c['weight']) < 0: c['weight'] = str(0) - v['num_conns'] = len(conns) - v['avg_weight'] = get_node_avg_weight(conns) - v['availability'] = get_node_availability(k,jlines) - sys.stderr.write( "%s -> %f\n" %(k ,v['availability'])) - - - -def write_node(k,v): - """ writes a single node and its edges - edges are weightet with the informations inside the nodes provided by - tinc - """ - - node = " "+k+"[label=\"" - node += k+"\\l" - node += "availability: %f\\l" % v['availability'] - #node += "avg weight: %.2f\\l" % v['avg_weight'] - if v.has_key('num_conns'): - node += "Num Connects:"+str(v['num_conns'])+"\\l" - node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" - for addr in v.get('internal-ip',['dunno lol']): #['¯\\\\(°_o)/¯']): - node += "internal:%s\\l"%addr - node +="\"" - - # warning if node only has one connection - if v['num_conns'] == 1: - node += ",fillcolor=red" - elif k in supernodes: - node += ",fillcolor=steelblue1" - #node +=",group=\""+v['external-ip'].replace(".","")+"\"" - node += "]" - print node - - for con in v.get('to',[]): - label = con['weight'] - w = int(con['weight']) - weight = str(1000 - (((w - 150) * (1000 - 0)) / (1000 -150 )) + 0) - - length = str(float(w)/1500) - #weight = "1000" #str(300/float(con['weight'])) - #weight = str((100/float(con['weight']))) - #weight = str(-1 * (200-100000/int(con['weight']))) - if float(weight) < 0 : - weight= "1" - - #sys.stderr.write(weight + ":"+ length +" %s -> " %k + str(con) + "\n") - edge = " "+k+ " -> " +con['name'] + "[label="+label + " weight="+weight #+ " minlen="+length - if con.get('bidirectional',False): - edge += ",dir=both" - edge += "]" - print edge - -if __name__ == "__main__": - nodes = json.load(sys.stdin) - nodes = delete_unused_nodes(nodes) - for supernode,addr in check_all_the_super(): - supernodes.append(supernode) - try: - dump_graph(nodes) - except Exception,e: - sys.stderr.write("Cannot dump graph: %s" % str(e)) - write_digraph(nodes) - try: - gr.send("graph.anon_build_time",(time()-begin)*1000) - except Exception as e: pass -- cgit v1.2.3