Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add msteams #3324

Merged
merged 5 commits into from Jun 8, 2023
Merged

Add msteams #3324

merged 5 commits into from Jun 8, 2023

Conversation

zhan9san
Copy link
Contributor

@zhan9san zhan9san commented Apr 12, 2023

Related to #3076

As the new line is important to Markdown format, a nested template definition __text_alert_list_markdown is added.

For simplicity, only text field is used to send message in Message card.

The message format is similar to Discord's.

Card design can be checked in Card Playground with following json text.

{
	"@type": "MessageCard",
	"@context": "https://schema.org/extensions",
	"themeColor": "8C1A1A",
	"title": "[FIRING:1] InstanceDown (v critical core)",
	"text": "\n\nAlerts Firing:\n\nLabels:\n - alertname = InstanceDown\n - env = build-service\n - environment = v\n - instance = https://example.com\n - job = blackbox\n - severity = critical\n - type = core\n\nAnnotations:\n - description = https://example.com of job blackbox has been down for more than 5 minutes.\n - summary = Instance https://example.com down\n\nSource: http://v:9090/graph?g0.expr=probe_success%7Btype%3D%22core%22%7D+%3D%3D+0&g0.tab=1\n"
}


```yaml
# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]
Copy link

Choose a reason for hiding this comment

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

The default is false

Suggested change
[ send_resolved: <boolean> | default = true ]
[ send_resolved: <boolean> | default = false ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kbudde

Thanks for your review. I think we need to keep the default value to true.

I have updated the default value in code.

@kbudde
Copy link

kbudde commented Apr 16, 2023

Hey @zhan9san,
LGTM, just change the default in the docs (or change the default in code).

@simonpasquier simonpasquier self-requested a review April 16, 2023 15:38
@zhan9san
Copy link
Contributor Author

@simonpasquier

Could you help review this PR?

Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM!

Thank you so much the contribution 🙏 our users will massively appreciate that. I have left a few nits and some comments please let me know what you think.

@@ -56,6 +56,7 @@ import (
"github.com/prometheus/alertmanager/notify/pushover"
"github.com/prometheus/alertmanager/notify/slack"
"github.com/prometheus/alertmanager/notify/sns"
"github.com/prometheus/alertmanager/notify/teams"
Copy link
Member

Choose a reason for hiding this comment

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

nit: Teams is a very common "name" for these type of integrations e.g. Webex also calls their platform Webex Teams.

How do we feel about renaming the package and structs from "teams" to "msteams", I think this is clearer and leaves no room for interpretation.

Copy link
Member

Choose a reason for hiding this comment

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

agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The package is renamed to msteams in new commit

@@ -1044,6 +1046,27 @@ attributes:
[ role_arn: <string> ]
```

### `<teams_config>`

Teams notifications are sent via the [Incoming Webhooks](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Teams notifications are sent via the [Incoming Webhooks](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors).
Microsoft Teams notifications are sent via the [Incoming Webhooks](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors) API endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fixed in new commit

webhookURL *config.SecretURL
}

// Message card https://learn.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Message card https://learn.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
// Message card reference can be found at https://learn.microsoft.com/en-us/outlook/actionable-messages/message-card-reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fixed in new commit

resp, err := notify.PostJSON(ctx, n.client, n.webhookURL.String(), &payload)
if err != nil {
return true, notify.RedactURL(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}
defer notify.Drain(resp)

Let's make sure we close the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fixed in new commit


shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
return shouldRetry, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return shouldRetry, err
return shouldRetry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)

Let's make sure we add a reason to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 429 status code is not set in a standard way. Instead, if it hits rate limit, 200 OK is always send with 'Microsoft Teams endpoint returned HTTP error 429' in response content.

So GetFailureReasonFromStatusCode is renamed to GetFailureReason and add a new parameter responseContent string to address this issue

// This is a test URL that has been modified to not be valid.
var testWebhookURL, _ = url.Parse("https://example.webhook.office.com/webhookb2/xxxxxx/IncomingWebhook/xxx/xxx")

func TestTeamsRetry(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we please add 1 more test that is similar to what we have in https://github.com/prometheus/alertmanager/pull/3252/files

I think it's important that we test:

  1. The expected format of the JSON on the webhook api
  2. the reason codes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is added in new commit

ThemeColor string `json:"themeColor"`
}

func New(c *config.TeamsConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func New(c *config.TeamsConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
// New returns a new notifier that uses the Microsoft Teams Webhook API.
func New(c *config.TeamsConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fixed in new commit

@gotjosh gotjosh added the waiting-for-user-input The Pull Request or Issue is waiting for input from the user that reported it or created it. label Apr 28, 2023
@@ -56,6 +56,7 @@ import (
"github.com/prometheus/alertmanager/notify/pushover"
"github.com/prometheus/alertmanager/notify/slack"
"github.com/prometheus/alertmanager/notify/sns"
"github.com/prometheus/alertmanager/notify/teams"
Copy link
Member

Choose a reason for hiding this comment

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

agreed

@@ -0,0 +1,130 @@
// Copyright 2019 Prometheus Team
Copy link
Member

Choose a reason for hiding this comment

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

(nit)

Suggested change
// Copyright 2019 Prometheus Team
// Copyright 2023 Prometheus Team

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fixed in new commit

Comment on lines 100 to 105
if alerts.Status() == model.AlertFiring {
color = colorRed
}
if alerts.Status() == model.AlertResolved {
color = colorGreen
}
Copy link
Member

Choose a reason for hiding this comment

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

(nit)

Suggested change
if alerts.Status() == model.AlertFiring {
color = colorRed
}
if alerts.Status() == model.AlertResolved {
color = colorGreen
}
switch alerts.Status() {
case model.AlertFiring:
color = colorRed
case alerts.Status():
color = colorGreen
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is addressed in new commit


level.Debug(n.logger).Log("incident", key)

alerts := types.Alerts(as...)
Copy link
Member

Choose a reason for hiding this comment

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

(nit) can you move it right before L99?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is addressed in new commit

@zhan9san
Copy link
Contributor Author

zhan9san commented May 4, 2023

Thanks for your careful review.

I just get back from a five-day vacation and I'll handle it later.

@TheMeier
Copy link
Contributor

TheMeier commented May 8, 2023

@zhan9san thanks a lot four your great contribution. Since the MessageCards are marked "legacy" I was wondering if it might be beneficial to explore switching to AdaptiveCards. Of cause only if that's not a lot of effort or causes more delays in this feature being available.

@zhan9san
Copy link
Contributor Author

zhan9san commented May 8, 2023

@TheMeier

Thanks for pointing it out. I thought about the legacy issue at first.

But to make the PR simple, I just make a lift-shift migration to make MSTeams work.

Besides, this can be considered as an improvement in next PR.

@zhan9san zhan9san force-pushed the feature/add-msteams branch 2 times, most recently from bf3b5ef to 787079b Compare May 9, 2023 18:58
@zhan9san
Copy link
Contributor Author

zhan9san commented May 9, 2023

@simonpasquier and @gotjosh

Would you kindly review this PR?

@zhan9san
Copy link
Contributor Author

Thank you again for taking the time to review the changes.
I just wanted to check in and see if there's anything that's unclear or needs further explanation.

Please let me know if there's anything I can do to make the process easier for you.

Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Sorry for the delay! Can you add msteams to the list of integrations here?

for _, integration := range []string{
"email",
"pagerduty",
"wechat",
"pushover",
"slack",
"opsgenie",
"webhook",
"victorops",
"sns",
"telegram",
} {

Otherwise this is good for me.

docs/configuration.md Outdated Show resolved Hide resolved
zhan9san and others added 2 commits June 2, 2023 21:46
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
Signed-off-by: Jack <jack4zhang@gmail.com>
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
@zhan9san
Copy link
Contributor Author

zhan9san commented Jun 2, 2023

@simonpasquier

Thanks for your review.

Can you add msteams to the list of integrations here?

It's done.

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Thanks! I'll wait a few days before merging in case @gotjosh has more comments :)

Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM

@gotjosh
Copy link
Member

gotjosh commented Jun 8, 2023

Thank you very much for your patience and your contributions ❤️

@gotjosh gotjosh merged commit d10f21f into prometheus:main Jun 8, 2023
5 checks passed
@rgarcia89
Copy link

Now all we need is a new release to be build 😁

@SergkeiM
Copy link

@zhan9san Amazing thanks a lot for this, we had to use Telegram until MS Teams is added, now we can use 1 messenger only :)

@rgarcia89 I hope will be soon, finger crossed

@danielfree
Copy link

when can we have a new release? last release was like ~6 months ago..

@rgarcia89
Copy link

rgarcia89 commented Jun 21, 2023

@gotjosh @simonpasquier any idea when we can count with a new release? It looks like there is quite some demand for this PR to become available 🤔

@rgarcia89
Copy link

Anyone tried to build an image including the merge by itself? Is there anything I should give a special look? I think this is the only reasonable way to get an updated image in time

@roidelapluie
Copy link
Member

You can use the :main image.

gotjosh pushed a commit that referenced this pull request Aug 7, 2023
* Add msteams

Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
---------
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Signed-off-by: Jack <jack4zhang@gmail.com>
@gotjosh
Copy link
Member

gotjosh commented Aug 25, 2023

Dear all - this as now been released as part of 0.26

@zhan9san zhan9san deleted the feature/add-msteams branch August 25, 2023 09:11
@SergkeiM
Copy link

SergkeiM commented Aug 25, 2023

Hi @gotjosh and @zhan9san Thank you, already changed it in our Ceph Cluster:
image 🚀

But having issue in Prometheus though: 3724

@@ -896,6 +907,7 @@ type Receiver struct {
SNSConfigs []*SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"`
TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"`
WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"`
MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"teams_configs,omitempty"`
Copy link

Choose a reason for hiding this comment

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

Should we align the configuration name? I am wondering why we call msteams for yaml but teams for json.
@zhan9san @simonpasquier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yeya24

Thanks for pointing it out. It has to be a typo.

I'll submit a PR to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@zhan9san zhan9san mentioned this pull request Sep 1, 2023
radek-ryckowski pushed a commit to goldmansachs/alertmanager that referenced this pull request Nov 6, 2023
* Add msteams

Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
---------
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Signed-off-by: Jack <jack4zhang@gmail.com>
qinxx108 pushed a commit to amazon-contributing/alertmanager that referenced this pull request Mar 28, 2024
* Add msteams

Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
---------
Signed-off-by: Jack Zhang <jack4zhang@gmail.com>
Signed-off-by: Jack <jack4zhang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-user-input The Pull Request or Issue is waiting for input from the user that reported it or created it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants