-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5138 from grafana/dev
v1.10.3
- Loading branch information
Showing
27 changed files
with
1,000 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
# Generated by Django 4.2.15 on 2024-10-04 16:38 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('user_management', '0022_alter_team_unique_together'), | ||
('alerts', '0059_escalationpolicy_severity_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RelatedIncident', | ||
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)), | ||
('attached_alert_groups', models.ManyToManyField(related_name='related_incidents', to='alerts.alertgroup')), | ||
('channel_filter', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='related_incidents', to='alerts.channelfilter')), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='related_incidents', to='user_management.organization')), | ||
], | ||
options={ | ||
'unique_together': {('organization', 'incident_id')}, | ||
}, | ||
), | ||
] |
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
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,48 @@ | ||
import typing | ||
from urllib.parse import urljoin | ||
|
||
from django.db import models | ||
|
||
from common.constants.plugin_ids import PluginID | ||
|
||
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/{PluginID.INCIDENT}/incidents/{incident_id}") | ||
|
||
|
||
class RelatedIncident(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="related_incidents", | ||
) | ||
channel_filter = models.ForeignKey( | ||
"alerts.ChannelFilter", | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
related_name="related_incidents", | ||
) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
is_active = models.BooleanField(default=True) | ||
|
||
attached_alert_groups = models.ManyToManyField( | ||
"alerts.AlertGroup", | ||
related_name="related_incidents", | ||
) | ||
|
||
class Meta: | ||
unique_together = ("organization", "incident_id") | ||
|
||
def get_incident_link(self) -> str: | ||
return get_incident_url(self.organization, self.incident_id) |
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
Oops, something went wrong.