summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <makefu@pnp.retiolum>2015-09-09 16:07:38 +0200
committermakefu <makefu@pnp.retiolum>2015-09-09 16:07:38 +0200
commit7ba002c6424034390d1ea8c92e8eaacbfd482383 (patch)
tree363808d376a0531963024b2dcb7cbf7e8dc34ff9
parent05bf2c8be209e619f8c9e727fd1353198b042642 (diff)
fix new param order of tinc output
-rwxr-xr-xretiolum/scripts/adv_graphgen/tinc_graphs/Log2JSON.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/retiolum/scripts/adv_graphgen/tinc_graphs/Log2JSON.py b/retiolum/scripts/adv_graphgen/tinc_graphs/Log2JSON.py
index 7df042fd..b0bc209b 100755
--- a/retiolum/scripts/adv_graphgen/tinc_graphs/Log2JSON.py
+++ b/retiolum/scripts/adv_graphgen/tinc_graphs/Log2JSON.py
@@ -26,7 +26,7 @@ def usage():
This tool dumps all tinc node informations as json
ENVIRONMENT VARIABLES:
- TINC_NETWORK The tinc network to dump
+ TINC_NETWORK The tinc network to dump
(default: retiolum)
""" % argv[0])
exit(1)
@@ -59,14 +59,27 @@ def parse_tinc_stats():
def parse_new_input(tinc_bin):
- nodes = {}
+ nodes = {}
pnodes = subprocess.Popen(
[tinc_bin,"-n",TINC_NETWORK,"dump","reachable","nodes"],
stdout=subprocess.PIPE).communicate()[0].decode()
for line in pnodes.split('\n'):
if not line: continue
l = line.split()
- nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] }
+ n = l[0]
+
+ token = l[1]
+ if token == 'id':
+ # new format
+ # <name> id <ident> at <ip> port <port>
+ ident = l[1]
+ l = l[2:] #shift over 'id <ident>'
+ # else: # token = 'at'
+ # old format:
+ # <name> at <ip> port <port>
+ _,_,ip,_,port = l[:5]
+ nodes[n]= { 'external-ip': ip, 'external-port' : l[4] }
+
psubnets = subprocess.check_output(
[tinc_bin,"-n",TINC_NETWORK,"dump","subnets"]).decode()
for line in psubnets.split('\n'):
@@ -78,16 +91,19 @@ def parse_new_input(tinc_bin):
nodes[l[2]]['internal-ip'].append(l[0].split('#')[0])
except KeyError:
pass # node does not exist (presumably)
+
pedges = subprocess.check_output(
[tinc_bin,"-n",TINC_NETWORK,"dump","edges"]).decode()
for line in pedges.split('\n'):
if not line: continue
l = line.split()
+ # TODO: tokenize this and parse the line
+ n = l[0]
try:
if not 'to' in nodes[l[0]] :
- nodes[l[0]]['to'] = []
- nodes[l[0]]['to'].append(
- {'name':l[2],'addr':l[4],'port':l[6],'weight' : l[10] })
+ nodes[n]['to'] = []
+ nodes[n]['to'].append(
+ {'name':l[2],'addr':l[4],'port':l[6],'weight' : l[-1] })
except KeyError:
pass #node does not exist
return nodes