Merge pull request #40 from mweinelt/master

Update package structure, add alfred socket support
influxdb
Nils Schneider 2015-03-24 22:50:51 +01:00
commit 79ec0eb9d9
11 changed files with 62 additions and 36 deletions

View File

@ -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)

View File

@ -6,20 +6,20 @@ https://github.com/ffnord/ffmap-backend
import argparse import argparse
import json import json
import os import os
import networkx as nx
from datetime import datetime from datetime import datetime
import networkx as nx
from networkx.readwrite import json_graph from networkx.readwrite import json_graph
import alfred from lib import graph, nodes
import nodes from lib.alfred import Alfred
import graph from lib.batman import Batman
from batman import Batman from lib.rrddb import RRD
from rrddb import RRD
def main(params): def main(params):
nodes_fn = os.path.join(params['destination_directory'], 'nodes.json') nodes_fn = os.path.join(params['dest_dir'], 'nodes.json')
graph_fn = os.path.join(params['destination_directory'], 'graph.json') graph_fn = os.path.join(params['dest_dir'], 'graph.json')
now = datetime.utcnow().replace(microsecond=0) now = datetime.utcnow().replace(microsecond=0)
@ -35,6 +35,8 @@ 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
alfred = Alfred(unix_sockpath=params['alfred_sock'])
nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(), nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(),
now, assume_online=True) now, assume_online=True)
@ -77,7 +79,7 @@ def main(params):
if params['rrd']: if params['rrd']:
script_directory = os.path.dirname(os.path.realpath(__file__)) script_directory = os.path.dirname(os.path.realpath(__file__))
rrd = RRD(os.path.join(script_directory, 'nodedb'), 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_database(nodedb['nodes'])
rrd.update_images() rrd.update_images()
@ -92,7 +94,10 @@ if __name__ == '__main__':
parser.add_argument('-m', '--mesh', action='append', parser.add_argument('-m', '--mesh', action='append',
default=['bat0'], default=['bat0'],
help='batman mesh interface (defaults to 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', help='destination directory for generated files',
required=True) required=True)
parser.add_argument('--vpn', action='append', metavar='MAC', parser.add_argument('--vpn', action='append', metavar='MAC',

View File

@ -1,6 +1,7 @@
import os import os
import subprocess import subprocess
from RRD import RRD, DS, RRA
from lib.RRD import DS, RRA, RRD
class GlobalRRD(RRD): class GlobalRRD(RRD):

View File

@ -1,6 +1,7 @@
import os import os
import subprocess import subprocess
from RRD import RRD, DS, RRA
from lib.RRD import DS, RRA, RRD
class NodeRRD(RRD): class NodeRRD(RRD):

View File

1
lib/__init__.py Normal file
View File

@ -0,0 +1 @@
__author__ = 'hexa'

35
lib/alfred.py Normal file
View 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)

View File

@ -1,7 +1,9 @@
import networkx as nx
from functools import reduce from functools import reduce
from itertools import chain 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): def import_vis_data(graph, nodes, vis_data):

View File

@ -1,8 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import time import time
import os import os
from GlobalRRD import GlobalRRD
from NodeRRD import NodeRRD from lib.GlobalRRD import GlobalRRD
from lib.NodeRRD import NodeRRD
class RRD(object): class RRD(object):