diff --git a/CHANGELOG.md b/CHANGELOG.md index 4434195e..6795515d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Fix missing timestamp value in old grafana API endpoint ([#3522](https://github.com/grafana/oncall/pull/3522)) + ## v1.3.73 (2023-12-06) ### Added diff --git a/engine/apps/integrations/tests/test_views.py b/engine/apps/integrations/tests/test_views.py index 7cfaa61a..79e28049 100644 --- a/engine/apps/integrations/tests/test_views.py +++ b/engine/apps/integrations/tests/test_views.py @@ -184,6 +184,46 @@ def test_integration_grafana_endpoint_has_alerts( ) +@patch("apps.integrations.views.create_alert") +@pytest.mark.django_db +def test_integration_old_grafana_endpoint( + mock_create_alert, settings, make_organization_and_user, make_alert_receive_channel +): + settings.DEBUG = False + + integration_type = "grafana" + organization, user = make_organization_and_user() + alert_receive_channel = make_alert_receive_channel( + organization=organization, + author=user, + integration=integration_type, + ) + + client = APIClient() + url = reverse("integrations:grafana", kwargs={"alert_channel_key": alert_receive_channel.token}) + + data = {} + now = timezone.now() + with patch("django.utils.timezone.now") as mock_now: + mock_now.return_value = now + response = client.post(url, data, format="json") + assert response.status_code == status.HTTP_200_OK + + mock_create_alert.apply_async.assert_called_once_with( + [], + { + "title": "Title", + "message": None, + "image_url": None, + "link_to_upstream_details": None, + "alert_receive_channel_pk": alert_receive_channel.pk, + "integration_unique_data": '{"evalMatches": []}', + "raw_request_data": data, + "received_at": now.isoformat(), + }, + ) + + @patch("apps.integrations.views.create_alert") @pytest.mark.parametrize( "integration_type", diff --git a/engine/apps/integrations/views.py b/engine/apps/integrations/views.py index 05ea76f3..b2f9d5c0 100644 --- a/engine/apps/integrations/views.py +++ b/engine/apps/integrations/views.py @@ -289,6 +289,7 @@ class GrafanaAPIView( }, ) else: + timestamp = timezone.now().isoformat() create_alert.apply_async( [], {