Skip to content

Conversation

JamesHillyard
Copy link
Contributor

@JamesHillyard JamesHillyard commented Aug 27, 2024

Summary

Fixes #820 by introducing a new teams-workflows alert compatible with Teams Workflows. Microsoft is deprecating the O365 webhook connector for Teams Workflows with MS Power Automate (Source: Microsoft DevBlog).

The new Workflows require Microsoft Adaptive Cards and have a proprietary JSON format that means the old teams connector using a new Workflow URL will fail with this error:

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.

Breaking Changes

There are no breaking changes. The old teams alert still exists and will work with legacy O365 Webhook URLs.

There are no breaking changes in configuring the teams and teamswebhook alerts, meaning migration is simple.

Migrating to new Teams Webhooks

End-users will need to make the following changes to migrate from the legacy teams alerts to teamswebhook alerts:

  • Create a Workflow in Microsoft Teams for incoming webhooks. Microsoft Documentation
  • Replace all occurences of teams (In alerting and endpoints[].alerts) with teams-workflows
  • Replace the alerting.teams.webhook-url (Now alerting.teams-workflows.webhook-url) with the new URL generated in the Teams Workflow

Configuring the teams-workflows Alert

MS Teams Configuration

image

Gatus Configuration

alerting:
  teams-workflows:
    webhook-url: "[WORKFLOW-WEBHOOK-URL-HERE]"
    default-alert:
      description: ""
      send-on-resolved: true
      failure-threshold: 3
      success-threshold: 3


endpoints:
  # Website Group
  - name: front-end
    url: https://www.google.com
    interval: 3s
    conditions:
      - "[STATUS] == 200"
      - "[RESPONSE_TIME] < 50"
    alerts:
      - type: teams-workflows
        description: "Description Lies Here"

Remaining Issues

There are a few remaining issues, none are blockers to using this feature, but likely should be addressed in the future with further investigation.

Adaptive Card Version >1.5

Using an Adaptive Card higher than 1.4 (1.6 is latest) results in the message showing

We're sorry, this card couldn't be displayed

This has been reported to AdaptiveCards (Report), but discussion around this issue seems very low.

Card Width

The cards do not show on teams as full-width. A StackOverflow post would suggest the width can be changed, but I wasn't able to get this to work.

Card Colour Strip

The red and green colour strip on the old teams cards at the top for triggered/resolved is not supported in Adaptive Cards. There are workaround options as identified in this Stack Overflow post but it doesn't look great.

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

Signed-off-by: James Hillyard <[email protected]>
Signed-off-by: James Hillyard <[email protected]>
Copy link
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! The only real change I see here is renaming teamsworkflowtoteams-workflows`.

Not a super big deal, but looking at https://support.microsoft.com/en-us/office/creating-a-workflow-from-a-channel-in-teams-242eb8f2-f328-45be-b81f-9817b51a5f0e, it seems like their service is "Workflows", not "Workflow", and well, I'd rather avoid confusion.

In a later version of Gatus, I'll probably get rid of the current teams once they get rid of the O365 connectors and replace it for this implementation.

@JamesHillyard
Copy link
Contributor Author

JamesHillyard commented Sep 4, 2024

@TwiN Makes sense, I have renamed teamsworkflow to teams-workflows and tested it still works. Thanks for the review!

@JamesHillyard JamesHillyard requested a review from TwiN September 4, 2024 08:57
Signed-off-by: James Hillyard <[email protected]>
Copy link
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesHillyard Looks like some of your tests are failing

 --- FAIL: TestAlertProvider_buildRequestBody (0.00s)
    --- FAIL: TestAlertProvider_buildRequestBody/triggered (0.00s)
        teamsworkflows_test.go:189: expected:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x1f6a8 Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been triggered due to having failed 3 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false,"facts":[{"title":"\u0026#x274C;","value":"[CONNECTED] == true"},{"title":"\u0026#x274C;","value":"[STATUS] == 200"}]}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
            got:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x26D1; Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been triggered due to having failed 3 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false,"facts":[{"title":"\u0026#x274C;","value":"[CONNECTED] == true"},{"title":"\u0026#x274C;","value":"[STATUS] == 200"}]}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
    --- FAIL: TestAlertProvider_buildRequestBody/resolved (0.00s)
        teamsworkflows_test.go:189: expected:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x1f6a8 Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been resolved after passing successfully 5 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false,"facts":[{"title":"\u0026#x2705;","value":"[CONNECTED] == true"},{"title":"\u0026#x2705;","value":"[STATUS] == 200"}]}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
            got:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x26D1; Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been resolved after passing successfully 5 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false,"facts":[{"title":"\u0026#x2705;","value":"[CONNECTED] == true"},{"title":"\u0026#x2705;","value":"[STATUS] == 200"}]}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
    --- FAIL: TestAlertProvider_buildRequestBody/resolved-with-no-conditions (0.00s)
        teamsworkflows_test.go:189: expected:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x1f6a8 Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been resolved after passing successfully 5 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
            got:
            {"attachments":[{"content":{"type":"AdaptiveCard","version":"1.4","body":[{"type":"TextBlock","text":"\u0026#x26D1; Gatus","wrap":false,"size":"Medium","weight":"Bolder"},{"type":"TextBlock","text":"An alert for **endpoint-name** has been resolved after passing successfully 5 time(s) in a row.","wrap":true},{"type":"FactSet","wrap":false}]},"contentType":"application/vnd.microsoft.card.adaptive"}],"type":"message"}
FAIL
coverage: 93.5% of statements
FAIL	github.com/TwiN/gatus/v5/alerting/provider/teamsworkflows	0.026s

@JamesHillyard
Copy link
Contributor Author

@TwiN Looks like the text was expecting a broken teams emoji.. I must have changed it last minute and not updated the test. I've now fixed it and running go test -v .\alerting\provider\teamsworkflows\ results in all tests passing.

@yeldeeb
Copy link

yeldeeb commented Oct 15, 2024

When can I use the new teams-workflows?

@TwiN TwiN changed the title Teams Workflow Alert (Issue #820) feat(alerting): Implement new Teams Workflow alert Oct 15, 2024
@TwiN TwiN added area/alerting Related to alerting feature New feature or request labels Oct 15, 2024
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 92.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 79.35%. Comparing base (bb97397) to head (7cc5bd3).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
alerting/provider/teamsworkflows/teamsworkflows.go 92.00% 3 Missing and 3 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #847      +/-   ##
==========================================
+ Coverage   79.15%   79.35%   +0.19%     
==========================================
  Files          71       72       +1     
  Lines        4778     4853      +75     
==========================================
+ Hits         3782     3851      +69     
- Misses        783      786       +3     
- Partials      213      216       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TwiN TwiN merged commit ff4b09d into TwiN:master Oct 15, 2024
1 check passed
@TwiN
Copy link
Owner

TwiN commented Oct 15, 2024

@JamesHillyard Great work & thank you for the contribution!

@liamjones-pw
Copy link
Contributor

@TwiN not pushing you, but any idea when you'll create a new release including this code?

@TwiN
Copy link
Owner

TwiN commented Oct 25, 2024

@liamjones-pw I usually let new features soak in latest for some time to give people time to report issues. If people are already using the feature and haven't reported any issues, I can create a release for it this weekend 👀

@TwiN
Copy link
Owner

TwiN commented Oct 26, 2024

@liamjones-pw I just released v5.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/alerting Related to alerting feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the Teams alert from the Office 365 connector to the Teams Workflow App Webhook Connector

5 participants