louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
57.45k stars 5.19k forks source link

teams_workflow #4934

Open vanurag63 opened 3 months ago

vanurag63 commented 3 months ago

⚠️ Please verify that this question has NOT been raised before.

🛡️ Security Policy

📝 Describe your problem

i unable to connect my webhook with the workflow. the teams is asking for the adptive card. can you give me the steps to do this.

i have found in internet but unable to get the solution.

📝 Error Message(s) or Log

No response

🐻 Uptime-Kuma Version

Version: 1.23.3 Frontend Version: 1.23.3

💻 Operating System and Arch

ubuntu

🌐 Browser

chrome

🖥️ Deployment Environment

vguttmann commented 3 months ago

The notification for Teams is intended to be used for webhooks created for Teams channels, not for Workflows. However, Microsoft is retiring Connectors in Teams, which is needed for channel webhooks.

Currently, you need to define a custom data schema in the generic webhook notification

vanurag63 commented 3 months ago

can you help me with that. can you provide me the documentation. im unable to define the schema

vguttmann commented 3 months ago

I don't know the schema myself, but I have opened a feature request to hopefully get something working - I'm also just a user who is annoyed with Microsoft retiring the Teams Webhooks https://github.com/louislam/uptime-kuma/issues/4937

vanurag63 commented 3 months ago

@vguttmann is there any other option for now to migrate to workflow.

vguttmann commented 3 months ago

I don't know. Existing Webhooks will continue working until October, and you can still create new webhooks. In the meantime, there should be a PR that fixes this, I think

vanurag63 commented 3 months ago

@vguttmann after october there will be a fix. let hope.

vanurag63 commented 3 months ago

@louislam can you give update on this

CommanderStorm commented 3 months ago

See my comment from https://github.com/louislam/uptime-kuma/pull/4538#issuecomment-2227995155

Using Workflows instead of webhooks also means changing the bits of documentation surrounding that. If you want to rebase this change, the contribution guide is here

image

=> instead of expecting other people to do the work, consider helping out

Tabisch commented 2 months ago

I made a PR to fix this in the project directly. For the interim I've made a docker image that converts the calls to the new workflow webhooks so we have something that works until there is a proper fix. https://github.com/Tabisch/uptime-kuma-teams-webhook-shim

tracyhoward commented 2 months ago

See my comment from #4538 (comment)

Using Workflows instead of webhooks also means changing the bits of documentation surrounding that. If you want to rebase this change, the contribution guide is here image

=> instead of expecting other people to do the work, consider helping out

We are really only in need of documentation updates so that the changes can be merged into a "patch" release; correct? If that is true; i will seek out some bandwidth to document/screenshot new PowerAutomate Workflow basic guidance

CommanderStorm commented 2 months ago

Help documenting this would be appreciated ^^

kaaac commented 2 months ago

Workflows webhook requires receiving a payload with attachments in the format:

{
    "type": "message",
    "attachments": []
}

And each of the attachments must be compliant with the Adaptive Cards schema. For example:

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "type": "AdaptiveCard",
                "version": "1.3",
                "body": [
                    {
                        "type" : "Container",
                        "showBorder" : true,
                        "roundedCorners" : true,
                        "items" : [
                            {
                                "type" : "TextBlock",
                                "text" : "Example Message",
                                "weight" : "Bolder",
                                "wrap" : "true"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

The webhook notification only allows me to configure payload when selecting "Request Body" option "Custom Body".

image

Unfortunately, when I try to send I get the following message:

Error: AxiosError: Request failed with status code 400 {"error":{"code":"InvalidRequestContent","message":"The input body for trigger 'manual' of type 'Request' must be of type JSON, but was of type 'application/x-www-form-urlencoded'."}}

When selecting the remaining options for "Request body" there is no possibility to define your own schema.

image

Maybe someone has an idea how to get around this?

Cheers

meako689 commented 2 months ago

@kaaac

image

Sending content type as header should do the trick.

tracyhoward commented 2 months ago

Help documenting this would be appreciated ^^

I have created some markdown documentation with screenshots for creating the proper workflow. I am not a front-end developer and I don't want to waste anybody's time with a PR showing the documentation of how to set this stuff up.

I really just wanted to provide the basic flow which makes this bugfix work. Please advise on how you would like me to proceed? I can paste everything here in a .md post or go through the PR process (with your guidance on the structure of the source files for documentation).

either way will be the same result thanks

tracyhoward commented 2 months ago

Setup Notifications with Teams, Power Automate and Uptime-Kuma

microsoft365

templateCreation

connectionContinue

editContinue

editNewFlow

webhookUrl

if using your personal account you may need to make an additional edit as seen in the following steps

finalEdit

That should allow for you to set the webhook URL in Uptime-Kuma to post to the Teams channel of your choice.

here's a curl command that you can use to test:

curl -X POST \
        -H "Content-type: application/json" \
        -d "{
            \"type\": \"message\",
            \"summary\": \"here is an uptime-kuma alert\",
            \"attachments\": [
                {
                    \"contentType\": \"application/vnd.microsoft.card.adaptive\",
                    \"contentUrl\": \"\",
                    \"content\": {
                        \"type\": \"AdaptiveCard\",
                        \"body\": [
                            {
                                \"type\": \"Container\",
                                \"verticalContentAlignment\": \"Center\",
                                \"items\": [
                                    {
                                        \"type\": \"ColumnSet\",
                                        \"style\": \"Good\",
                                        \"columns\": [
                                            {
                                                \"type\": \"Column\",
                                                \"width\": \"auto\",
                                                \"verticalContentAlignment\": \"Center\",
                                                \"items\": [
                                                    {
                                                        \"type\": \"Image\",
                                                        \"width\": \"32px\",
                                                        \"style\": \"Person\",
                                                        \"url\": \"https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png\",
                                                        \"altText\": \"Uptime Kuma Logo\"
                                                    }
                                                ]
                                            },
                                            {
                                                \"type\": \"Column\",
                                                \"width\": \"stretch\",
                                                \"items\": [
                                                    {
                                                        \"type\": \"TextBlock\",
                                                        \"size\": \"Medium\",
                                                        \"weight\": \"Bolder\",
                                                        \"text\": \"here is some text from uptime-kuma\",
                                                    },
                                                    {
                                                        \"type\": \"TextBlock\",
                                                        \"size\": \"Small\",
                                                        \"weight\": \"Default\",
                                                        \"text\": \"Uptime Kuma Alert\",
                                                        \"isSubtle\": \"true\",
                                                        \"spacing\": \"None\"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                \"type\": \"FactSet\",
                                \"facts\": [
                                    {
                                        \"title\": \"Test Passed:\",
                                        \"value\": \"1000\"
                                    },
                                    {
                                        \"title\": \"Test Failed:\",
                                        \"value\": \"0\"
                                    },
                                    {
                                        \"title\": \"Author:\",
                                        \"value\": \"SOMEBODY\"
                                    },
                                    {
                                        \"title\": \"Commit:\",
                                        \"value\": \"45w34gretretysh\"
                                    }
                                ]
                            }
                        ],
                        \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",
                        \"version\": \"1.5\"
                    }
                }
            ]
        }" \
[ YOUR NEW WEBHOOK URL HERE ]
mofc-foodbank commented 2 months ago

@tracyhoward

Setup Notifications with Teams, Power Automate and Uptime-Kuma

I followed your guide here, but when I push a test notification from Kuma, I get an error in Power Automate. On the Flows page, I can see 28 day run history and it shows a status of Failed after I hit the test. Going into the attempt on Power Automate, it shows the chart-looking thing like in your screenshot (When a Teams... --> Send each adaptive card --> Post card...) and there is a red exclamation mark on the middle "Send each adaptive card." Clicking it shows the error below:

ExpressionEvaluationFailed The execution of template action 'Send_each_adaptive_card' failed: the result of the evaluation of 'foreach' expression '@triggerOutputs()?['body']?['attachments']' is of type 'Null'. The result must be a valid array.

Is there a step that I missed or maybe something you left out of your instructions thinking it'd be obvious?

tracyhoward commented 1 month ago

@mofc-foodbank

Is there a step that I missed or maybe something you left out of your instructions thinking it'd be obvious?

ya; this won't work from Kuma at this point... A PR (https://github.com/louislam/uptime-kuma/pull/4538) was raised/completed back in march of this year to change the way kuma sends notifcations to use Cards. This is now required by Teams. However, that has not made its way into the next release (v2.0, see #4500) at this time. The instructions above are what you will follow once those changes are in place (a new tagged Kuma release). The curl command should work for the 'flow' that you created using this documentation.

CommanderStorm commented 1 month ago

@Tabisch is currently backporting that change here https://github.com/louislam/uptime-kuma/pull/4957

4538 is a feature-PR raised against master and will not be included in 1.x releases. See #4500 what is needed to release v2.0