mirror of
https://github.com/unraid/webgui.git
synced 2026-01-12 20:49:56 -06:00
6.10 removes /var/run/nginx.origin, need to build links to http://tower.local Redirects will forward user to a better url if one is available.
452 lines
17 KiB
XML
452 lines
17 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<Agents>
|
|
<Agent>
|
|
<Name>Boxcar</Name>
|
|
<Variables>
|
|
<Variable Help="Get your access token as explained [a href='http://help.boxcar.io/knowledgebase/articles/314474-how-to-get-my-boxcar-access-token' target='_blank'][u]here[/u].[/a]" Desc="Access Token" Default="">ACCESS_TOKEN</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
|
|
curl -s -k \
|
|
-d "user_credentials=$ACCESS_TOKEN" \
|
|
-d "notification[title]=$TITLE" \
|
|
-d "notification[long_message]=$MESSAGE" \
|
|
-d "notification[source_name]=Unraid" \
|
|
-d "notification[sound]=bird-1" \
|
|
-d "notification[icon_url]=http://i.imgur.com/u63iSL1.png" \
|
|
https://new.boxcar.io/api/notifications 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Discord</Name>
|
|
<Variables>
|
|
<Variable Help="Add an '#unraid-notifications' channel to your personal Discord server, then get a WebHook URL as explained [a href='https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks' target='_blank'][u]here[/u].[/a] Note that multiple Unraid servers can use the same Webhook." Desc="WebHook URL" Default="USE YOUR OWN WEBHOOK VALUE HERE">WEBH_URL</Variable>
|
|
<Variable Help="Provide the https URL to an icon representing this Unraid server (using different icons for each server can help distinguish between them in the list of notifications.) To disable this feature, specify 'none'." Desc="Server Icon" Default="https://craftassets.unraid.net/uploads/logos/un-mark-gradient@2x.png">SERVER_ICON</Variable>
|
|
<Variable Help="In Discord, right-click the '#unraid-notifications' channel and choose Notification Settings -> Only @mentions. Then to receive an @mention on 'alert' priority notifications only, provide your personal Discord ID (it is a series of numbers, not letters). To find your ID, in Discord type \@yourusername. To disable this feature, specify 'none'." Desc="Discord Tag ID" Default="none">DISCORD_TAG_ID</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
|
|
############
|
|
# Quick test with default values:
|
|
# bash /boot/config/plugins/dynamix/notifications/agents/Discord.sh
|
|
# Quick test with values set through environment (all vars are optional)
|
|
# EVENT="My Event" SUBJECT="My Subject" DESCRIPTION="My Description" CONTENT="My Message" IMPORTANCE="alert" LINK="/Dashboard" bash /boot/config/plugins/dynamix/notifications/agents/Discord.sh
|
|
# Full test of notification system (at least one param is required)
|
|
# /usr/local/emhttp/webGui/scripts/notify -e "My Event" -s "My Subject" -d "My Description" -m "My Message" -i "alert" -l "/Dashboard"
|
|
#
|
|
# If a notification does not go through, check the /var/log/notify_Discord file for hints
|
|
############
|
|
|
|
############
|
|
# Discord webhooks docs: https://birdie0.github.io/discord-webhooks-guide/
|
|
#
|
|
# Available fields from notification system
|
|
# HOSTNAME
|
|
# EVENT (notify -e)
|
|
# IMPORTANCE (notify -i)
|
|
# SUBJECT (notify -s)
|
|
# DESCRIPTION (notify -d)
|
|
# CONTENT (notify -m)
|
|
# LINK (notify -l)
|
|
# TIMESTAMP (seconds from epoch)
|
|
|
|
SCRIPTNAME=$(basename "$0")
|
|
LOG="/var/log/notify_${SCRIPTNAME%.*}"
|
|
|
|
# for quick test, setup environment to mimic notify script
|
|
[[ -z "${EVENT}" ]] && EVENT='Unraid Status'
|
|
[[ -z "${SUBJECT}" ]] && SUBJECT='Notification'
|
|
[[ -z "${DESCRIPTION}" ]] && DESCRIPTION='No description'
|
|
[[ -z "${IMPORTANCE}" ]] && IMPORTANCE='normal'
|
|
[[ -z "${TIMESTAMP}" ]] && TIMESTAMP=$(date +%s)
|
|
# ensure link has a host
|
|
if [[ -n "${LINK}" ]] && [[ ${LINK} != http* ]]; then
|
|
source <(grep "NAME\|LOCAL_TLD\|PORT" /usr/local/emhttp/state/var.ini 2>/dev/null)
|
|
HOST_NAME=${NAME,,}
|
|
[[ -n ${LOCAL_TLD} ]] && LOCAL_TLD=".${LOCAL_TLD,,}"
|
|
[[ "${PORT}" = "80" ]] && PORT=
|
|
[[ -n ${PORT} ]] && PORT=":${PORT}"
|
|
HOST="http://${HOST_NAME}${LOCAL_TLD}${PORT}"
|
|
LINK=${HOST}${LINK}
|
|
fi
|
|
# note: there is no default for CONTENT
|
|
|
|
# send DESCRIPTION and/or CONTENT. Ignore the default DESCRIPTION.
|
|
[[ "${DESCRIPTION}" == 'No description' ]] && DESCRIPTION=""
|
|
if [[ -n "${DESCRIPTION}" ]] && [[ -n "${CONTENT}" ]]; then
|
|
FULL_DETAILS="${DESCRIPTION}\n\n${CONTENT}"
|
|
elif [[ -n "${DESCRIPTION}" ]]; then
|
|
FULL_DETAILS="${DESCRIPTION}"
|
|
elif [[ -n "${CONTENT}" ]]; then
|
|
FULL_DETAILS="${CONTENT}"
|
|
fi
|
|
# split into 1024 character segments
|
|
[[ -n "${FULL_DETAILS}" ]] && DESC_FIELD=$(
|
|
cat <<EOF
|
|
{
|
|
"name": "Description",
|
|
"value": "${FULL_DETAILS:0:1024}"
|
|
},
|
|
EOF
|
|
)
|
|
[[ -n "${FULL_DETAILS}" ]] && [[ ${#FULL_DETAILS} -gt 1024 ]] && DESC_FIELD=$(
|
|
cat <<EOF
|
|
${DESC_FIELD}
|
|
{
|
|
"name": "Description (cont)",
|
|
"value": "${FULL_DETAILS:1024:1024}"
|
|
},
|
|
EOF
|
|
)
|
|
[[ -n "${FULL_DETAILS}" ]] && [[ ${#FULL_DETAILS} -gt 2048 ]] && DESC_FIELD=$(
|
|
cat <<EOF
|
|
${DESC_FIELD}
|
|
{
|
|
"name": "Description (cont)",
|
|
"value": "${FULL_DETAILS:2048:1024}"
|
|
},
|
|
EOF
|
|
)
|
|
|
|
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/timestamp.html
|
|
# https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
|
|
FORMATTED_TIMESTAMP=$(date -u +\"%Y-%m-%dT%H:%M:%S.000Z\" -d @"${TIMESTAMP}")
|
|
|
|
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/thumbnail.html
|
|
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/color.html
|
|
# vary data based on IMPORTANCE
|
|
if [[ "${IMPORTANCE}" != "normal" ]] && [[ "${IMPORTANCE}" != "warning" ]] && [[ "${IMPORTANCE}" != "alert" ]]; then
|
|
IMPORTANCE="normal"
|
|
fi
|
|
case "${IMPORTANCE}" in
|
|
normal)
|
|
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-normal.png"
|
|
COLOR="39208"
|
|
;;
|
|
warning)
|
|
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-warning.png"
|
|
COLOR="16747567"
|
|
;;
|
|
alert)
|
|
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-alert.png"
|
|
COLOR="14821416"
|
|
[[ -n "${DISCORD_TAG_ID}" && "${DISCORD_TAG_ID}" == "none" ]] && DISCORD_TAG_ID=""
|
|
if [[ -n "${DISCORD_TAG_ID}" ]]; then
|
|
# add leading @ if needed
|
|
[[ "${DISCORD_TAG_ID:0:1}" != "@" ]] && DISCORD_TAG_ID="@${DISCORD_TAG_ID}"
|
|
# @mentions only work in the "content" area, not the "embed" area
|
|
DISCORD_CONTENT_AREA="\"content\": \"<${DISCORD_TAG_ID}>\","
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/author.html
|
|
# if SERVER_ICON is defined, use it
|
|
[[ -n "${SERVER_ICON}" && "${SERVER_ICON:0:8}" == "https://" ]] && ICON_URL="\"icon_url\": \"${SERVER_ICON}\","
|
|
|
|
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/url.html
|
|
# if LINK is defined, use it
|
|
[[ -n "${LINK}" ]] && LINK_URL="\"url\": \"${LINK}\","
|
|
|
|
DATA=$(
|
|
cat <<EOF
|
|
{
|
|
${DISCORD_CONTENT_AREA}
|
|
"embeds": [
|
|
{
|
|
"title": "${EVENT:0:256}",
|
|
"description": "${SUBJECT:0:2043}",
|
|
${LINK_URL}
|
|
"timestamp": ${FORMATTED_TIMESTAMP},
|
|
"color": "${COLOR}",
|
|
"author": {
|
|
${ICON_URL}
|
|
"name": "${HOSTNAME}"
|
|
},
|
|
"thumbnail": {
|
|
"url": "${THUMBNAIL}"
|
|
},
|
|
"fields": [
|
|
${DESC_FIELD}
|
|
{
|
|
"name": "Priority",
|
|
"value": "${IMPORTANCE}",
|
|
"inline": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
EOF
|
|
)
|
|
|
|
# echo "${DATA}" >>"${LOG}"
|
|
|
|
# try several times in case we are being rate limited
|
|
# this is not foolproof, messages can still be rejected
|
|
MAX=4
|
|
for ((i = 1; i <= "${MAX}"; i++)); do
|
|
RET=$(
|
|
curl -s -X "POST" "$WEBH_URL" -H 'Content-Type: application/json' --data-ascii @- <<EOF
|
|
${DATA}
|
|
EOF
|
|
)
|
|
# if nothing was returned, message was successfully sent. exit loop
|
|
[[ -z "${RET}" ]] && break
|
|
# log the attempt
|
|
{
|
|
date
|
|
echo "attempt ${i} of ${MAX} failed"
|
|
echo "${RET}"
|
|
} >>"${LOG}"
|
|
# if there was an error with the submission, log details and exit loop
|
|
[[ "${RET}" != *"retry_after"* ]] && echo "${DATA}" >>"${LOG}" && logger -t "${SCRIPTNAME}" "Failed sending notification" && break
|
|
# if retries exhausted, log failure
|
|
[[ "${i}" -eq "${MAX}" ]] && echo "${DATA}" >>"${LOG}" && logger -t "${SCRIPTNAME}" "Failed sending notification - rate limited" && break
|
|
# we were rate limited, try again after a delay
|
|
sleep 1
|
|
done
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Gotify</Name>
|
|
<Variables>
|
|
<Variable Help="The full server base URL including protocol and port. eg: https://example.com:8888/" Desc="Full Server Base URL" Default="">SERVER_URL</Variable>
|
|
<Variable Help="The App Token to use." Desc="App Token" Default="">APP_TOKEN</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
case "$IMPORTANCE" in
|
|
'normal' )
|
|
PRIORITY="3"
|
|
;;
|
|
'warning' )
|
|
PRIORITY="5"
|
|
;;
|
|
'alert' )
|
|
PRIORITY="7"
|
|
;;
|
|
esac
|
|
|
|
# Remove any trailing slash
|
|
SERVER_URL=${SERVER_URL%/}
|
|
|
|
curl -s -k -X POST \
|
|
-F "title=$TITLE" \
|
|
-F "message=$MESSAGE" \
|
|
-F "priority=$PRIORITY" \
|
|
${SERVER_URL}/message?token=$APP_TOKEN 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Join</Name>
|
|
<Variables>
|
|
<Variable Help="The API key can be found [a href='https://joinjoaomgcd.appspot.com' target='_blank'] [u]here[/u].[/a]" Desc="API key" Default="">API_KEY</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
##########
|
|
{0}
|
|
##########
|
|
TITLE=$(echo -e "$TITLE")
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
|
|
curl -s -k -G \
|
|
-d "apikey=$API_KEY" \
|
|
--data-urlencode "title=$TITLE" \
|
|
--data-urlencode "text=$MESSAGE" \
|
|
-d "deviceId=group.all" \
|
|
https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Prowl</Name>
|
|
<Variables>
|
|
<Variable Help="Get your api key as explained [a href='https://www.prowlapp.com/api_settings.php' target='_blank'][u]here[/u].[/a]" Desc="Api Key" Default="">API_KEY</Variable>
|
|
<Variable Help="Application name, e.g., Unraid Server." Desc="Application Name" Default="Unraid Server">APP_NAME</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
TITLE=$(echo -e "$TITLE")
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
|
|
case "$IMPORTANCE" in
|
|
'normal' )
|
|
PRIORITY="0"
|
|
;;
|
|
'warning' )
|
|
PRIORITY="1"
|
|
;;
|
|
'alert' )
|
|
PRIORITY="2"
|
|
;;
|
|
esac
|
|
|
|
curl -s -k \
|
|
-F "apikey=$API_KEY" \
|
|
-F "application=$APP_NAME" \
|
|
-F "event=$TITLE" \
|
|
-F "description=$MESSAGE" \
|
|
-F "priority=$PRIORITY" \
|
|
https://api.prowlapp.com/publicapi/add 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Pushbullet</Name>
|
|
<Variables>
|
|
<Variable Help="The Access Token can be found [a href='https://www.pushbullet.com/account' target='_blank'] [u]here[/u].[/a]" Desc="Access Token" Default="">TOKEN</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
##########
|
|
{0}
|
|
##########
|
|
MESSAGE=$(echo "$MESSAGE" | sed -e 's:<br[ /]*>:\\n:gI' -e 's/<[^>]*>//g')
|
|
|
|
curl -s -k \
|
|
-X POST --header "Authorization: Bearer $TOKEN" \
|
|
--header 'Content-Type: application/json' \
|
|
-d "{\"type\": \"note\", \"title\": \"$TITLE\", \"body\": \"$MESSAGE\"}" \
|
|
https://api.pushbullet.com/v2/pushes 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Pushover</Name>
|
|
<Variables>
|
|
<Variable Help="The User Key can be found [a href='https://pushover.net/' target='_blank'][u]here[/u].[/a]" Desc="User Key" Default="">USER_KEY</Variable>
|
|
<Variable Help="The App Token can be found [a href='https://pushover.net/apps' target='_blank'][u]here[/u][/a]." Desc="App Token" Default="">APP_TOKEN</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$SUBJECT,$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
case "$IMPORTANCE" in
|
|
'normal' )
|
|
PRIORITY="-1"
|
|
;;
|
|
'warning' )
|
|
PRIORITY="0"
|
|
;;
|
|
'alert' )
|
|
PRIORITY="1"
|
|
;;
|
|
esac
|
|
|
|
curl -s -k \
|
|
-F "token=$APP_TOKEN" \
|
|
-F "user=$USER_KEY" \
|
|
-F "message=$MESSAGE" \
|
|
-F "timestamp=$TIMESTAMP" \
|
|
-F "priority=$PRIORITY" \
|
|
-F "html=1" \
|
|
https://api.pushover.net/1/messages.json 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Slack</Name>
|
|
<Variables>
|
|
<Variable Help="Get your WebHook as explained [a href='https://api.slack.com/incoming-webhooks' target='_blank'][u]here[/u].[/a]" Desc="WebHook URL" Default="USE YOUR OWN WEBHOOK VALUE HERE">WEBH_URL</Variable>
|
|
<Variable Help="Application name, e.g., Unraid Server." Desc="Application Name" Default="Unraid Server">APP_NAME</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
TITLE=$(echo -e "$TITLE")
|
|
MESSAGE=$(echo -e "$MESSAGE")
|
|
curl -X POST --header 'Content-Type: application/json' \
|
|
-d "{\"username\": \"$APP_NAME\", \"text\": \"*$TITLE* \n $MESSAGE\"}" $WEBH_URL 2>&1
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
<Agent>
|
|
<Name>Telegram</Name>
|
|
<Variables>
|
|
<Variable Help="[a href='https://telegram.me/botfather' target='_blank'][u]BotFather[/u][/a] is the one bot to rule them all.[br][br]
|
|
1. Make a bot using BotFather[br]
|
|
2. Paste the bot token in this field[br]
|
|
3. Message the bot via Telegram (either via a direct message or a message via a group)[br]
|
|
4. Test the bot[br][br]
|
|
* To reset the notifications receiving user or group, run [i]rm /boot/config/plugins/dynamix/telegram/chatid[/i] in the terminal and re-run steps 3. and 4.[/a]" Desc="Bot Access Token" Default="">BOT_TOKEN</Variable>
|
|
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
|
|
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
|
|
</Variables>
|
|
<Script>
|
|
<![CDATA[
|
|
#!/bin/bash
|
|
############
|
|
{0}
|
|
############
|
|
LEGACY=/boot/config/telegram
|
|
TELEGRAM=/boot/config/plugins/dynamix/telegram
|
|
STORED_TOKEN=$(< $TELEGRAM/token) || "";
|
|
|
|
# move legacy folder (if existing)
|
|
[[ -d $LEGACY && ! -d $TELEGRAM ]] && mv $LEGACY $TELEGRAM
|
|
|
|
if [[ ! -f $TELEGRAM/token || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
|
|
mkdir -p $TELEGRAM;
|
|
echo $BOT_TOKEN > $TELEGRAM/token;
|
|
fi
|
|
|
|
if [[ ! -f $TELEGRAM/chatid || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
|
|
mkdir -p $TELEGRAM;
|
|
LASTCHATID=$(curl -s https://api.telegram.org/bot$BOT_TOKEN/getUpdates | jq ".result | last .message .chat .id");
|
|
[[ $LASTCHATID =~ ^-*[0-9]+$ ]] && echo $LASTCHATID > $TELEGRAM/chatid || exit 1
|
|
fi
|
|
|
|
CHATID=$(< $TELEGRAM/chatid);
|
|
MESSAGE=$(echo -e "$(hostname): $TITLE\n$MESSAGE");
|
|
curl -G -s "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" --data-urlencode "chat_id=$CHATID" --data-urlencode "text=$MESSAGE" 2>&1;
|
|
]]>
|
|
</Script>
|
|
</Agent>
|
|
</Agents>
|