This script is a simple wrapper to send messages from Truenas to a Discord chat using webhooks. There are 3 args to fill in:
-wthe webhook endpoint (required)-mthe message you want to send (markdown also is supported, but pay attention to the correct format)-soptionally, the sender name (if not provided, the hostname/Truenas BOTwill be automatically used)
In case of need, passing --debug_enabled as arg to the script will activate the debug mode: every step will be printed to help troubleshooting.
The script shouldn't require particular privilegies, but ensure to only run it in a secured folder, not accessible to un-priviliged users, to avoid unexpected behaviour.
Plugin will help retrieving data and incapsulate a message for the tn-to-discord.py.
plugin_disktemp.sh
run this script in a cronjob, set a threshold temp, and get a message if a disk exceeds that. Credit to @scarbrtj from TN forums for the idea and some line of code
THRESHOLD=50 DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/**" ./disktemp.sh
optional args --sender (the name of the sender for the message) or --show-output (to print the result into shell) can be passed
#!/bin/bash
export DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/***
python3 tn-to-discord.py \
-w "$DISCORD_WEBHOOK_URL" \
-m $'**[System Report](https://example.com)**\n\n> **Task completed** successfully on _pool_ `MyDataPool`\n> Total time: `12m 33s`\n> Status: ✅\n\n__Details:__\n• Dataset: `pool/data`\n• Size: 123 GB\n• Snapshot: `snap_2025-08-11`\n\n```bash\nzfs list -o name,used,avail\n```\n\n~~No errors detected~~' \
-s "TnToDiscord"When running from the Cron Job scheduler, use
printf '%b'instead ofANSI-C quotingto interpret\nas real newlines:
#!/bin/sh
cd /mnt/mypool/mysecurefolder &&
export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/***" &&
python3 /mnt/pool/scripts/tn-to-discord.py \
-w "$DISCORD_WEBHOOK_URL" \
-m "$(printf '%b' '**[System Report](https://example.com)**\n\n> **Task completed** successfully on _pool_ `MyDataPool`\n> Total time: `12m 33s`\n> Status: ✅\n\n__Details:__\n• Dataset: `pool/data`\n• Size: 123 GB\n• Snapshot: `snap_2025-08-11`\n\n```bash\nzfs list -o name,used,avail\n```\n\n~~No errors detected~~')" \
-s "TnToDiscord"