Пример #1
0
 def sync_status(self, request: Request, slug: str) -> Response:
     """Get source's sync status"""
     source = self.get_object()
     task = TaskInfo.by_name(f"ldap_sync_{slugify(source.name)}")
     if not task:
         raise Http404
     return Response(TaskSerializer(task, many=False).data)
Пример #2
0
 def sync_status(self, request: Request, slug: str) -> Response:
     """Get source's sync status"""
     source = self.get_object()
     results = []
     for sync_class in [
             UserLDAPSynchronizer,
             GroupLDAPSynchronizer,
             MembershipLDAPSynchronizer,
     ]:
         sync_name = sync_class.__name__.replace("LDAPSynchronizer",
                                                 "").lower()
         task = TaskInfo.by_name(f"ldap_sync_{source.slug}_{sync_name}")
         if task:
             results.append(task)
     return Response(TaskSerializer(results, many=True).data)
Пример #3
0
 def retry(self, request: Request, pk=None) -> Response:
     """Retry task"""
     task = TaskInfo.by_name(pk)
     if not task:
         raise Http404
     try:
         task_module = import_module(task.task_call_module)
         task_func = getattr(task_module, task.task_call_func)
         task_func.delay(*task.task_call_args, **task.task_call_kwargs)
         messages.success(
             self.request,
             _("Successfully re-scheduled Task %(name)s!" % {"name": task.task_name}),
         )
         return Response(status=204)
     except (ImportError, AttributeError):  # pragma: no cover
         # if we get an import error, the module path has probably changed
         task.delete()
         return Response(status=500)
Пример #4
0
    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)
Пример #5
0
 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)
Пример #6
0
 def retrieve(self, request: Request, pk=None) -> Response:
     """Get a single system task"""
     task = TaskInfo.by_name(pk)
     if not task:
         raise Http404
     return Response(TaskSerializer(task, many=False).data)