From b6f054300e8c575bf66bd6fcc6d11c865cb524cb Mon Sep 17 00:00:00 2001 From: minix Date: Mon, 15 Jul 2024 09:24:13 +0700 Subject: [PATCH 1/5] Add new MS Workflow Webhook --- globalConfig.json | 51 +++++-------------- ...lert_ms_teams_publish_to_channel_helper.py | 50 +++++++++++++++++- package/default/alert_actions.conf | 1 + .../alerts/ms_teams_publish_to_channel.html | 18 +++++++ 4 files changed, 79 insertions(+), 41 deletions(-) diff --git a/globalConfig.json b/globalConfig.json index 1fcf1bd..2829426 100644 --- a/globalConfig.json +++ b/globalConfig.json @@ -99,41 +99,7 @@ "title": "Proxy" }, { - "name": "logging", - "entity": [ - { - "type": "singleSelect", - "label": "Log level", - "options": { - "disableSearch": true, - "autoCompleteFields": [ - { - "value": "DEBUG", - "label": "DEBUG" - }, - { - "value": "INFO", - "label": "INFO" - }, - { - "value": "WARNING", - "label": "WARNING" - }, - { - "value": "ERROR", - "label": "ERROR" - }, - { - "value": "CRITICAL", - "label": "CRITICAL" - } - ] - }, - "defaultValue": "INFO", - "field": "loglevel" - } - ], - "title": "Logging" + "type": "loggingTab" }, { "name": "additional_parameters", @@ -199,7 +165,7 @@ "name": "ms_teams_publish_to_channel", "label": "MS teams publish to channel", "description": "Publish a message to a Microsoft Teams channel", - "activeResponse": { + "adaptiveResponse": { "task": [ "Create", "Update", @@ -223,9 +189,16 @@ } ], "drilldownUri": "search?q=search%20index%3D_internal%20OR%20index%3Dcim_modaction%20sourcetype%3Dta:msteams:alert:log&earliest=0&latest=", - "sourcetype": "ta:msteams:alert:log" + "sourcetype": "ta:msteams:alert:log", + "supportsCloud": true }, "entity": [ + { + "type": "checkbox", + "label": "Does use new webhook?", + "help": "Use new MS workflow webhook", + "field": "alert_ms_teams_new_webhook" + }, { "type": "text", "label": "Override default Webhook URL:", @@ -409,7 +382,7 @@ "restRoot": "ta_ms_teams_alert_action", "version": "1.1.6", "displayName": "MS Teams alert action", - "schemaVersion": "0.0.3", - "_uccVersion": "5.39.1" + "schemaVersion": "0.0.7", + "_uccVersion": "5.48.0" } } diff --git a/package/bin/ta_ms_teams_alert_action/modalert_ms_teams_publish_to_channel_helper.py b/package/bin/ta_ms_teams_alert_action/modalert_ms_teams_publish_to_channel_helper.py index e85dfd6..a0a2967 100644 --- a/package/bin/ta_ms_teams_alert_action/modalert_ms_teams_publish_to_channel_helper.py +++ b/package/bin/ta_ms_teams_alert_action/modalert_ms_teams_publish_to_channel_helper.py @@ -179,6 +179,35 @@ def process_event(helper, *args, **kwargs): # data facts data_json_facts = '"facts": [\n' + data_json_attachments = ( + '"type": "exampleType",\n' + + '"attachments": [\n' + + ' {\n' + + ' "contentType": "application/vnd.microsoft.card.adaptive",\n' + + ' "content": {\n' + + ' "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",\n' + + ' "type": "AdaptiveCard",\n' + + ' "version": "1.2",\n' + + ' "body": [\n' + + ' {\n' + + ' "type": "TextBlock",\n' + + ' "size": "Medium",\n' + + ' "weight": "Bolder",\n' + + ' "text": "' + alert_ms_teams_activity_title + '"\n' + + ' },\n' + + ' {\n' + + ' "type": "TextBlock",\n' + + ' "text": "",\n' + + ' "wrap": true\n' + + ' },\n' + + ' {\n' + + ' "type": "FactSet",\n' + + ' "facts": [\n' + ) + + # Set to use new MS webhook + alert_ms_teams_new_webhook = helper.get_param("alert_ms_teams_new_webhook") == "1" + helper.log_info(f"Use new MS workflow Webhook. Value is {alert_ms_teams_new_webhook}.") # Fields ordering in the message publication, defaults to alphabetical ordering alert_ms_teams_fields_order = helper.get_param("alert_ms_teams_fields_order") @@ -268,18 +297,32 @@ def process_event(helper, *args, **kwargs): if count != 0: data_json_facts = data_json_facts + "," + data_json_attachments = data_json_attachments + "," key = checkstr(key) value = checkstr(value) data_json_facts = data_json_facts + "{\n" data_json_facts = data_json_facts + '"name": "' + key + '",\n' data_json_facts = data_json_facts + '"value": "' + value + '"\n' data_json_facts = data_json_facts + "}\n" + # Add attachments new webhook + data_json_attachments += '{\n' + data_json_attachments += '"title": "' + key + ':",\n' + data_json_attachments += '"value": "' + value + '"\n' + data_json_attachments += '}\n' count += 1 # helper.log_debug("count={}".format(count)) + + data_json_attachments += ' ]\n' + data_json_attachments += ' }\n' + data_json_attachments += ' ]\n' + data_json_attachments += ' }\n' + data_json_attachments += ' }\n' + data_json_attachments += ']' data_json_facts = data_json_facts + "]," - data_json = data_json + data_json_facts + if not (alert_ms_teams_new_webhook): + data_json = data_json + data_json_facts # MS teams action, this is optional @@ -361,6 +404,9 @@ def process_event(helper, *args, **kwargs): # terminate the sections pattern data_json = data_json + "\n" + '"markdown": false' + "\n" + "}]" + if(alert_ms_teams_new_webhook): + data_json = data_json + ",\n" + data_json_attachments + # Actions statuses has_action1 = False has_action2 = False @@ -569,7 +615,7 @@ def process_event(helper, *args, **kwargs): use_proxy=opt_use_proxy, ) # No http exception, but http post was not successful - if response.status_code not in (200, 201, 204): + if response.status_code not in (200, 201, 202, 204): helper.log_error( "Microsoft Teams publish to channel has failed!. " diff --git a/package/default/alert_actions.conf b/package/default/alert_actions.conf index 65cd9f7..10dd28c 100644 --- a/package/default/alert_actions.conf +++ b/package/default/alert_actions.conf @@ -5,6 +5,7 @@ param._cam = {"task": ["Create", "Update", "Communicate"], "subject": ["incident python.version = python3 is_custom = 1 payload_format = json +param.alert_ms_teams_new_webhook = false param.alert_ms_teams_url = param.alert_ms_teams_activity_title = param.alert_ms_teams_fields_list = diff --git a/package/default/data/ui/alerts/ms_teams_publish_to_channel.html b/package/default/data/ui/alerts/ms_teams_publish_to_channel.html index 0422d02..af9e8e5 100644 --- a/package/default/data/ui/alerts/ms_teams_publish_to_channel.html +++ b/package/default/data/ui/alerts/ms_teams_publish_to_channel.html @@ -1,4 +1,22 @@
+
+ +
+ + + If you want to use new MS workflow webhook, check this + +
+