From 446bc984039816bc6f6e6a5a202c9306e68c954c Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Thu, 31 Jul 2014 11:41:26 +0200 Subject: [PATCH] input alfred: unify nodeinfo and stats datatypes --- ffmap/inputs/alfred.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ffmap/inputs/alfred.py b/ffmap/inputs/alfred.py index 6c0f66e..340c0d9 100644 --- a/ffmap/inputs/alfred.py +++ b/ffmap/inputs/alfred.py @@ -7,12 +7,26 @@ class Input: def get_data(self, nodedb): """Add data from alfred to the supplied nodedb""" + # get nodeinfo output = subprocess.check_output([ "alfred-json", "-r", str(self.request_data_type), "-f", "json", ]) - alfred_data = json.loads(output.decode("utf-8")) + nodeinfo = json.loads(output.decode("utf-8")) - for mac, node in alfred_data.items(): + # get statistics + output = subprocess.check_output([ + "alfred-json", + "-r", str(self.request_data_type+1), + "-f", "json", + ]) + statistics = json.loads(output.decode("utf-8")) + + # merge statistics into nodeinfo to be compatible with earlier versions + for mac, node in statistics.items(): + if mac in nodeinfo: + nodeinfo[mac]['statistics'] = statistics[mac] + + for mac, node in nodeinfo.items(): nodedb.add_or_update([mac], node)