opensearch-project / notifications

Notifications plugin for OpenSearch enables other plugins to send notifications via Email, Slack, Amazon Chime, Custom web-hook etc channels
Apache License 2.0
25 stars 64 forks source link

[BUG] Unable to use MS Teams Workflow webhook url in Channels #942

Open sharathganga opened 1 month ago

sharathganga commented 1 month ago

What is the bug? Microsoft is deprecating the Office 365 connectors for Teams and we need to utilize the Workflows webhook URL to post messages to Teams channels. I've generated a webhook URL but am unable to use it in OpenSearch.

Refer: https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/

How can one reproduce the bug?

Method 1:

Go to 'Notifications -> Channels -> Create Channel' Set a channel name Select Channel Type -> Microsoft Teams Webhook URL -> https://prod-XX.westeurope.logic.azure.com:443/workflows/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Click "Send Test Message"

Error: [status_exception] Wrong Microsoft Teams url. Should contain "webhook.office.com"

Method 2:

Select Channel Type -> Custom webhook Method -> POST Webhook URL -> https://prod-XX.westeurope.logic.azure.com:443/workflows/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Click "Send Test Message"

Error: [status_exception] {"event_status_list": [{"config_id":"666cK5EB6cKDPdC7sDsE","config_type":"webhook","config_name":"temp-MS Teams Workflow Test","email_recipient_status":[],"delivery_status":{"status_code":"500","status_text":"Failed to send webhook message Failed: {\"error\":{\"code\":\"InvalidRequestContent\",\"message\":\"The request content is not valid and could not be deserialized: 'Unexpected character encountered while parsing value: T. Path '', line 0, position 0.'.\"}}"}}]}

What is your host/environment?

AWS OpenSearch 2.11

Hailong-am commented 1 month ago

@sharathganga as a workaround you can select slack and input the workflows URL for teams

sharathganga commented 1 month ago

@Hailong-am It still fails to send a test message when I use Slack Channel type but this time with a different error:

[status_exception] {"event_status_list": [{"config_id":"B6SLLJEBJpQT_mdoZxeG","config_type":"slack","config_name":"temp-Test","email_recipient_status":[],"delivery_status":{"status_code":"500","status_text":"Failed to send webhook message Failed: {\"error\":{\"code\":\"TriggerInputSchemaMismatch\",\"message\":\"The input body for trigger 'manual' of type 'Request' did not match its schema definition. Error details: 'Invalid type. Expected Object but got String.'.\"}}"}}]}

Hailong-am commented 1 month ago

@Hailong-am It still fails to send a test message when I use Slack Channel type but this time with a different error:

[status_exception] {"event_status_list": [{"config_id":"B6SLLJEBJpQT_mdoZxeG","config_type":"slack","config_name":"temp-Test","email_recipient_status":[],"delivery_status":{"status_code":"500","status_text":"Failed to send webhook message Failed: {\"error\":{\"code\":\"TriggerInputSchemaMismatch\",\"message\":\"The input body for trigger 'manual' of type 'Request' did not match its schema definition. Error details: 'Invalid type. Expected Object but got String.'.\"}}"}}]}

@sharathganga can you share an example request for new webhook? i need this to check whether the schema has changed.

Hailong-am commented 1 month ago

@opensearch-project/admin please transfer this to notification repo

Nils-543 commented 1 month ago

Hi, I have the same issue, do you already have something new regarding this issue?

dcopestake commented 4 weeks ago

Unfortunately the issue here is that the suggested migration path for moving away from the "Incoming Webhook" Office 365 Connector is to use a Power Automate Workflow with the "When a Teams webhook request is received" as the trigger, however this does not support the same basic JSON schema that the original connector supported and instead will only accept Adaptive Card data instead.

It is possible to temporarily work around this issue by using the OpenSearch "Custom webhook" notification channel type instead. This will allow you to define any webhook URL you want, and then within the actual monitor action you can format the message to include the correct JSON. For example something like this:

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "type": "AdaptiveCard",
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "version": "1.3",
                "body": [
                    {
                        "type": "TextBlock",
                        "size": "Medium",
                        "weight": "Bolder",
                        "text": "{{ctx.monitor.name}}"
                    },
                    {
                        "type": "TextBlock",
                        "text": "{{ctx.trigger.name}}"
                    }
                ]
            }
        }
    ]
}

Obviously replacing the Mustache template variables for whatever is appropriate for your situation.

GerardMorgan commented 3 weeks ago

It's possible to configure the Teams workflow(PowerAutomate) webhooks any way you want. You don't have to adopt the default adaptive-card schema. I've managed to get the custom webhook to trigger with the OpenSearch action message defined with a Mustache expression as:

{ "text": "{{#ctx.results.0.hits.hits.0}} {{_source.["k8s.event.reason"]}}<br> {{_source.body}} {{/ctx.results.0.hits.hits.0}}" }

But having trouble accessing the JSON attributes that have dotted names ie.: ["k8s.event.reason"]. Is there a syntax to escape those, so that they are parseable and get rendered in the message

dblock commented 2 weeks ago

[Catch All Triage - 1, 2, 3, 4, 5]