diff --git a/CHANGELOG.md b/CHANGELOG.md index 82ae90ca..1b9f5ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix schedule final_events datetime filtering when splitting override ([#2715](https://github.com/grafana/oncall/pull/2715)) - Fix swap requests event filter limits in schedule events ([#2716](https://github.com/grafana/oncall/pull/2716)) +- Fix Alerting contact point auto-creation ([2721](https://github.com/grafana/oncall/pull/2721)) ## v1.3.21 (2023-08-01) diff --git a/engine/apps/alerts/models/alert_receive_channel.py b/engine/apps/alerts/models/alert_receive_channel.py index b07ca6c5..d01ffb24 100644 --- a/engine/apps/alerts/models/alert_receive_channel.py +++ b/engine/apps/alerts/models/alert_receive_channel.py @@ -18,7 +18,7 @@ from emoji import emojize from apps.alerts.grafana_alerting_sync_manager.grafana_alerting_sync import GrafanaAlertingSyncManager from apps.alerts.integration_options_mixin import IntegrationOptionsMixin from apps.alerts.models.maintainable_object import MaintainableObject -from apps.alerts.tasks import disable_maintenance +from apps.alerts.tasks import disable_maintenance, sync_grafana_alerting_contact_points from apps.base.messaging import get_messaging_backend_from_id from apps.base.utils import live_settings from apps.integrations.legacy_prefix import remove_legacy_prefix @@ -652,6 +652,20 @@ def listen_for_alertreceivechannel_model_save( metrics_add_integration_to_cache(instance) + if instance.integration in { + AlertReceiveChannel.INTEGRATION_GRAFANA_ALERTING, + AlertReceiveChannel.INTEGRATION_LEGACY_GRAFANA_ALERTING, + }: + if created: + instance.grafana_alerting_sync_manager.create_contact_points() + # do not trigger sync contact points if field "is_finished_alerting_setup" was updated + elif ( + kwargs is None + or not kwargs.get("update_fields") + or "is_finished_alerting_setup" not in kwargs["update_fields"] + ): + sync_grafana_alerting_contact_points.apply_async((instance.pk,), countdown=5) + elif instance.deleted_at: metrics_remove_deleted_integration_from_cache(instance) else: