2017-08-14 18:03:36 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2022-02-07 23:24:56 +01:00
|
|
|
class OpsgenieHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "opsgenie"
|
2018-03-16 22:53:50 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/opsgenie?&api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "opsgenie"
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_acknowledge_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: Acknowledge
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"acknowledge",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_addnote_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: AddNote
|
|
|
|
* **Note**: note to test alert
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"addnote",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_addrecipient_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: AddRecipient
|
|
|
|
* **Recipient**: team2_escalation
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"addrecipient",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_addtags_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: AddTags
|
|
|
|
* **Tags added**: tag1,tag2,tag3
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`, `tag3`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"addtags",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_addteam_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: AddTeam
|
|
|
|
* **Team added**: team2
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"addteam",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_assignownership_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: AssignOwnership
|
|
|
|
* **Assigned owner**: user2@ifountain.com
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"assignownership",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_close_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: Close
|
|
|
|
* **Message**: test alert
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"close",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_create_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Webhook"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Webhook](https://app.opsgenie.com/alert/V2#/show/ec03dad6-62c8-4c94-b38b-d88f398e900f):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: Create
|
|
|
|
* **Message**: another alert
|
|
|
|
* **Tags**: `vip`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"create",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_customaction_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: TestAction
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"customaction",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_delete_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: Delete
|
|
|
|
* **Message**: test alert
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"delete",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_escalate_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Webhook_Test"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Webhook_Test](https://app.opsgenie.com/alert/V2#/show/7ba97e3a-d328-4b5e-8f9a-39e945a3869a):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: Escalate
|
|
|
|
* **Escalation**: test_esc
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"escalate",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_removetags_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: RemoveTags
|
|
|
|
* **Tags removed**: tag3
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"removetags",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_takeownership_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Webhook"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Webhook](https://app.opsgenie.com/alert/V2#/show/8a745a79-3ed3-4044-8427-98e067c0623c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: TakeOwnership
|
|
|
|
* **Message**: message test
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"takeownership",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-08-14 18:03:36 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_unacknowledge_alert(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Integration1"
|
2019-05-09 04:49:54 +02:00
|
|
|
expected_message = """
|
2022-02-07 23:24:56 +01:00
|
|
|
[Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c):
|
2019-05-09 04:49:54 +02:00
|
|
|
* **Type**: UnAcknowledge
|
|
|
|
* **Message**: test alert
|
|
|
|
* **Tags**: `tag1`, `tag2`
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"unacknowledge",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|