2014-07-07 23:27:21 +02:00
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
|
|
|
class Input:
|
|
|
|
def __init__(self,request_data_type = 158):
|
|
|
|
self.request_data_type = request_data_type
|
|
|
|
|
|
|
|
def get_data(self, nodedb):
|
|
|
|
"""Add data from alfred to the supplied nodedb"""
|
2014-07-31 11:41:26 +02:00
|
|
|
# get nodeinfo
|
2014-07-07 23:27:21 +02:00
|
|
|
output = subprocess.check_output([
|
|
|
|
"alfred-json",
|
|
|
|
"-r", str(self.request_data_type),
|
|
|
|
"-f", "json",
|
|
|
|
])
|
2014-07-31 11:41:26 +02:00
|
|
|
nodeinfo = json.loads(output.decode("utf-8"))
|
2014-07-07 23:27:21 +02:00
|
|
|
|
2014-07-31 11:41:26 +02:00
|
|
|
# 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():
|
2014-07-07 23:27:21 +02:00
|
|
|
nodedb.add_or_update([mac], node)
|