summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--retiolum/scripts/adv_graphgen/find_super.py50
-rwxr-xr-xretiolum/scripts/adv_graphgen/parse_tinc_anon.py4
-rwxr-xr-xretiolum/scripts/adv_graphgen/parse_tinc_stats.py12
3 files changed, 59 insertions, 7 deletions
diff --git a/retiolum/scripts/adv_graphgen/find_super.py b/retiolum/scripts/adv_graphgen/find_super.py
new file mode 100644
index 00000000..df01734e
--- /dev/null
+++ b/retiolum/scripts/adv_graphgen/find_super.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+def find_super(path="/etc/tinc/retiolum/hosts"):
+ import os
+ import re
+
+ needle_addr = re.compile("Address\s*=\s*(.*)")
+ needle_port = re.compile("Port\s*=\s*(.*)")
+ for f in os.listdir(path):
+ with open(path+"/"+f) as of:
+ addrs = []
+ port = "655"
+
+ for line in of.readlines():
+
+ addr_found = needle_addr.match(line)
+ if addr_found:
+ addrs.append(addr_found.group(1))
+
+ port_found = needle_port.match(line)
+ if port_found:
+ port = port_found.group(1)
+
+ if addrs : yield (f ,[(addr ,int(port)) for addr in addrs])
+
+def check_super(path="/etc/tinc/retiolum/hosts"):
+ from socket import socket,AF_INET,SOCK_STREAM
+ for host,addrs in find_super(path):
+ valid_addrs = []
+ for addr in addrs:
+ try:
+ s = socket(AF_INET,SOCK_STREAM)
+ s.settimeout(3)
+ s.connect(addr)
+ #print("success connecting %s:%d"%(addr))
+ s.settimeout(None)
+ s.close()
+ valid_addrs.append(addr)
+ except Exception as e:
+ pass
+ #print("cannot connect to %s:%d"%(addr))
+ if valid_addrs: yield (host,valid_addrs)
+
+
+if __name__ == "__main__":
+ """
+ usage
+ """
+ for host,addrs in check_super():
+ print host,addrs
diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_anon.py b/retiolum/scripts/adv_graphgen/parse_tinc_anon.py
index e0bea913..21c36e0f 100755
--- a/retiolum/scripts/adv_graphgen/parse_tinc_anon.py
+++ b/retiolum/scripts/adv_graphgen/parse_tinc_anon.py
@@ -15,7 +15,7 @@ try:
sys.stderr.write("connecting to %s:%d"%(host,port))
s.connect((host,port))
except Exception as e:
- print >>sys.stderr, "Cannot connect to graphite: " + str(e)
+ sys.stderr.write( "Cannot connect to graphite: " + str(e))
""" TODO: Refactoring needed to pull the edges out of the node structures again,
it should be easier to handle both structures"""
DUMP_FILE = "/krebs/db/availability"
@@ -151,4 +151,4 @@ try:
msg = '%s.graph.anon_build_time %d %d\r\n' % (g_path,((end-begin)*1000),end)
s.send(msg)
s.close()
-except Exception as e: print >>sys.stderr, e
+except Exception as e: pass
diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
index 16f4f795..8371ad3d 100755
--- a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
+++ b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
@@ -2,6 +2,7 @@
# -*- coding: utf8 -*-
from BackwardsReader import BackwardsReader
import sys,json
+from find_super import check_super
try:
from time import time
import socket
@@ -16,7 +17,10 @@ try:
except Exception as e:
sys.stderr.write("Cannot connect to graphite: %s\n" % str(e))
-supernodes= [ "kaah","supernode","euer","pa_sharepoint","oxberg" ]
+supernodes= [ ]
+#supernodes= [ "kaah","supernode","euer","pa_sharepoint","oxberg" ]
+for supernode,addr in check_super():
+ supernodes.append(supernode)
""" TODO: Refactoring needed to pull the edges out of the node structures again,
it should be easier to handle both structures"""
DUMP_FILE = "/krebs/db/availability"
@@ -53,8 +57,7 @@ def write_stat_node(nodes):
try:
msg = '%s.num_nodes %d %d\r\n' %(g_path,num_nodes,begin)
s.send(msg)
- #print >>sys.stderr, msg
- except Exception as e: print sys.stderr,e
+ except Exception as e: pass
#except: pass
for k,v in nodes.iteritems():
num_conns+= len(v['to'])
@@ -82,8 +85,7 @@ def generate_stats(nodes):
jlines.append(jline)
lines_to_use -=1
- except Exception,e:
- sys.stderr.write(str(e))
+ except Exception,e: sys.stderr.write(str(e))
for k,v in nodes.iteritems():
conns = v.get('to',[])
for c in conns: #sanitize weights