Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations/thinkst: Use global time.

Niloth P253483b10ad8
diff --git a/static/images/integrations/thinkst/001.png b/static/images/integrations/thinkst/001.png
index db9a344097e..ab6ad7b7721 100644
Binary files a/static/images/integrations/thinkst/001.png and b/static/images/integrations/thinkst/001.png differ
diff --git a/zerver/webhooks/thinkst/tests.py b/zerver/webhooks/thinkst/tests.py
index b7ef318e956..4256ab18240 100644
--- a/zerver/webhooks/thinkst/tests.py
+++ b/zerver/webhooks/thinkst/tests.py
@@ -12,7 +12,7 @@ class ThinkstHookTests(WebhookTestCase):
"This is a dummy incident.\n\n"
"**Incident ID:** `aa875f255f94e3ffe40dc85cf1a8b1e0`\n"
"**Kind:** Dummy Incident\n"
- "**Timestamp:** 2020-06-09 13:59:38 (UTC)\n"
+ "**Timestamp:** <time:2020-06-09 13:59:38Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Source IP:** `2.2.2.2`\n"
"**Reverse DNS:** `attacker-ip.local`\n"
@@ -35,7 +35,7 @@ class ThinkstHookTests(WebhookTestCase):
"1.1.1.1.\n\n"
"**Incident ID:** `3f25fec9e18c7673dcc468800b7af0a6`\n"
"**Kind:** Consolidated Network Port Scan\n"
- "**Timestamp:** 2020-07-20 16:18:40 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 16:18:40Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Canary location:** dining room\n"
"**Source IP:** `1.1.1.1`\n"
@@ -60,7 +60,7 @@ class ThinkstHookTests(WebhookTestCase):
"(bar-foo) at 1.1.1.1.\n\n"
"**Incident ID:** `a7bb317ba2072415462233cef3bc615a`\n"
"**Kind:** Shared File (Re)Opened\n"
- "**Timestamp:** 2020-07-20 16:27:20 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 16:27:20Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Canary location:** dining room\n"
"**Source IP:** `1.1.1.1`\n"
@@ -87,7 +87,7 @@ class ThinkstHookTests(WebhookTestCase):
"(foo-bar) at 1.1.1.1.\n\n"
"**Incident ID:** `9060473d2da98afe494adad648495620`\n"
"**Kind:** Host Port Scan\n"
- "**Timestamp:** 2020-07-20 16:26:30 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 16:26:30Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Canary location:** dining room\n"
"**Source IP:** `1.1.1.1`\n"
@@ -109,7 +109,7 @@ class ThinkstHookTests(WebhookTestCase):
"(foo-bar) at 1.1.1.1.\n\n"
"**Incident ID:** `1ef86f5cf4090a5252c6f453c5cd46bd`\n"
"**Kind:** HTTP Login Attempt\n"
- "**Timestamp:** 2020-07-20 14:55:45 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 14:55:45Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Canary location:** dining room\n"
"**Source IP:** `1.1.1.1`\n"
@@ -134,7 +134,7 @@ class ThinkstHookTests(WebhookTestCase):
"(foo-bar) at 1.1.1.1.\n\n"
"**Incident ID:** `4ef51a936d05e0a6b4846378c8c38d2c`\n"
"**Kind:** SSH Login Attempt\n"
- "**Timestamp:** 2020-07-20 16:26:22 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 16:26:22Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Canary location:** dining room\n"
"**Source IP:** `1.1.1.1`\n"
@@ -158,7 +158,7 @@ class ThinkstHookTests(WebhookTestCase):
"This is a dummy incident.\n\n"
"**Incident ID:** `aa875f255f94e3ffe40dc85cf1a8b1e0`\n"
"**Kind:** Dummy Incident\n"
- "**Timestamp:** 2020-06-09 13:59:38 (UTC)\n"
+ "**Timestamp:** <time:2020-06-09 13:59:38Z>\n"
"**Canary IP:** `1.1.1.1`\n"
"**Source IP:** `2.2.2.2`\n"
"**Reverse DNS:** `attacker-ip.local`\n"
@@ -182,7 +182,7 @@ class ThinkstHookTests(WebhookTestCase):
"**Incident ID:** `db6f9b5528c6c6c385cb3bb63f5949c8`\n"
"**Token:** `dbwx4d68flwh2u5zku56nogu6`\n"
"**Kind:** MS Word .docx Document\n"
- "**Timestamp:** 2020-07-20 14:40:15 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 14:40:15Z>\n"
"**Triggered:** 5 times\n"
"**Accept:** `*/*`\n"
"**Accept-Encoding:** gzip, deflate\n"
@@ -209,7 +209,7 @@ class ThinkstHookTests(WebhookTestCase):
"**Incident ID:** `533395067f6d655cd19384bc6991cc0f`\n"
"**Token:** `ew5n8gqtb82m4uegrttarn2zu`\n"
"**Kind:** Remote Web Image\n"
- "**Timestamp:** 2020-07-20 16:33:12 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 16:33:12Z>\n"
"**Triggered:** 37 times\n"
"**Accept:** `image/webp,*/*`\n"
"**Accept-Encoding:** gzip, deflate\n"
@@ -240,7 +240,7 @@ class ThinkstHookTests(WebhookTestCase):
"**Incident ID:** `db6f9b5528c6c6c385cb3bb63f5949c8`\n"
"**Token:** `dbwx4d68flwh2u5zku56nogu6`\n"
"**Kind:** MS Word .docx Document\n"
- "**Timestamp:** 2020-07-20 14:40:15 (UTC)\n"
+ "**Timestamp:** <time:2020-07-20 14:40:15Z>\n"
"**Triggered:** 5 times\n"
"**Accept:** `*/*`\n"
"**Accept-Encoding:** gzip, deflate\n"
diff --git a/zerver/webhooks/thinkst/view.py b/zerver/webhooks/thinkst/view.py
index 7cc81eb988f..8fc2d87f6c2 100644
--- a/zerver/webhooks/thinkst/view.py
+++ b/zerver/webhooks/thinkst/view.py
@@ -73,7 +73,11 @@ def body(message: WildValue) -> str:
body += f"**Kind:** {message['Description'].tame(check_string)}\n"
if "Timestamp" in message:
- body += f"**Timestamp:** {message['Timestamp'].tame(check_string)}\n"
+ timestamp = message["Timestamp"].tame(check_string)
+ # Thinkst datetime format: https://help.canary.tools/hc/en-gb/articles/360012727777-How-do-I-configure-notifications-for-a-Generic-Webhook#h_01K71QZ806C5D49RYB6RBXSZ1B
+ # Convert "YYYY-MM-DD HH:MM:SS (UTC)" -> "YYYY-MM-DD HH:MM:SSZ"
+ formatted_timestamp = timestamp.replace("(UTC)", "").strip() + "Z"
+ body += f"**Timestamp:** <time:{formatted_timestamp}>\n"
if "CanaryIP" in message:
body += f"**Canary IP:** `{message['CanaryIP'].tame(check_string)}`\n"