diff --git a/backend.py b/backend.py index 685c606..f638049 100755 --- a/backend.py +++ b/backend.py @@ -17,6 +17,7 @@ from lib.alfred import Alfred from lib.batman import Batman from lib.rrddb import RRD from lib.nodelist import export_nodelist +from lib.validate import validate_nodeinfos NODES_VERSION = 1 GRAPH_VERSION = 1 @@ -76,13 +77,15 @@ def main(params): # integrate alfred nodeinfo 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) # integrate static aliases data for aliases in params['aliases']: 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) nodes.reset_statistics(nodedb['nodes']) diff --git a/lib/validate.py b/lib/validate.py new file mode 100644 index 0000000..eb6c11f --- /dev/null +++ b/lib/validate.py @@ -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