Skip to content

Instantly share code, notes, and snippets.

@DanielOaks
Last active November 28, 2021 21:24
Show Gist options
  • Save DanielOaks/ac3dc2341e0876188eca2190b3aa0cdb to your computer and use it in GitHub Desktop.
Save DanielOaks/ac3dc2341e0876188eca2190b3aa0cdb to your computer and use it in GitHub Desktop.
#! /bin/sh
# SMARTd discord notifier
export WEBHOOK_URL="https://discord.com/api/webhooks/YOUR_WEBHOOK_HERE"
export TMP_FILE=/tmp/smartd-discord
# assemble file
echo "**S.M.A.R.T. ERROR**" > $TMP_FILE
echo "> $SMARTD_MESSAGE" >> $TMP_FILE
#echo "> $SMARTD_DEVICEINFO" >> $TMP_FILE
echo '> ```' >> $TMP_FILE
lsblk $SMARTD_DEVICE | sed 's/^/> /' >> $TMP_FILE
echo '> ```' >> $TMP_FILE
echo "> Error first appeared $SMARTD_TFIRST and has appeared $SMARTD_PREVCNT times previously" >> $TMP_FILE
# send
export CONTENT=$(jq -n --arg username "smartd" --arg content "$(cat $TMP_FILE)" '{"username": $username, "content": $content}')
curl -s \
-H "Content-Type: application/json" \
-d "$CONTENT" \
"$WEBHOOK_URL" \
> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment