Merge pull request #40 from mweinelt/master
Update package structure, add alfred socket support
This commit is contained in:
commit
79ec0eb9d9
20
alfred.py
20
alfred.py
|
@ -1,20 +0,0 @@
|
|||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
def _fetch(data_type):
|
||||
output = subprocess.check_output(
|
||||
["alfred-json", "-z", "-f", "json", "-r", str(data_type)])
|
||||
return json.loads(output.decode("utf-8")).values()
|
||||
|
||||
|
||||
def nodeinfo():
|
||||
return _fetch(158)
|
||||
|
||||
|
||||
def statistics():
|
||||
return _fetch(159)
|
||||
|
||||
|
||||
def vis():
|
||||
return _fetch(160)
|
25
backend.py
25
backend.py
|
@ -6,20 +6,20 @@ https://github.com/ffnord/ffmap-backend
|
|||
import argparse
|
||||
import json
|
||||
import os
|
||||
import networkx as nx
|
||||
from datetime import datetime
|
||||
|
||||
import networkx as nx
|
||||
from networkx.readwrite import json_graph
|
||||
|
||||
import alfred
|
||||
import nodes
|
||||
import graph
|
||||
from batman import Batman
|
||||
from rrddb import RRD
|
||||
from lib import graph, nodes
|
||||
from lib.alfred import Alfred
|
||||
from lib.batman import Batman
|
||||
from lib.rrddb import RRD
|
||||
|
||||
|
||||
def main(params):
|
||||
nodes_fn = os.path.join(params['destination_directory'], 'nodes.json')
|
||||
graph_fn = os.path.join(params['destination_directory'], 'graph.json')
|
||||
nodes_fn = os.path.join(params['dest_dir'], 'nodes.json')
|
||||
graph_fn = os.path.join(params['dest_dir'], 'graph.json')
|
||||
|
||||
now = datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
|
@ -35,6 +35,8 @@ def main(params):
|
|||
for node_id, node in nodedb['nodes'].items():
|
||||
node['flags']['online'] = False
|
||||
|
||||
alfred = Alfred(unix_sockpath=params['alfred_sock'])
|
||||
|
||||
nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(),
|
||||
now, assume_online=True)
|
||||
|
||||
|
@ -77,7 +79,7 @@ def main(params):
|
|||
if params['rrd']:
|
||||
script_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
rrd = RRD(os.path.join(script_directory, 'nodedb'),
|
||||
os.path.join(params['destination_directory'], 'nodes'))
|
||||
os.path.join(params['dest_dir'], 'nodes'))
|
||||
rrd.update_database(nodedb['nodes'])
|
||||
rrd.update_images()
|
||||
|
||||
|
@ -92,7 +94,10 @@ if __name__ == '__main__':
|
|||
parser.add_argument('-m', '--mesh', action='append',
|
||||
default=['bat0'],
|
||||
help='batman mesh interface (defaults to bat0)')
|
||||
parser.add_argument('-d', '--destination-directory', action='store',
|
||||
parser.add_argument('-s', '--alfred-sock',
|
||||
default=None,
|
||||
help='alfred unix socket path')
|
||||
parser.add_argument('-d', '--dest-dir', action='store',
|
||||
help='destination directory for generated files',
|
||||
required=True)
|
||||
parser.add_argument('--vpn', action='append', metavar='MAC',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import subprocess
|
||||
from RRD import RRD, DS, RRA
|
||||
|
||||
from lib.RRD import DS, RRA, RRD
|
||||
|
||||
|
||||
class GlobalRRD(RRD):
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import subprocess
|
||||
from RRD import RRD, DS, RRA
|
||||
|
||||
from lib.RRD import DS, RRA, RRD
|
||||
|
||||
|
||||
class NodeRRD(RRD):
|
1
lib/__init__.py
Normal file
1
lib/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
__author__ = 'hexa'
|
35
lib/alfred.py
Normal file
35
lib/alfred.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import subprocess
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class Alfred(object):
|
||||
"""
|
||||
Bindings for the alfred-json utility
|
||||
"""
|
||||
def __init__(self, unix_sockpath=None):
|
||||
if unix_sockpath:
|
||||
if os.path.exists(unix_sockpath):
|
||||
self.unix_sock = unix_sockpath
|
||||
else:
|
||||
raise RuntimeError('alfred: invalid unix socket path given')
|
||||
|
||||
def _fetch(self, data_type):
|
||||
cmd = ['alfred-json',
|
||||
'-z',
|
||||
'-f', 'json',
|
||||
'-r', data_type]
|
||||
if self.unix_sock:
|
||||
cmd.extend(['-s', self.unix_sock])
|
||||
|
||||
output = subprocess.check_output(cmd)
|
||||
return json.loads(output.decode("utf-8")).values()
|
||||
|
||||
def nodeinfo(self):
|
||||
return self._fetch(158)
|
||||
|
||||
def statistics(self):
|
||||
return self._fetch(159)
|
||||
|
||||
def vis(self):
|
||||
return self._fetch(160)
|
|
@ -1,7 +1,9 @@
|
|||
import networkx as nx
|
||||
from functools import reduce
|
||||
from itertools import chain
|
||||
from nodes import build_mac_table
|
||||
|
||||
import networkx as nx
|
||||
|
||||
from lib.nodes import build_mac_table
|
||||
|
||||
|
||||
def import_vis_data(graph, nodes, vis_data):
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import time
|
||||
import os
|
||||
from GlobalRRD import GlobalRRD
|
||||
from NodeRRD import NodeRRD
|
||||
|
||||
from lib.GlobalRRD import GlobalRRD
|
||||
from lib.NodeRRD import NodeRRD
|
||||
|
||||
|
||||
class RRD(object):
|
Loading…
Reference in a new issue