Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
newrelic: ids are uuids, not integers.
Alex Vandiverdb203cfc2d82
diff --git a/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.json b/zerver/webhooks/newrelic/fixtures/incident_acknowledged_new.jsonindex b1ee9bed12a..8623aa73a89 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.jsonindex 766aeda8ad5..8d050435690 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.jsonindex 3412e9ff6cc..224cbfab4c0 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.jsonindex b9aa02c36b8..27933f0ed36 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.jsonindex 82db1eb44cc..b6e258c7e4e 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.jsonindex 60f2d44ed40..6190ac00278 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.jsonindex c86cad125d8..f6de013941e 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.jsonindex 8ca464ebc14..23536d633b5 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.jsonindex 81c7ad3256e..f72e9abb4d7 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.jsonindex cb56618011b..5719ff27da3 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.pyindex 369527dbf01..1f56a069e7e 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 namedef 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 <time:2020-11-11 22:32:11.151000+00:00>``` 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 <time:2020-11-11 22:32:11.151000+00:00>``` quotediff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.pyindex f4f1be24d63..3a4aaffe590 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,)from zerver.lib.webhooks.common import check_send_webhook_message, unix_milliseconds_to_timestamp@@ -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)