Merge branch 'master' of https://github.com/mweinelt/ffmap-backend into mweinelt-master

This commit is contained in:
Nils Schneider 2015-03-24 18:36:11 +01:00
commit bd943e4360
4 changed files with 28 additions and 14 deletions

View file

@ -23,8 +23,9 @@ class GlobalRRD(RRD):
super().__init__(os.path.join(directory, "nodes.rrd")) super().__init__(os.path.join(directory, "nodes.rrd"))
self.ensure_sanity(self.ds_list, self.rra_list, step=60) self.ensure_sanity(self.ds_list, self.rra_list, step=60)
def update(self, nodeCount, clientCount): # TODO: fix this, python does not support function overloading
super().update({'nodes': nodeCount, 'clients': clientCount}) def update(self, node_count, client_count):
super().update({'nodes': node_count, 'clients': client_count})
def graph(self, filename, timeframe): def graph(self, filename, timeframe):
args = ["rrdtool", 'graph', filename, args = ["rrdtool", 'graph', filename,

View file

@ -3,7 +3,8 @@ import json
def _fetch(data_type): def _fetch(data_type):
output = subprocess.check_output(["alfred-json", "-z", "-f", "json", "-r", str(data_type)]) output = subprocess.check_output(
["alfred-json", "-z", "-f", "json", "-r", str(data_type)])
return json.loads(output.decode("utf-8")).values() return json.loads(output.decode("utf-8")).values()

View file

@ -35,16 +35,20 @@ def main(params):
for node_id, node in nodedb['nodes'].items(): for node_id, node in nodedb['nodes'].items():
node['flags']['online'] = False node['flags']['online'] = False
nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(), now, assume_online=True) nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(),
now, assume_online=True)
for aliases in params['aliases']: for aliases in params['aliases']:
with open(aliases, 'r') as f: with open(aliases, 'r') as f:
nodes.import_nodeinfo(nodedb['nodes'], json.load(f), now, assume_online=False) nodes.import_nodeinfo(nodedb['nodes'], json.load(f),
now, assume_online=False)
nodes.reset_statistics(nodedb['nodes']) nodes.reset_statistics(nodedb['nodes'])
nodes.import_statistics(nodedb['nodes'], alfred.statistics()) nodes.import_statistics(nodedb['nodes'], alfred.statistics())
bm = list(map(lambda d: (d.vis_data(True), d.gateway_list()), map(Batman, params['mesh']))) bm = list(map(lambda d:
(d.vis_data(True), d.gateway_list()),
map(Batman, params['mesh'])))
for vis_data, gateway_list in bm: for vis_data, gateway_list in bm:
nodes.import_mesh_ifs_vis_data(nodedb['nodes'], vis_data) nodes.import_mesh_ifs_vis_data(nodedb['nodes'], vis_data)
nodes.import_vis_clientcount(nodedb['nodes'], vis_data) nodes.import_vis_clientcount(nodedb['nodes'], vis_data)

View file

@ -30,30 +30,37 @@ class Batman(object):
def vis_data_batctl_legacy(self): def vis_data_batctl_legacy(self):
""" """
Parse "batctl -m <mesh_interface> vd json -n" into an array of dictionaries. Parse "batctl -m <mesh_interface> vd json -n"
into an array of dictionaries.
""" """
output = subprocess.check_output(['batctl', '-m', self.mesh_interface, 'vd', 'json', '-n']) output = subprocess.check_output(
['batctl', '-m', self.mesh_interface, 'vd', 'json', '-n'])
lines = output.splitlines() lines = output.splitlines()
vds = self.vis_data_helper(lines) vds = self.vis_data_helper(lines)
return vds return vds
def vis_data_batadv_vis(self): def vis_data_batadv_vis(self):
""" """
Parse "batadv-vis -i <mesh_interface> -f json" into an array of dictionaries. Parse "batadv-vis -i <mesh_interface> -f json"
into an array of dictionaries.
""" """
output = subprocess.check_output(['batadv-vis', '-i', self.mesh_interface, '-f', 'json']) output = subprocess.check_output(
['batadv-vis', '-i', self.mesh_interface, '-f', 'json'])
lines = output.splitlines() lines = output.splitlines()
return self.vis_data_helper(lines) return self.vis_data_helper(lines)
def gateway_list(self): def gateway_list(self):
""" """
Parse "batctl -m <mesh_interface> gwl -n" into an array of dictionaries. Parse "batctl -m <mesh_interface> gwl -n"
into an array of dictionaries.
""" """
output = subprocess.check_output(['batctl', '-m', self.mesh_interface, 'gwl', '-n']) output = subprocess.check_output(
['batctl', '-m', self.mesh_interface, 'gwl', '-n'])
output_utf8 = output.decode('utf-8') output_utf8 = output.decode('utf-8')
lines = output_utf8.splitlines() lines = output_utf8.splitlines()
own_mac = re.match(r"^.*MainIF/MAC: [^/]+/([0-9a-f:]+).*$", lines[0]).group(1) own_mac = re.match(r"^.*MainIF/MAC: [^/]+/([0-9a-f:]+).*$",
lines[0]).group(1)
gateways = [] gateways = []
gw_mode = self.gateway_mode() gw_mode = self.gateway_mode()
@ -71,7 +78,8 @@ class Batman(object):
""" """
Parse "batctl -m <mesh_interface> gw" Parse "batctl -m <mesh_interface> gw"
""" """
output = subprocess.check_output(['batctl', '-m', self.mesh_interface, 'gw']) output = subprocess.check_output(
['batctl', '-m', self.mesh_interface, 'gw'])
elements = output.decode("utf-8").split() elements = output.decode("utf-8").split()
mode = elements[0] mode = elements[0]
if mode == 'server': if mode == 'server':