output nodelist.json
This commit is contained in:
parent
4b88a196ac
commit
fa740273bb
2 changed files with 29 additions and 0 deletions
24
lib/nodelist.py
Normal file
24
lib/nodelist.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
def export_nodelist(now, nodedb):
|
||||
nodelist = list()
|
||||
|
||||
for node_id, node in nodedb["nodes"].items():
|
||||
node_out = dict()
|
||||
node_out["id"] = node_id
|
||||
node_out["name"] = node["nodeinfo"]["hostname"]
|
||||
|
||||
if "location" in node["nodeinfo"]:
|
||||
node_out["position"] = {"lat": node["nodeinfo"]["location"]["latitude"],
|
||||
"long": node["nodeinfo"]["location"]["longitude"]}
|
||||
|
||||
node_out["status"] = dict()
|
||||
node_out["status"]["online"] = node["flags"]["online"]
|
||||
|
||||
if "lastseen" in node:
|
||||
node_out["status"]["lastcontact"] = node["lastseen"]
|
||||
|
||||
if "clients" in node["statistics"]:
|
||||
node_out["status"]["clients"] = node["statistics"]["clients"]
|
||||
|
||||
nodelist.append(node_out)
|
||||
|
||||
return {"version": "1.0.1", "nodes": nodelist, "updated_at": now.isoformat()}
|
Loading…
Add table
Add a link
Reference in a new issue