mirror_zfs/cmd/zed
Phil Kauffman aa9905d89b
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 <szuberskidamian@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Philip Kauffman <philip@kauffman.me>
Closes #13049
2022-02-03 14:31:57 -08:00
..
agents zed: agents: fmd_api: fix unused, remove argsused 2021-12-21 12:05:11 -08:00
zed.d zed-functions.sh: escape newline to produce valid json 2022-02-03 14:31:57 -08:00
.gitignore Initial implementation of zed (ZFS Event Daemon) 2014-04-02 13:10:03 -07:00
Makefile.am Add ShellCheck's --enable=all inside cmd/ 2022-01-06 16:07:54 -08:00
zed_conf.c Upstream: Add snapshot and zvol events 2021-09-09 10:44:21 -07:00
zed_conf.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_disk_event.c ZED: Match added disk by pool/vdev GUID if found (#12217) 2021-06-30 07:37:20 -07:00
zed_disk_event.h Bring over illumos ZFS FMA logic -- phase 1 2016-09-01 11:39:45 -07:00
zed_event.c Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_event.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_exec.c zed: exec: fix unused, remove argsused 2021-12-21 12:05:11 -08:00
zed_exec.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_file.c Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_file.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_log.c Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_log.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_strings.c Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed_strings.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00
zed.c zed: main: fix unused, remove argsused 2021-12-21 12:05:11 -08:00
zed.h Replace ZoL with OpenZFS where applicable 2021-05-07 17:20:37 -07:00