From 822c43a763aa61c1accce3768090d066048faaff Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 3 Nov 2011 20:14:06 +0100 Subject: //retiolum//tinc_stats: initial commit tinc_stats writes the current TINC statistics into stdout --- retiolum/scripts/adv_graphgen/tinc_stats.py | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 retiolum/scripts/adv_graphgen/tinc_stats.py (limited to 'retiolum/scripts/adv_graphgen/tinc_stats.py') diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/scripts/adv_graphgen/tinc_stats.py new file mode 100755 index 00000000..0d3ebb11 --- /dev/null +++ b/retiolum/scripts/adv_graphgen/tinc_stats.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +from BackwardsReader import BackwardsReader +import os +import re + + +TINC_NETWORK = os.environ.get("TINC_NETWORK","retiolum") +SYSLOG_FILE = "/var/log/everything.log" + + +# Tags and Delimiters +TINC_TAG="tinc.%s" % TINC_NETWORK +BEGIN_NODES = "Nodes:" +END_NODES = "End of nodes." +BEGIN_SUBNET = "Subnet list:" +END_SUBNET = "End of subnet list" +BEGIN_EDGES = "Edges:" +END_EDGES = "End of edges." + +def get_tinc_block(log_file): + """ returns an iterateable block from the given log file (syslog) """ + tinc_block = [] + in_block = False + bf = BackwardsReader(log_file) + BOL = re.compile(".*tinc.retiolum\[[0-9]+\]: ") + while True: + line = bf.readline() + if not line: + raise Exception("end of file at log file? This should not happen!") + line = BOL.sub('',line).strip() + + if END_SUBNET in line: + print("Found end of block") + in_block = True + + if not in_block: + continue + + tinc_block.append(line) + + if BEGIN_NODES in line: + print("Found begin of block") + break + return reversed(tinc_block) + +def parse_input(log_data): + nodes={} + for line in log_data: + if BEGIN_NODES in line : + nodes={} + for line in log_data: + if END_NODES in line : + break + l = line.replace('\n','').split() #TODO unhack me + nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] } + if BEGIN_SUBNET in line : + for line in log_data: + if END_SUBNET in line : + 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 BEGIN_EDGES in line : + edges = {} + for line in log_data: + if END_EDGES in line : + 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 + +print parse_input((get_tinc_block(SYSLOG_FILE))) -- cgit v1.2.3 From fc5b5f2562cbfd9028f6b77269d123261dae89e9 Mon Sep 17 00:00:00 2001 From: EUcancER Date: Fri, 4 Nov 2011 13:41:01 +0100 Subject: //retiolum/adv_graphgen: bug-fixing debian uses features of adv_graphgen which hasn't been tested until now. Bugs has been fixed concerning usage of LOG_FILE environ and many more fix minor calculation bug in availability calucluation (delete faulty archive lines) --- retiolum/scripts/adv_graphgen/tinc_stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'retiolum/scripts/adv_graphgen/tinc_stats.py') diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/scripts/adv_graphgen/tinc_stats.py index fb238abe..370c59f7 100755 --- a/retiolum/scripts/adv_graphgen/tinc_stats.py +++ b/retiolum/scripts/adv_graphgen/tinc_stats.py @@ -7,7 +7,8 @@ import json TINC_NETWORK = os.environ.get("TINC_NETWORK","retiolum") -SYSLOG_FILE = "/var/log/everything.log" +os.environ["LOG_FILE"] +SYSLOG_FILE = os.environ.get("LOG_FILE","/var/log/everything.log") # Tags and Delimiters -- cgit v1.2.3 From 0ed905da208ff9eed13878485325ea26ae2e2c8f Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 4 Nov 2011 14:21:26 +0100 Subject: //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) --- retiolum/scripts/adv_graphgen/tinc_stats.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'retiolum/scripts/adv_graphgen/tinc_stats.py') 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)))) -- cgit v1.2.3 From 0dd85c8b1acaebb18a648b0c0b5d4c48b69903d9 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 4 Nov 2011 14:43:58 +0100 Subject: //retiolum/adv_graphgen: tinc_stats now invokes USR2 against tinc deamon --- retiolum/scripts/adv_graphgen/tinc_stats.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'retiolum/scripts/adv_graphgen/tinc_stats.py') diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/scripts/adv_graphgen/tinc_stats.py index fb238abe..21d03cc4 100755 --- a/retiolum/scripts/adv_graphgen/tinc_stats.py +++ b/retiolum/scripts/adv_graphgen/tinc_stats.py @@ -76,4 +76,7 @@ def parse_input(log_data): if __name__ == '__main__': + import subprocess,time + subprocess.popen("pkill -SIGUSR2 tincd") + time.sleep(1) print json.dumps(parse_input((get_tinc_block(SYSLOG_FILE)))) -- cgit v1.2.3