summaryrefslogtreecommitdiffstats
path: root/retiolum/hosts
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-05-11 13:48:07 +0200
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-05-11 13:48:07 +0200
commitb719d0e21d6f0fb8476fbd8acc50f0a01ebbf804 (patch)
treef2b9487a82cdf2a0ca31cce03cacaf0a8921b9fd /retiolum/hosts
parent513b1ad5c490f9f3821fc6aa2a9bddf3c3f31802 (diff)
refactored parse.py
parse.py: now also writes the number of current connections
Diffstat (limited to 'retiolum/hosts')
-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