Merge branch 'master' of https://github.com/mweinelt/ffmap-backend into mweinelt-master
commit
bd943e4360
|
@ -23,8 +23,9 @@ class GlobalRRD(RRD):
|
|||
super().__init__(os.path.join(directory, "nodes.rrd"))
|
||||
self.ensure_sanity(self.ds_list, self.rra_list, step=60)
|
||||
|
||||
def update(self, nodeCount, clientCount):
|
||||
super().update({'nodes': nodeCount, 'clients': clientCount})
|
||||
# TODO: fix this, python does not support function overloading
|
||||
def update(self, node_count, client_count):
|
||||
super().update({'nodes': node_count, 'clients': client_count})
|
||||
|
||||
def graph(self, filename, timeframe):
|
||||
args = ["rrdtool", 'graph', filename,
|
||||
|
|
|
@ -3,7 +3,8 @@ import json
|
|||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
|
|
10
backend.py
10
backend.py
|
@ -35,16 +35,20 @@ def main(params):
|
|||
for node_id, node in nodedb['nodes'].items():
|
||||
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']:
|
||||
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.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:
|
||||
nodes.import_mesh_ifs_vis_data(nodedb['nodes'], vis_data)
|
||||
nodes.import_vis_clientcount(nodedb['nodes'], vis_data)
|
||||
|
|
24
batman.py
24
batman.py
|
@ -30,30 +30,37 @@ class Batman(object):
|
|||
|
||||
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()
|
||||
vds = self.vis_data_helper(lines)
|
||||
return vds
|
||||
|
||||
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()
|
||||
return self.vis_data_helper(lines)
|
||||
|
||||
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')
|
||||
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 = []
|
||||
gw_mode = self.gateway_mode()
|
||||
|
@ -71,7 +78,8 @@ class Batman(object):
|
|||
"""
|
||||
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()
|
||||
mode = elements[0]
|
||||
if mode == 'server':
|
||||
|
|
Loading…
Reference in New Issue