

@decorators.list_route()
def stats(self, request, *args, **kwargs):
    '\n        To get count of alerts per severities - run **GET** request against */api/alerts/stats/*.\n        This endpoint supports all filters that are available for alerts list (*/api/alerts/*).\n\n        Response example:\n\n        .. code-block:: javascript\n\n            {\n                "debug": 2,\n                "error": 1,\n                "info": 1,\n                "warning": 1\n            }\n        '
    queryset = self.filter_queryset(self.get_queryset())
    alerts_severities_count = queryset.values('severity').annotate(count=Count('severity'))
    severity_names = dict(models.Alert.SeverityChoices.CHOICES)
    alerts_severities_count = {severity_names[asc['severity']].lower(): asc['count'] for asc in alerts_severities_count}
    for severity_name in severity_names.values():
        if (severity_name.lower() not in alerts_severities_count):
            alerts_severities_count[severity_name.lower()] = 0
    return response.Response(alerts_severities_count, status=status.HTTP_200_OK)

dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/logging/views.py AlertViewSet.stats/original