zfs/cmd
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
..
arc_summary Removed Python 2 and Python 3.5- support 2022-01-13 09:51:12 -07:00
arcstat Removed Python 2 and Python 3.5- support 2022-01-13 09:51:12 -07:00
dbufstat Removed Python 2 and Python 3.5- support 2022-01-13 09:51:12 -07:00
fsck_zfs Add ShellCheck's `--enable=all` inside `cmd/` 2022-01-06 16:07:54 -08:00
mount_zfs Use fallthrough macro 2021-09-14 10:17:54 -06:00
raidz_test raidz_test: init_rand: fix unused, remove argsused 2021-12-21 12:05:11 -08:00
vdev_id Remove basename(1). Clean up/shorten some coreutils pipelines 2021-11-11 13:27:37 -07:00
zdb Replace *CTASSERT() with _Static_assert() 2022-01-26 11:38:52 -08:00
zed zed-functions.sh: escape newline to produce valid json 2022-02-03 14:31:57 -08:00
zfs Revert "zfs list: Allow more fields in ZFS_ITER_SIMPLE mode" 2022-01-06 11:12:53 -08:00
zfs_ids_to_path zfs_ids_to_path: print correct wrong values 2021-04-11 11:58:16 -07:00
zgenhostid Prune /*NOTREACHED*/ 2021-07-26 12:07:26 -07:00
zhack module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
zinject zinject: cancel_one_handler: fix unused, remove argsused 2021-12-21 12:05:11 -08:00
zpool Add enumerated vdev names to 'zpool iostat -v' and 'zpool list -v' 2022-02-03 14:29:29 -08:00
zpool_influxdb Fix trivial calloc(3) arguments order 2022-02-02 11:27:35 -08:00
zstream Report dnodes with faulty bonuslen 2022-02-03 14:28:19 -08:00
ztest module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
zvol_id Use substantially more robust program exit status logic in zvol_id 2021-07-02 13:10:36 -07:00
zvol_wait Add ShellCheck's `--enable=all` inside `cmd/` 2022-01-06 16:07:54 -08:00
Makefile.am Add ShellCheck's `--enable=all` inside `cmd/` 2022-01-06 16:07:54 -08:00