def get(self, request: HttpRequest) -> HttpResponse: """Check for HTTP-Basic auth""" auth_header = request.META.get("HTTP_AUTHORIZATION", "") auth_type, _, given_credentials = auth_header.partition(" ") credentials = f"monitor:{settings.SECRET_KEY}" expected = b64encode(str.encode(credentials)).decode() authed = auth_type == "Basic" and given_credentials == expected if not authed and not settings.DEBUG: response = HttpResponse(status=401) response["WWW-Authenticate"] = 'Basic realm="authentik-monitoring"' return response count = len(CELERY_APP.control.ping(timeout=0.5)) GAUGE_WORKERS.set(count) for task in TaskInfo.all().values(): task.set_prom_metrics() return ExportToDjangoView(request)
def list(self, request: Request) -> Response: """List system tasks""" tasks = sorted(TaskInfo.all().values(), key=lambda task: task.task_name) return Response(TaskSerializer(tasks, many=True).data)