}
@router.get(config.get("base_url") + "/api/top.json", response_class=JSONResponse)
-def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None):
+def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None):
if blocked != None:
if blocked > 500:
raise HTTPException(status_code=400, detail="Too many results")
if originator > 500:
raise HTTPException(status_code=400, detail="Too many results")
fba.cursor.execute("SELECT originator, COUNT(domain) FROM instances WHERE originator IS NOT NULL GROUP BY originator ORDER BY COUNT(domain) DESC, originator ASC LIMIT ?", [originator])
+ elif error_code != None:
+ if error_code > 500:
+ raise HTTPException(status_code=400, detail="Too many results")
+ fba.cursor.execute("SELECT last_status_code, COUNT(domain) AS cnt FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY cnt DESC LIMIT ?", [error_code])
else:
raise HTTPException(status_code=400, detail="No filter specified")
return JSONResponse(status_code=200, content={})
@router.get(config.get("base_url") + "/scoreboard")
-def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None):
- scores = None
-
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None):
if blockers != None and blockers > 0:
response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?blockers={blockers}")
elif blocked != None and blocked > 0:
response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?software={software}")
elif originator != None and originator > 0:
response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?originator={originator}")
+ elif error_code != None and error_code > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?error_code={error_code}")
else:
raise HTTPException(status_code=400, detail="No filter specified")
"reference" : reference,
"software" : software,
"originator": originator,
+ "error_code": error_code,
"scores" : fba.json_from_response(response)
})