aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zed/zed.d
diff options
context:
space:
mode:
authorPhil Kauffman <[email protected]>2022-02-03 16:31:57 -0600
committerGitHub <[email protected]>2022-02-03 14:31:57 -0800
commitaa9905d89b3559e1cd280d018615d392f57a18d0 (patch)
treeff978053a415f3c448d5ff073196697158dd6803 /cmd/zed/zed.d
parent7b468ed2d81ec7fe68358af9467b8704420fd6b9 (diff)
zed-functions.sh: escape newline to produce valid json
This was discovered when using Discords Slack compatible webhook. Slack webhooks works without the escape, however Discord rightly refuses the POST as it contains invalid JSON. https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook Valid (while escaping the newline: ``` + msg_json='{"text": "*ZFS scrub_finish error for test on quartz*\nZFS has detected a data error:\n\n eid: 124\n class: scrub_finish\n host: quartz\n time: \n error: \n objid: :\n pool: test\n"}' ``` Invalid (no escape): ``` + msg_json='{"text": "*ZFS scrub_finish error for test on quartz* ZFS has detected a data error:\n\n eid: 124\n class: scrub_finish\n host: quartz\n time: \n error: \n objid: :\n pool: test\n"}' ``` The new line gets rendered and not sent inside the JSON as intended. ``` ++ curl -X POST https://discord.com/api/webhooks/{webhook.id}/{webhook.token}/slack --header 'Content-Type: application/json' --data-binary '{"text": "*ZFS scrub_finish error for test on quartz* ZFS has detected a data error:\n\n eid: 124\n class: scrub_finish\n host: quartz\n time: \n error: \n objid: :\n pool: test\n"}' + msg_out='{"message": "Cannot send an empty message", "code": 50006}' ``` Test method: `root@quartz:/etc/zfs/zed.d# export ZED_ZEDLET_DIR=/etc/zfs/zed.d; export ZEVENT_EID=124; export ZEVENT_SUBCLASS=scrub_finish; export ZEVENT_POOL=test; export ZED_NOTIFY_DATA=1; bash -x ./data-notify.sh` Reviewed-by: Damian Szuberski <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Philip Kauffman <[email protected]> Closes #13049
Diffstat (limited to 'cmd/zed/zed.d')
-rw-r--r--cmd/zed/zed.d/zed-functions.sh2
1 files changed, 1 insertions, 1 deletions
diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh
index bbff9c008..e6d3ce9ec 100644
--- a/cmd/zed/zed.d/zed-functions.sh
+++ b/cmd/zed/zed.d/zed-functions.sh
@@ -417,7 +417,7 @@ zed_notify_slack_webhook()
# Construct the JSON message for posting.
#
- msg_json="$(printf '{"text": "*%s*\n%s"}' "${subject}" "${msg_body}" )"
+ msg_json="$(printf '{"text": "*%s*\\n%s"}' "${subject}" "${msg_body}" )"
# Send the POST request and check for errors.
#