diff --git a/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.json b/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.json index b1ee9bed12..8623aa73a8 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "3576f543-dc3c-4d97-9f16-5c81f35195cb", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_active_new.json b/zerver/webhooks/newrelic/fixtures/incident_active_new.json index 766aeda8ad..8d05043569 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_active_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_active_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "8ceed342-f305-4bfa-adb8-97ba93f5dd26", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_closed_new.json b/zerver/webhooks/newrelic/fixtures/incident_closed_new.json index 3412e9ff6c..224cbfab4c 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_closed_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_closed_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "f0d98b28-bf9d-49e7-b9d0-ac7cbb52e73a", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_created_new.json b/zerver/webhooks/newrelic/fixtures/incident_created_new.json index b9aa02c36b..27933f0ed3 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_created_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_created_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "8114ada3-572e-4550-a310-12375371669e", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_default_fields_new.json b/zerver/webhooks/newrelic/fixtures/incident_default_fields_new.json index 82db1eb44c..b6e258c7e4 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_default_fields_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_default_fields_new.json @@ -1,5 +1,5 @@ { - "id": 1234, + "id": "e04156e4-4cac-4f39-9d27-75d361e40a6d", "createdAt": 1605133931151, "state": "activated" } diff --git a/zerver/webhooks/newrelic/fixtures/incident_malformatted_time_new.json b/zerver/webhooks/newrelic/fixtures/incident_malformatted_time_new.json index 60f2d44ed4..6190ac0027 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_malformatted_time_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_malformatted_time_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "3881eb6c-6d57-447e-beaf-b2f610f014b0", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_missing_state_new.json b/zerver/webhooks/newrelic/fixtures/incident_missing_state_new.json index c86cad125d..f6de013941 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_missing_state_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_missing_state_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "279751d5-8ad8-41d4-adb8-9e895c58b606", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_missing_timestamp_new.json b/zerver/webhooks/newrelic/fixtures/incident_missing_timestamp_new.json index 8ca464ebc1..23536d633b 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_missing_timestamp_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_missing_timestamp_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "6eba9b54-898f-43eb-8892-e41ddca4a10f", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_state_not_recognized_new.json b/zerver/webhooks/newrelic/fixtures/incident_state_not_recognized_new.json index 81c7ad3256..f72e9abb4d 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_state_not_recognized_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_state_not_recognized_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "1d1fff5c-c723-4bf6-8458-bc63b253279e", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/fixtures/incident_time_too_large_new.json b/zerver/webhooks/newrelic/fixtures/incident_time_too_large_new.json index cb56618011..5719ff27da 100644 --- a/zerver/webhooks/newrelic/fixtures/incident_time_too_large_new.json +++ b/zerver/webhooks/newrelic/fixtures/incident_time_too_large_new.json @@ -1,6 +1,6 @@ { "incident_acknowledge_url": "https://alerts.newrelic.com/accounts/2941966/incidents/1234/acknowledge", - "id": 1234, + "id": "37d07862-e156-480f-86f9-7e8e9b7ed4f4", "details": "Violation description test.", "alertPolicyNames": ["Test policy name"], "condition_name": "Server Down", diff --git a/zerver/webhooks/newrelic/tests.py b/zerver/webhooks/newrelic/tests.py index 369527dbf0..1f56a069e7 100644 --- a/zerver/webhooks/newrelic/tests.py +++ b/zerver/webhooks/newrelic/tests.py @@ -131,7 +131,7 @@ No details. # corresponding json fixtures have "_new" trailing in the name def test_activated_new(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic = "Test policy name (8ceed342-f305-4bfa-adb8-97ba93f5dd26)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **active** for condition: **Server Down** at ``` quote @@ -147,7 +147,7 @@ Violation description test. ) def test_created_new(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic = "Test policy name (8114ada3-572e-4550-a310-12375371669e)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **created** for condition: **Server Down** """.strip() @@ -160,7 +160,7 @@ Violation description test. ) def test_closed_new(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic = "Test policy name (f0d98b28-bf9d-49e7-b9d0-ac7cbb52e73a)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **closed** for condition: **Server Down** """.strip() @@ -173,7 +173,7 @@ Violation description test. ) def test_acknowledged_new(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic = "Test policy name (3576f543-dc3c-4d97-9f16-5c81f35195cb)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **acknowledged** by **Alice** for condition: **Server Down** """.strip() @@ -199,7 +199,7 @@ Violation description test. ) def test_missing_fields_new(self) -> None: - expected_topic = "Unknown Policy (1234)" + expected_topic = "Unknown Policy (e04156e4-4cac-4f39-9d27-75d361e40a6d)" expected_message = """ [Incident](https://alerts.newrelic.com) **active** for condition: **Unknown condition** at ``` quote diff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.py index 2b54f0eb70..5d47917ce6 100644 --- a/zerver/webhooks/newrelic/view.py +++ b/zerver/webhooks/newrelic/view.py @@ -12,6 +12,7 @@ from zerver.lib.validator import ( check_list, check_none_or, check_string, + check_string_fixed_length, check_union, to_wild_value, ) @@ -59,7 +60,7 @@ def api_newrelic_webhook( ) -> HttpResponse: # Handle old format # Once old is EOLed, delete if block and keep else block - if not payload.get("id").tame(check_none_or(check_int)): + if not payload.get("id").tame(check_none_or(check_string_fixed_length(36))): info = { "condition_name": payload.get("condition_name", "Unknown condition").tame(check_string), "details": payload.get("details", "No details.").tame(check_string), @@ -160,9 +161,7 @@ def api_newrelic_webhook( policy_names_str = "Unknown Policy" topic_info = { "policy_name": policy_names_str, - "incident_id": payload.get("id", "Unknown ID").tame( - check_union([check_string, check_int]) - ), + "incident_id": payload.get("id", "Unknown ID").tame(check_string), } topic = TOPIC_TEMPLATE.format(**topic_info)