Include alert details in Grafana Incident alert-group endpoint (#1280)
This will be used by Grafana Incident to infer details about the incident if alert groups are present. Depends on #1279
This commit is contained in:
parent
e5a420f75a
commit
f930e3687e
1 changed files with 18 additions and 4 deletions
|
|
@ -2,17 +2,30 @@ import logging
|
|||
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.alerts.models import AlertGroup
|
||||
from common.api_helpers.mixins import EagerLoadingMixin
|
||||
from apps.alerts.models import Alert, AlertGroup
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AlertGroupSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
||||
class AlertSerializer(serializers.ModelSerializer):
|
||||
|
||||
id_oncall = serializers.CharField(read_only=True, source="public_primary_key")
|
||||
payload = serializers.JSONField(read_only=True, source="raw_request_data")
|
||||
|
||||
class Meta:
|
||||
model = Alert
|
||||
fields = [
|
||||
"id_oncall",
|
||||
"payload",
|
||||
]
|
||||
|
||||
|
||||
class AlertGroupSerializer(serializers.ModelSerializer):
|
||||
|
||||
id = serializers.CharField(read_only=True, source="public_primary_key")
|
||||
status = serializers.SerializerMethodField(source="get_status")
|
||||
link = serializers.CharField(read_only=True, source="web_link")
|
||||
alerts = AlertSerializer(many=True, read_only=True)
|
||||
|
||||
def get_status(self, obj):
|
||||
return next(filter(lambda status: status[0] == obj.status, AlertGroup.STATUS_CHOICES))[1].lower()
|
||||
|
|
@ -20,7 +33,8 @@ class AlertGroupSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = AlertGroup
|
||||
fields = [
|
||||
"id_oncall",
|
||||
"id",
|
||||
"link",
|
||||
"status",
|
||||
"alerts",
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue