summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-11-04 14:21:26 +0100
committermakefu <github@syntax-fehler.de>2011-11-04 14:21:26 +0100
commit0ed905da208ff9eed13878485325ea26ae2e2c8f (patch)
tree81eb6ea1808eae5a83e3635cc8cbd553574d0020
parent7f69a51022ae7456c20ec5d4f0b84843561d0116 (diff)
//retiolum/adv_graphgen: replace old parsing style, refactoring
tinc_stats now writes the current tinc state into stdout as json sanitize.sh uses tinc_stats and pipes the output to parse_tinc_stats.py (the name is a lie)
-rwxr-xr-xretiolum/scripts/adv_graphgen/parse_tinc_stats.py (renamed from retiolum/scripts/adv_graphgen/parse.py)52
-rwxr-xr-xretiolum/scripts/adv_graphgen/sanitize.sh8
-rwxr-xr-xretiolum/scripts/adv_graphgen/tinc_stats.py8
3 files changed, 25 insertions, 43 deletions
diff --git a/retiolum/scripts/adv_graphgen/parse.py b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
index e99a5573..c02c9a84 100755
--- a/retiolum/scripts/adv_graphgen/parse.py
+++ b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
@@ -49,11 +49,14 @@ def write_stat_node(nodes):
def generate_stats(nodes):
""" Generates some statistics of the network and nodes
"""
- f = open(DUMP_FILE,'r')
+ try:
+ f = open(DUMP_FILE,'r')
+ f.close()
+ except Exception,e:
+ f = []
jlines = []
for line in f:
jlines.append(json.loads(line))
- f.close()
for k,v in nodes.iteritems():
conns = v.get('to',[])
v['num_conns'] = len(conns)
@@ -89,7 +92,10 @@ def get_node_availability(name,jlines):
#sys.stderr.write("%s offline at timestamp %f\n" %(name,current))
last = ts
all_the_time = last - begin
- return uptime/ all_the_time
+ try:
+ return uptime/ all_the_time
+ except:
+ return 1
def delete_unused_nodes(nodes):
new_nodes = {}
@@ -156,38 +162,12 @@ def write_node(k,v):
edge += "]"
print edge
-def parse_input():
- nodes={}
- for line in sys.stdin:
- line = line.replace('\n','')
- if line == 'Nodes:':
- nodes={}
- for line in sys.stdin:
- if line == 'End of nodes.\n':
- break
- l = line.replace('\n','').split() #TODO unhack me
- nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] }
- if line == 'Subnet list:':
- for line in sys.stdin:
- if line == 'End of subnet list.\n':
- break
- l = line.replace('\n','').split()
- if not nodes[l[2]].get('internal-ip',False):
- nodes[l[2]]['internal-ip'] = []
- nodes[l[2]]['internal-ip'].append(l[0].split('#')[0])
- if line == 'Edges:':
- edges = {}
- for line in sys.stdin:
- if line == 'End of edges.\n':
- break
- l = line.replace('\n','').split()
-
- if not nodes[l[0]].has_key('to') :
- nodes[l[0]]['to'] = []
- nodes[l[0]]['to'].append(
- {'name':l[2],'addr':l[4],'port':l[6],'weight' : l[10] })
- return nodes
-nodes = parse_input()
+def decode_input(FILE):
+ return json.load(FILE)
+nodes = decode_input(sys.stdin)
nodes = delete_unused_nodes(nodes)
-dump_graph(nodes)
+try:
+ dump_graph(nodes)
+except Exception,e:
+ sys.stderr.write("Cannot dump graph: %s" % str(e))
write_digraph(nodes)
diff --git a/retiolum/scripts/adv_graphgen/sanitize.sh b/retiolum/scripts/adv_graphgen/sanitize.sh
index 3fddb605..16479304 100755
--- a/retiolum/scripts/adv_graphgen/sanitize.sh
+++ b/retiolum/scripts/adv_graphgen/sanitize.sh
@@ -1,18 +1,18 @@
#!/bin/sh
-HERE=$(dirname `readlink -f $0`)
+cd $(dirname `readlink -f $0`)
GRAPH_SETTER1=dot
GRAPH_SETTER2=circo
GRAPH_SETTER3='neato -Goverlap=prism '
GRAPH_SETTER4=sfdp
-LOG_FILE=/var/log/syslog
+#LOG_FILE=/var/log/syslog
TYPE=svg
TYPE2=png
OPENER=/bin/true
DOTFILE=`mktemp`
trap 'rm $DOTFILE' SIGINT SIGTERM
sudo pkill -USR2 tincd
-sudo sed -n '/tinc.retiolum/{s/.*tinc.retiolum\[[0-9]*\]: //gp}' $LOG_FILE |\
- $HERE/parse.py > $DOTFILE
+sudo python tinc_stats.py |\
+ python parse_tinc_stats.py > $DOTFILE
$GRAPH_SETTER1 -T$TYPE -o $1/retiolum_1.$TYPE $DOTFILE
$GRAPH_SETTER2 -T$TYPE -o $1/retiolum_2.$TYPE $DOTFILE
diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/scripts/adv_graphgen/tinc_stats.py
index 0d3ebb11..fb238abe 100755
--- a/retiolum/scripts/adv_graphgen/tinc_stats.py
+++ b/retiolum/scripts/adv_graphgen/tinc_stats.py
@@ -2,6 +2,8 @@
from BackwardsReader import BackwardsReader
import os
import re
+import sys
+import json
TINC_NETWORK = os.environ.get("TINC_NETWORK","retiolum")
@@ -30,7 +32,6 @@ def get_tinc_block(log_file):
line = BOL.sub('',line).strip()
if END_SUBNET in line:
- print("Found end of block")
in_block = True
if not in_block:
@@ -39,7 +40,6 @@ def get_tinc_block(log_file):
tinc_block.append(line)
if BEGIN_NODES in line:
- print("Found begin of block")
break
return reversed(tinc_block)
@@ -74,4 +74,6 @@ def parse_input(log_data):
{'name':l[2],'addr':l[4],'port':l[6],'weight' : l[10] })
return nodes
-print parse_input((get_tinc_block(SYSLOG_FILE)))
+
+if __name__ == '__main__':
+ print json.dumps(parse_input((get_tinc_block(SYSLOG_FILE))))