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

feat: enable new-style slack apps #2560

Merged
merged 1 commit into from
May 27, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [#2544](https://github.com/influxdata/kapacitor/pull/2544): flux tasks skeleton in Kapacitor
- [#2555](https://github.com/influxdata/kapacitor/pull/2555): run flux tasks with built-in flux engine
- [#2559](https://github.com/influxdata/kapacitor/pull/2559): kapacitor cli supports flux tasks
- [#2560](https://github.com/influxdata/kapacitor/pull/2560): enable new-style slack apps

## v1.5.9 [2021-04-01]

Expand Down
12 changes: 7 additions & 5 deletions integrations/streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"text/template"
"time"

"github.com/influxdata/kapacitor/services/discord"
"github.com/influxdata/kapacitor/services/discord/discordtest"

"github.com/davecgh/go-spew/spew"
"github.com/docker/docker/api/types/swarm"
"github.com/google/go-cmp/cmp"
Expand All @@ -45,6 +42,8 @@ import (
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/bigpanda/bigpandatest"
"github.com/influxdata/kapacitor/services/diagnostic"
"github.com/influxdata/kapacitor/services/discord"
"github.com/influxdata/kapacitor/services/discord/discordtest"
"github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/hipchat/hipchattest"
"github.com/influxdata/kapacitor/services/httppost"
Expand Down Expand Up @@ -8713,6 +8712,7 @@ stream
c2.Workspace = "company_private"
c2.Enabled = true
c2.URL = ts.URL + "/test/slack/url2"
c2.Token = "my_secret_token"
c2.Channel = "#channel"
d := diagService.NewSlackHandler().WithContext(keyvalue.KV("test", "slack"))
sl, err := slack.NewService([]slack.Config{c1, c2}, d)
Expand All @@ -8725,7 +8725,8 @@ stream

exp := []interface{}{
slacktest.Request{
URL: "/test/slack/url",
URL: "/test/slack/url",
AuthHeader: "",
PostData: slacktest.PostData{
Channel: "@jim",
Username: "kapacitor",
Expand All @@ -8741,7 +8742,8 @@ stream
},
},
slacktest.Request{
URL: "/test/slack/url2",
URL: "/test/slack/url2",
AuthHeader: "Bearer my_secret_token",
PostData: slacktest.PostData{
Channel: "#alerts",
Username: "kapacitor",
Expand Down
35 changes: 35 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7982,6 +7982,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"global": true,
"icon-emoji": "",
"state-changes-only": false,
"token": false,
"url": false,
"username": "kapacitor",
"ssl-ca": "",
Expand All @@ -7991,6 +7992,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
}},
},
Expand All @@ -8005,6 +8007,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": false,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8013,6 +8016,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
updates: []updateAction{
Expand All @@ -8025,6 +8029,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"channel": "#general",
"username": slack.DefaultUsername,
"url": "http://slack.example.com/secret-token",
"token": "my_other_secret",
},
},
element: "company_private",
Expand All @@ -8041,6 +8046,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": false,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8049,6 +8055,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8062,6 +8069,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": true,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8070,6 +8078,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
}},
},
Expand All @@ -8084,6 +8093,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": true,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8092,6 +8102,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand Down Expand Up @@ -8121,6 +8132,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": false,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8129,6 +8141,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8142,6 +8155,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": true,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8150,6 +8164,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8163,6 +8178,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8171,6 +8187,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand All @@ -8186,6 +8203,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8194,6 +8212,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand All @@ -8219,6 +8238,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": false,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8227,6 +8247,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8240,6 +8261,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": true,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8248,6 +8270,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8261,6 +8284,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "testbot",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8269,6 +8293,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand All @@ -8284,6 +8309,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "testbot",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8292,6 +8318,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand All @@ -8314,6 +8341,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": false,
"token": false,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8322,6 +8350,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8335,6 +8364,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": true,
"username": "kapacitor",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8343,6 +8373,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
{
Expand All @@ -8356,6 +8387,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8364,6 +8396,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand All @@ -8379,6 +8412,7 @@ func TestServer_UpdateConfig(t *testing.T) {
"icon-emoji": "",
"state-changes-only": false,
"url": true,
"token": false,
"username": "",
"ssl-ca": "",
"ssl-cert": "",
Expand All @@ -8387,6 +8421,7 @@ func TestServer_UpdateConfig(t *testing.T) {
},
Redacted: []string{
"url",
"token",
},
},
},
Expand Down
9 changes: 8 additions & 1 deletion services/slack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ type Config struct {
Default bool `toml:"default" override:"default"`
// ID assigned if multiple slack configs are given
Workspace string `toml:"workspace" override:"workspace"`
// The Slack webhook URL, can be obtained by adding Incoming Webhook integration.
// The Slack webhook URL.
// For new-style slack apps, use "https://slack.com/api/chat.postMessage".
// For legacy webhooks (e.g. created at https://slack.com/services/new/incoming-webhook), use the webhook link.
URL string `toml:"url" override:"url,redact"`
// The Slack OAuth token.
// For new-style slack apps, go to https://api.slack.com/apps -> your app -> 'OAuth & Permissions' to find
// the token. Ensure your app has 'chat:write' and 'chat:write.public' permissions.
// For legacy webhooks this can be left blank.
Token string `toml:"token" override:"token,redact"`
// The default channel, can be overridden per alert.
Channel string `toml:"channel" override:"channel"`
// The username of the Slack bot.
Expand Down
Loading