Skip to content

Instantly share code, notes, and snippets.

@Log1x
Created April 16, 2020 08:24
Show Gist options
  • Save Log1x/0c24e25952d039fa7e708d5205cd94f9 to your computer and use it in GitHub Desktop.
Save Log1x/0c24e25952d039fa7e708d5205cd94f9 to your computer and use it in GitHub Desktop.
Discord Notification Webhook for unRAID
#!/bin/bash
# Replace Slack.sh in /boot/config/plugins/dynamix/notifications/agents
# Set to your Discord webhook token.
WEBHOOK="https://discordapp.com/api/webhooks/ID/TOKEN"
curl "$WEBHOOK" \
-X "POST" \
-H 'Content-Type: application/json' \
--data @<(cat <<EOF
{
"embeds": [
{
"title": "$EVENT",
"description": "$SUBJECT",
"footer": {
"text": "$(date) on $(hostname)"
},
"thumbnail": {
"url": "https://i.imgur.com/tlooVc1.png",
"height": 16,
"width": 16
},
"fields": [
{
"name": "Priority",
"value": "${IMPORTANCE^}"
},
{
"name": "Description",
"value": "$DESCRIPTION\n\n$CONTENT"
}
]
}
]
}
EOF
)
@Log1x
Copy link
Author

Log1x commented Apr 16, 2020

Screenshot

@Bluscream
Copy link

Here's a alternative for HomeAssistant:

#!/bin/bash

# Replace with your Home Assistant instance URL and long-lived token
HA_URL="http://homeassistant.local:8123"
HA_TOKEN="<token from http://homeassistant.local/profile/security>"

# Create event data
event_data=$(cat <<EOF
{
  "event": "$EVENT",
  "subject": "$SUBJECT",
  "priority": "${IMPORTANCE^}",
  "description": "$DESCRIPTION",
  "content": "$CONTENT",
  "timestamp": "$(date)",
  "hostname": "$(hostname)"
}
EOF
)

# Send the event to Home Assistant
curl "$HA_URL/api/events/unraid" \
  -X "POST" \
  -H "Authorization: Bearer $HA_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$event_data"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment