From d0777ccfd34eeac886aa8825b5b4e9d22e5b9049 Mon Sep 17 00:00:00 2001 From: Tomas Touceda Date: Mon, 8 Nov 2021 15:13:02 -0300 Subject: [PATCH] Change message for text so webhook works on slack (#2838) * Change message for text so webhook works on slack * Update preview text for the webhook in the FE --- changes/issue-2434-change-webhook | 1 + frontend/components/forms/admin/AppConfigForm/AppConfigForm.jsx | 2 +- server/webhooks/host_status.go | 2 +- server/webhooks/host_status_test.go | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changes/issue-2434-change-webhook diff --git a/changes/issue-2434-change-webhook b/changes/issue-2434-change-webhook new file mode 100644 index 0000000000..6825773cff --- /dev/null +++ b/changes/issue-2434-change-webhook @@ -0,0 +1 @@ +* Update key text for webhook from message to text to support Slack out of the box diff --git a/frontend/components/forms/admin/AppConfigForm/AppConfigForm.jsx b/frontend/components/forms/admin/AppConfigForm/AppConfigForm.jsx index a677407a17..e018082f1e 100644 --- a/frontend/components/forms/admin/AppConfigForm/AppConfigForm.jsx +++ b/frontend/components/forms/admin/AppConfigForm/AppConfigForm.jsx @@ -250,7 +250,7 @@ class AppConfigForm extends Component { } const json = { - message: + text: "More than X% of your hosts have not checked into Fleet for more than Y days. You’ve been sent this message because the Host status webhook is enabled in your Fleet instance.", data: { unseen_hosts: 1, diff --git a/server/webhooks/host_status.go b/server/webhooks/host_status.go index a5aa322230..737e9d503c 100644 --- a/server/webhooks/host_status.go +++ b/server/webhooks/host_status.go @@ -38,7 +38,7 @@ func TriggerHostStatusWebhook( percentUnseen, appConfig.WebhookSettings.HostStatusWebhook.DaysCount, ) payload := map[string]interface{}{ - "message": message, + "text": message, "data": map[string]interface{}{ "unseen_hosts": unseen, "total_hosts": total, diff --git a/server/webhooks/host_status_test.go b/server/webhooks/host_status_test.go index ea57410251..660ab568ae 100644 --- a/server/webhooks/host_status_test.go +++ b/server/webhooks/host_status_test.go @@ -45,7 +45,7 @@ func TestTriggerHostStatusWebhook(t *testing.T) { require.NoError(t, TriggerHostStatusWebhook(context.Background(), ds, kitlog.NewNopLogger(), ac)) assert.Equal( t, - `{"data":{"days_unseen":2,"total_hosts":10,"unseen_hosts":6},"message":"More than 60.00% of your hosts have not checked into Fleet for more than 2 days. You’ve been sent this message because the Host status webhook is enabled in your Fleet instance."}`, + `{"data":{"days_unseen":2,"total_hosts":10,"unseen_hosts":6},"text":"More than 60.00% of your hosts have not checked into Fleet for more than 2 days. You’ve been sent this message because the Host status webhook is enabled in your Fleet instance."}`, requestBody, ) requestBody = ""