jquery - Using 3rd party json data in django -
i have live monitoring data tool called prtg via api want build django site brings in real time reporting along other dashboards have created.
i'm stuck @ first step of bring in api data display on page.
the api data this:
{"prtg-version": "14.1.8.1371", "treesize": 381, "sensors": [ { "objid": 1001, "probe": "newname", "group": "newname", "device": "br-s-log", "sensor": "system health", "status": "up", "status_raw": 3, "message": "<div class=\"status\">ok<div class=\"moreicon\"></div></div>", "message_raw": "ok", "lastvalue": "100 %", "lastvalue_raw": 100.0000, "priority": 5 }, { "objid": 1002, "probe": "newname", "group": "newname", "device": "br-s-log", "sensor": "core health", "status": "up", "status_raw": 3, "message": "<div class=\"status\">ok<div class=\"moreicon\"></div></div>", "message_raw": "ok", "lastvalue": "100 %", "lastvalue_raw": 100.0000, "priority": 5 }, { "objid": 1003, "probe": "newname", "group": "newname", "device": "br-s-log", "sensor": "probe health", "status": "up", "status_raw": 3, "message": "<div class=\"status\">ok<div class=\"moreicon\"></div></div>", "message_raw": "ok", "lastvalue": "98 %", "lastvalue_raw": 98.0000, "priority": 5 }, { "objid": 1004, "probe": "newname", "group": "newname", "device": "br-s-log", "sensor": "disk free", "status": "up", "status_raw": 3, "message": "<div class=\"status\">ok<div class=\"moreicon\"></div></div>", "message_raw": "ok", "lastvalue": "", "lastvalue_raw": "", "priority": 4 } ]}
i have view, can't working
import requests import json django.shortcuts import render, def list_all(request): jsonlist = [] url = "https://server/api/link" req = requests.get(url) jsonlist.append(json.loads(req.content)) parseddata = [] prtgdata = {} data in jsonlist: prtgdata['group'] = data ['group'] prtgdata['device'] = data ['device'] prtgdata['status'] = data ['status'] prtgdata['lastvalue'] = data ['lastvalue'] parseddata.append(prtgdata) return render(request, 'status/main.html', {'data': parseddata})
i error:
keyerror @ /status/ 'group' request method: request url: http://127.0.0.1:8000/status/ django version: 1.9.2 exception type: keyerror exception value:'group' exception location: c:\users\documents\site\status\views.py in list_all, line 44 python executable: c:\python27\python.exe python version: 2.7.10 python path: ['c:\\users\\documents\\site', 'c:\\windows\\system32\\python27.zip', 'c:\\python27\\dlls', 'c:\\python27\\lib', 'c:\\python27\\lib\\plat-win', 'c:\\python27\\lib\\lib-tk', 'c:\\python27', 'c:\\python27\\lib\\site-packages', 'c:\\python27\\lib\\site-packages\\newrelic-2.60.0.46', 'c:\\users\\documents\\site'] server time: thu, 10 nov 2016 16:36:44 +1000
any thoughts best way bring in? might not using right method, have tried jquery no success either
the goal bring in every 10 minutes or so, check status of device ptrg against event data (manually entered form) create monitoring dashboard.
new django or hints appreciated.
Comments
Post a Comment