From 61956c4f11eafab1e4db48634433ead701ce2538 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Wed, 16 Aug 2023 17:15:38 -0300 Subject: [PATCH 1/4] Add alertmanager integration for heartbeat support --- engine/apps/integrations/metadata/heartbeat/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/apps/integrations/metadata/heartbeat/__init__.py b/engine/apps/integrations/metadata/heartbeat/__init__.py index 1c987dc02c..464f11d675 100644 --- a/engine/apps/integrations/metadata/heartbeat/__init__.py +++ b/engine/apps/integrations/metadata/heartbeat/__init__.py @@ -4,6 +4,7 @@ Filename MUST match INTEGRATION_TO_REVERSE_URL_MAP. """ +import apps.integrations.metadata.heartbeat.alertmanager # noqa import apps.integrations.metadata.heartbeat.elastalert # noqa import apps.integrations.metadata.heartbeat.formatted_webhook # noqa import apps.integrations.metadata.heartbeat.grafana # noqa From 2f668a59dc170169f608bde8433a7cbebea4de9e Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Wed, 16 Aug 2023 17:17:53 -0300 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b87074aceb..4487584def 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix issue with updating "Require resolution note" setting by @Ferril ([#2782](https://github.com/grafana/oncall/pull/2782)) - Don't send notifications about past SSRs when turning on info notifications by @vadimkerr ([#2783](https://github.com/grafana/oncall/pull/2783)) - Add schedule shift type validation on create/preview ([#2789](https://github.com/grafana/oncall/pull/2789)) +- Add alertmanager integration for heartbeat support ([2807](https://github.com/grafana/oncall/pull/2807)) ## v1.3.23 (2023-08-10) From 5ceaa745d6f2c694c234dd0a03c4dc2ff163a438 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Wed, 16 Aug 2023 17:40:09 -0300 Subject: [PATCH 3/4] Add test --- .../alerts/tests/test_alert_receiver_channel.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/engine/apps/alerts/tests/test_alert_receiver_channel.py b/engine/apps/alerts/tests/test_alert_receiver_channel.py index ab94e6a405..a4628cb726 100644 --- a/engine/apps/alerts/tests/test_alert_receiver_channel.py +++ b/engine/apps/alerts/tests/test_alert_receiver_channel.py @@ -206,3 +206,17 @@ def test_get_or_create_manual_integration_deleted_team(make_organization, make_t organization=organization, team=None, integration=AlertReceiveChannel.INTEGRATION_MANUAL, defaults={} ) assert integration == general_manual + + +@pytest.mark.django_db +@pytest.mark.parametrize( + "integration", + [ + AlertReceiveChannel.INTEGRATION_LEGACY_ALERTMANAGER, + AlertReceiveChannel.INTEGRATION_ALERTMANAGER, + ], +) +def test_alertmanager_available_for_heartbeat(make_organization, make_alert_receive_channel, integration): + organization = make_organization() + alert_receive_channel = make_alert_receive_channel(organization, integration=integration) + assert alert_receive_channel.is_available_for_integration_heartbeat From 7db9c9bb3f9f26001f1f428eb5b42eaf4412076b Mon Sep 17 00:00:00 2001 From: Innokentii Konstantinov Date: Thu, 17 Aug 2023 09:08:05 +0800 Subject: [PATCH 4/4] Fix heartbeat restored payload --- .../integrations/metadata/heartbeat/alertmanager.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/engine/apps/integrations/metadata/heartbeat/alertmanager.py b/engine/apps/integrations/metadata/heartbeat/alertmanager.py index 7077efc354..ea7a2648c2 100644 --- a/engine/apps/integrations/metadata/heartbeat/alertmanager.py +++ b/engine/apps/integrations/metadata/heartbeat/alertmanager.py @@ -37,7 +37,10 @@ "numResolved": 0, "commonLabels": {"alertname": "OnCallHeartBeatMissing"}, "truncatedAlerts": 0, - "commonAnnotations": {}, + "commonAnnotations": { + "title": heartbeat_expired_title, + "description": heartbeat_expired_message, + }, } heartbeat_restored_title = heartbeat_text.heartbeat_restored_title @@ -61,7 +64,7 @@ "generatorURL": "", }, ], - "status": "firing", + "status": "resolved", "version": "4", "groupKey": '{}:{alertname="OnCallHeartBeatMissing"}', "receiver": "", @@ -71,5 +74,8 @@ "numResolved": 1, "commonLabels": {"alertname": "OnCallHeartBeatMissing"}, "truncatedAlerts": 0, - "commonAnnotations": {}, + "commonAnnotations": { + "title": heartbeat_restored_title, + "description": heartbeat_restored_message, + }, }