-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add declare incident step and model (#5047)
Related to grafana/oncall-private#2831 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] 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. --------- Co-authored-by: Matias Bordese <[email protected]> Co-authored-by: Dominik <[email protected]>
- Loading branch information
1 parent
612c0e5
commit 70b7273
Showing
27 changed files
with
1,009 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
engine/apps/alerts/migrations/0059_escalationpolicy_severity_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.2.15 on 2024-09-25 20:57 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('user_management', '0022_alter_team_unique_together'), | ||
('alerts', '0058_alter_alertgroup_reason_to_skip_escalation'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='escalationpolicy', | ||
name='severity', | ||
field=models.CharField(default=None, max_length=512, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='escalationpolicy', | ||
name='step', | ||
field=models.IntegerField(choices=[(0, 'Wait'), (1, 'Notify User'), (2, 'Notify Whole Channel'), (3, 'Repeat Escalation (5 times max)'), (4, 'Resolve'), (5, 'Notify Group'), (6, 'Notify Schedule'), (7, 'Notify User (Important)'), (8, 'Notify Group (Important)'), (9, 'Notify Schedule (Important)'), (10, 'Trigger Outgoing Webhook'), (11, 'Notify User (next each time)'), (12, 'Continue escalation only if time is from'), (13, 'Notify multiple Users'), (14, 'Notify multiple Users (Important)'), (15, 'Continue escalation if >X alerts per Y minutes'), (16, 'Trigger Webhook'), (17, 'Notify all users in a Team'), (18, 'Notify all users in a Team (Important)'), (19, 'Declare Incident')], default=None, null=True), | ||
), | ||
migrations.CreateModel( | ||
name='DeclaredIncident', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('incident_id', models.CharField(db_index=True, max_length=50)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('is_active', models.BooleanField(default=True)), | ||
('channel_filter', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='declared_incidents', to='alerts.channelfilter')), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='declared_incidents', to='user_management.organization')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='alertgroup', | ||
name='declared_incident', | ||
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attached_alert_groups', to='alerts.declaredincident'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import typing | ||
from urllib.parse import urljoin | ||
|
||
from django.db import models | ||
|
||
if typing.TYPE_CHECKING: | ||
from django.db.models.manager import RelatedManager | ||
|
||
from apps.alerts.models import AlertGroup, ChannelFilter | ||
from apps.user_management.models import Organization | ||
|
||
|
||
def get_incident_url(organization, incident_id) -> str: | ||
return urljoin(organization.grafana_url, f"a/grafana-incident-app/incidents/{incident_id}") | ||
|
||
|
||
class DeclaredIncident(models.Model): | ||
attached_alert_groups: "RelatedManager['AlertGroup']" | ||
channel_filter: typing.Optional["ChannelFilter"] | ||
organization: "Organization" | ||
|
||
incident_id = models.CharField(db_index=True, max_length=50) | ||
organization = models.ForeignKey( | ||
"user_management.Organization", | ||
on_delete=models.CASCADE, | ||
related_name="declared_incidents", | ||
) | ||
channel_filter = models.ForeignKey( | ||
"alerts.ChannelFilter", | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
related_name="declared_incidents", | ||
) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
is_active = models.BooleanField(default=True) | ||
|
||
def get_incident_link(self) -> str: | ||
return get_incident_url(self.organization, self.incident_id) |
Oops, something went wrong.