summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xretiolum/hosts/.scripts/parse.py32
-rwxr-xr-xretiolum/hosts/.scripts/sanitize.sh2
2 files changed, 31 insertions, 3 deletions
diff --git a/retiolum/hosts/.scripts/parse.py b/retiolum/hosts/.scripts/parse.py
index 951fce94..54f6c35d 100755
--- a/retiolum/hosts/.scripts/parse.py
+++ b/retiolum/hosts/.scripts/parse.py
@@ -1,24 +1,52 @@
#!/usr/bin/python2
import sys
+""" TODO: Refactoring needed to pull the edges out of the node structures again,
+it should be easier to handle both structures"""
def write_digraph(nodes):
- print ('digraph retiolum {')
+ """
+ writes the complete digraph in dot format
+ """
+ print ('graph retiolum {')
print (' node[shape=box,style=filled,fillcolor=grey]')
+ generate_stats(nodes)
+ merge_edges(nodes)
for k,v in nodes.iteritems():
write_node(k,v)
print ('}')
+def generate_stats(nodes):
+ """ Generates some statistics of the network and nodes
+ """
+ for k,v in nodes.iteritems():
+ v['num_conns'] = len(v.get('to',[]))
+
+def merge_edges(nodes):
+ """ merge back and forth edges into one
+ DESTRUCTS the current structure by deleting "connections" in the nodes
+
+ """
+ for k,v in nodes.iteritems():
+ for con in v.get('to',[]):
+ for i,secon in enumerate(nodes[con['name']].get('to',[])):
+ if k == secon['name']:
+ del (nodes[con['name']]['to'][i])
+
+
def write_node(k,v):
+ """ writes a single node and its edges """
node = " "+k+"[label=\""
node += k+"\\l"
node += "external:"+v['external-ip']+":"+v['external-port']+"\\l"
+ if v.has_key('num_conns'):
+ node += "Num Connects:"+str(v['num_conns'])+"\\l"
node += "internal:"+v['internal-ip']+"\\l\""
if v['external-ip'] == "MYSELF":
node += ",fillcolor=steelblue1"
node += "]"
print (node)
for con in v.get('to',[]):
- print " "+k+ "->" +con['name'] + "[weight="+str(10/float(con['weight']))+"]"
+ print " "+k+ " -- " +con['name'] + "[weight="+str(10/float(con['weight']))+"]"
def parse_input():
nodes={}
diff --git a/retiolum/hosts/.scripts/sanitize.sh b/retiolum/hosts/.scripts/sanitize.sh
index 75a04af1..0342d98b 100755
--- a/retiolum/hosts/.scripts/sanitize.sh
+++ b/retiolum/hosts/.scripts/sanitize.sh
@@ -1,2 +1,2 @@
-sudo sed -n '/tinc.retiolum/{s/.*tinc.retiolum\[[1-9]*\]: //gp}' /var/log/everything.log | ./parse.py | tee here.dot | dot -Tpng -o retiolum.png
+sudo sed -n '/tinc.retiolum/{s/.*tinc.retiolum\[[1-9]*\]: //gp}' /var/log/everything.log | ./parse.py | tee retiolum.dot | dot -Tpng -o retiolum.png
mirage retiolum.png