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

zed-functions.sh: escape newline to produce valid json. #13049

Merged
merged 1 commit into from
Feb 3, 2022

Commits on Feb 2, 2022

  1. 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`
    
    Signed-off-by: Philip Kauffman <philip@kauffman.me>
    papamoose committed Feb 2, 2022
    Configuration menu
    Copy the full SHA
    249647f View commit details
    Browse the repository at this point in the history