alfred: Retrieve aliases from alfred and integrate batadv-vis.

Extending the visualisation data sources by the new batadv-vis,
which itself base ontop of alfred. Also extending the aliases import
by parsing informations from alfred. The last part is possible
through the preprocessing of data with alfred-json, so we don't
need to process the 'broken' format alfred itself supports.

This patch needs batadv-vis and tcatm/alfred-json in the PATH.
alfred-data
Daniel Ehlers 2014-01-24 02:53:17 +01:00
parent 33d7b3aefc
commit 2c79b1d91c
3 changed files with 53 additions and 4 deletions

28
alfred.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import subprocess
import json
class alfred:
def __init__(self,request_data_type = 158):
self.request_data_type = request_data_type
def aliases(self):
output = subprocess.check_output(["alfred-json","-r",str(self.request_data_type),"-f","json"])
alfred_data = json.loads(output.decode("utf-8"))
alias = {}
for mac,node in alfred_data.items():
node_alias = {}
if 'location' in node:
node_alias['gps'] = str(node['location']['latitude']) + ' ' + str(node['location']['longitude'])
if 'hostname' in node:
node_alias['name'] = node['hostname']
elif 'name' in node:
node_alias['name'] = node['name']
if len(node_alias):
alias[mac] = node_alias
return alias
if __name__ == "__main__":
ad = alfred()
al = ad.alias()
print(al)

View File

@ -6,6 +6,7 @@ import argparse
import os
from batman import batman
from alfred import alfred
from rrd import rrd
from nodedb import NodeDB
from d3mapbuilder import D3MapBuilder
@ -32,6 +33,9 @@ parser.add_argument('-m', '--mesh', action='append',
parser.add_argument('-o', '--obscure', action='store_true',
help='obscure client macs')
parser.add_argument('-A', '--alfred', action='store_true',
help='retrieve aliases from alfred')
parser.add_argument('-d', '--destination-directory', action='store',
help='destination directory for generated files',required=True)
@ -56,6 +60,10 @@ if options['aliases']:
for aliases in options['aliases']:
db.import_aliases(json.load(open(aliases)))
if options['alfred']:
af = alfred()
db.import_aliases(af.aliases())
if options['obscure']:
db.obscure_clients()

View File

@ -10,10 +10,9 @@ class batman:
self.mesh_interface = mesh_interface
def vis_data(self):
""" 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"])
lines = output.splitlines()
return self.vis_data_batadv_vis() + self.vis_data_batctl_legacy()
def vis_data_helper(self,lines):
vd = []
for line in lines:
try:
@ -23,6 +22,20 @@ class batman:
pass
return vd
def vis_data_batctl_legacy(self):
""" 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"])
lines = output.splitlines()
return self.vis_data_helper(lines)
def vis_data_batadv_vis(self):
""" 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"])
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.
"""