basic nodeinfo validation (location)
This commit is contained in:
parent
8b8b2cc324
commit
1835abac7f
|
@ -17,6 +17,7 @@ from lib.alfred import Alfred
|
||||||
from lib.batman import Batman
|
from lib.batman import Batman
|
||||||
from lib.rrddb import RRD
|
from lib.rrddb import RRD
|
||||||
from lib.nodelist import export_nodelist
|
from lib.nodelist import export_nodelist
|
||||||
|
from lib.validate import validate_nodeinfos
|
||||||
|
|
||||||
NODES_VERSION = 1
|
NODES_VERSION = 1
|
||||||
GRAPH_VERSION = 1
|
GRAPH_VERSION = 1
|
||||||
|
@ -76,13 +77,15 @@ def main(params):
|
||||||
|
|
||||||
# integrate alfred nodeinfo
|
# integrate alfred nodeinfo
|
||||||
for alfred in alfred_instances:
|
for alfred in alfred_instances:
|
||||||
nodes.import_nodeinfo(nodedb['nodes'], alfred.nodeinfo(),
|
nodeinfo = validate_nodeinfos(alfred.nodeinfo())
|
||||||
|
nodes.import_nodeinfo(nodedb['nodes'], nodeinfo,
|
||||||
now, assume_online=True)
|
now, assume_online=True)
|
||||||
|
|
||||||
# integrate static aliases data
|
# integrate static aliases data
|
||||||
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),
|
nodeinfo = validate_nodeinfos(json.load(f))
|
||||||
|
nodes.import_nodeinfo(nodedb['nodes'], nodeinfo,
|
||||||
now, assume_online=False)
|
now, assume_online=False)
|
||||||
|
|
||||||
nodes.reset_statistics(nodedb['nodes'])
|
nodes.reset_statistics(nodedb['nodes'])
|
||||||
|
|
19
lib/validate.py
Normal file
19
lib/validate.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def validate_nodeinfos(nodeinfos):
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for nodeinfo in nodeinfos:
|
||||||
|
if validate_nodeinfo(nodeinfo):
|
||||||
|
result.append(nodeinfo)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def validate_nodeinfo(nodeinfo):
|
||||||
|
if 'location' in nodeinfo:
|
||||||
|
if 'latitude' not in nodeinfo['location'] or 'longitude' not in nodeinfo['location']:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
Loading…
Reference in a new issue