oncall-engine/engine/apps/alerts/incident_appearance/renderers/base_renderer.py
Yulya Artyukhina 35ddfab0e4
Add method to send notification bundle by SMS (#4624)
# What this PR does
Adds method to render and send notification bundle by sms.

Example of SMS message:
```
Grafana OnCall: Alert groups #1, #2, #3 and 2 more 
from stack: TestOrganization, 
integrations: Grafana Alerting and 1 more.
```

Should be merged with https://github.com/grafana/oncall/pull/4457

## Which issue(s) this PR closes
https://github.com/grafana/oncall-private/issues/2713

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-07-16 14:20:16 +00:00

44 lines
1.2 KiB
Python

import typing
from abc import ABC, abstractmethod
from django.db.models import QuerySet
from django.utils.functional import cached_property
if typing.TYPE_CHECKING:
from apps.alerts.models import Alert, AlertGroup, BundledNotification
class AlertBaseRenderer(ABC):
def __init__(self, alert: "Alert"):
self.alert = alert
@cached_property
def templated_alert(self):
return self.templater_class(self.alert).render()
@property
@abstractmethod
def templater_class(self):
raise NotImplementedError
class AlertGroupBaseRenderer(ABC):
def __init__(self, alert_group: "AlertGroup", alert: typing.Optional["Alert"] = None):
if alert is None:
alert = alert_group.alerts.first()
self.alert_group = alert_group
self.alert_renderer = self.alert_renderer_class(alert)
@property
@abstractmethod
def alert_renderer_class(self):
raise NotImplementedError
class AlertGroupBundleBaseRenderer:
MAX_ALERT_GROUPS_TO_RENDER = 3
MAX_CHANNELS_TO_RENDER = 1
def __init__(self, notifications: "QuerySet[BundledNotification]"):
self.notifications = notifications