notifications icon indicating copy to clipboard operation
notifications copied to clipboard

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

Open sharathganga opened this issue 1 year ago • 8 comments
trafficstars

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

sharathganga avatar Aug 07 '24 06:08 sharathganga

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

Hailong-am avatar Aug 07 '24 09:08 Hailong-am

@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 avatar Aug 07 '24 11:08 sharathganga

@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 avatar Aug 08 '24 02:08 Hailong-am

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

Hailong-am avatar Aug 08 '24 02:08 Hailong-am

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

Nils-543 avatar Aug 13 '24 09:08 Nils-543

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.

dcopestake avatar Aug 15 '24 15:08 dcopestake

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

GerardMorgan avatar Aug 19 '24 18:08 GerardMorgan

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

dblock avatar Aug 26 '24 16:08 dblock

Hi Team,

Has there been any newer developments regarding this Git? Is the configuration of MS Team integration on OpenSearch Dev still being worked on or was it completed already?

Thank you

andisiw3 avatar May 21 '25 12:05 andisiw3

Experiencing the same issue with OpenSearch 2.19. What's the current workaround?

fire2 avatar Jun 18 '25 16:06 fire2

Here's what I've done that works:

  1. Configure your webhook in Teams the same as below Image

  2. In OpenSearch create a Channel using the Custom Webhook option, use the POST method and Content-Type w/ application/json in the header. FYI this test button will not work!

  3. When setting up the monitor in OpenSearch, under Triggers > Action > Message Field, input your text formatted in JSON. Example:

{ "text": ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\nMonitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n - Trigger: {{ctx.trigger.name}}\n - Severity: {{ctx.trigger.severity}}\n - No of Error hits : {{ctx.results.0.hits.total.value}}\n - Period start: {{ctx.periodStart}}\n - Period end: {{ctx.periodEnd}}\n\nKibana Link: https://example.com/_dashboards/goto/b9b1e0f87c5c806c6fca5?security_tenant=global \n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" }

  1. If you use the test button located within the Action setup it should work if you did everything correctly, hope this helps!

aparnell572 avatar Jul 01 '25 00:07 aparnell572

I would like to use teams notifications within in snapshot policy. Any way workarounds for that?

mario-lukic avatar Oct 30 '25 10:10 mario-lukic