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

Introduce Teams support #109

Merged
merged 3 commits into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -141,6 +141,7 @@ Ease Probe supports the following notifications:
- **Lark**. Support the Lark(Feishu) notification.
- **Log File**. Write the notification into a log file
- **SMS**. Support SMS notification with multiple SMS service providers - [Twilio](https://www.twilio.com/sms), [Vonage(Nexmo)](https://developer.vonage.com/messaging/sms/overview), [YunPain](https://www.yunpian.com/doc/en/domestic/list.html)
- **Teams**. Support the [Microsoft Teams](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#setting-up-a-custom-incoming-webhook) notification.

**Note**:

Expand Down Expand Up @@ -188,6 +189,9 @@ notify:
key: xxxxxxxxxxxx # yunpian apikey
mobile: 123456789,987654321 # mobile phone number, multiple phone number joint by `,`
sign: "xxxxxxxx" # need to register; usually brand name
teams:
- name: "teams alert service"
webhook: "https://outlook.office365.com/webhook/a1269812-6d10-44b1-abc5-b84f93580ba0@9e7b80c7-d1eb-4b52-8582-76f921e416d9/IncomingWebhook/3fdd6767bae44ac58e5995547d66a4e4/f332c8d9-3397-4ac5-957b-b8e3fc465a8c" # see https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors
haoel marked this conversation as resolved.
Show resolved Hide resolved
```

Check the [Notification Configuration](#37-notification-configuration) to see how to configure it.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -3,6 +3,7 @@ module github.com/megaease/easeprobe
go 1.18

require (
github.com/atc0005/go-teams-notify/v2 v2.6.1
github.com/aws/aws-sdk-go v1.44.4
github.com/go-chi/chi v1.5.4
github.com/go-chi/chi/v5 v5.0.7
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Expand Up @@ -40,6 +40,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/atc0005/go-teams-notify/v2 v2.6.1 h1:t22ybzQuaQs4UJe4ceF5VYGsPhs6ir3nZOId/FBy6Go=
github.com/atc0005/go-teams-notify/v2 v2.6.1/go.mod h1:xo6GejLDHn3tWBA181F8LrllIL0xC1uRsRxq7YNXaaY=
github.com/aws/aws-sdk-go v1.44.4 h1:ePN0CVJMdiz2vYUcJH96eyxRrtKGSDMgyhP6rah2OgE=
github.com/aws/aws-sdk-go v1.44.4/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -242,6 +244,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
Expand Down
2 changes: 2 additions & 0 deletions notify/notify.go
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/megaease/easeprobe/notify/log"
"github.com/megaease/easeprobe/notify/slack"
"github.com/megaease/easeprobe/notify/sms"
"github.com/megaease/easeprobe/notify/teams"
"github.com/megaease/easeprobe/notify/telegram"
"github.com/megaease/easeprobe/notify/wecom"
"github.com/megaease/easeprobe/probe"
Expand All @@ -44,6 +45,7 @@ type Config struct {
Dingtalk []dingtalk.NotifyConfig `yaml:"dingtalk"`
Lark []lark.NotifyConfig `yaml:"lark"`
Sms []sms.NotifyConfig `yaml:"sms"`
Teams []teams.NotifyConfig `yaml:"teams"`
}

// Notify is the configuration of the Notify
Expand Down
62 changes: 62 additions & 0 deletions notify/teams/teams.go
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2022, MegaEase
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package teams

import (
"github.com/megaease/easeprobe/global"
"github.com/megaease/easeprobe/notify/base"
"github.com/megaease/easeprobe/report"

log "github.com/sirupsen/logrus"

goteamsnotify "github.com/atc0005/go-teams-notify/v2"
)

// NotifyConfig is the teams notification configuration
type NotifyConfig struct {
base.DefaultNotify `yaml:",inline"`
WebhookURL string `yaml:"webhook"`

client goteamsnotify.API
}

// Kind return the type of Notify
func (c *NotifyConfig) Kind() string {
return c.MyKind
}

// Config configures the teams notification
func (c *NotifyConfig) Config(gConf global.NotifySettings) error {
c.MyKind = "teams"
c.Format = report.MarkdownSocial
c.SendFunc = c.SendTeamsMessage
c.DefaultNotify.Config(gConf)

c.client = goteamsnotify.NewClient()
log.Debugf("Notification [%s] - [%s] configuration: %+v", c.MyKind, c.Name, c)
return nil
}

// SendTeamsMessage sends the message to the teams channel
func (c *NotifyConfig) SendTeamsMessage(title, msg string) error {
msgCard := goteamsnotify.NewMessageCard()
msgCard.Title = title
msgCard.Text = msg

return c.client.Send(c.WebhookURL, msgCard)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we deal with time out problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder why there is no ctx, I was opening an issue but too many fields in the future req template :(

}