Skip to content

Instantly share code, notes, and snippets.

@edubxb
Created May 20, 2024 22:15
Show Gist options
  • Save edubxb/e09beb643bec805a044fe06b45dd75b7 to your computer and use it in GitHub Desktop.
Save edubxb/e09beb643bec805a044fe06b45dd75b7 to your computer and use it in GitHub Desktop.
OpenMediaVault Telegram notification script
#!/bin/bash
## +info: ##
## https://docs.openmediavault.org/en/latest/administration/general/notifications.html#third-party-notifications
## https://forum.openmediavault.org/index.php?thread/14919-guide-use-telegram-as-notification-service/
BOT_TOKEN="<BOT_TOKEN>"
CHAT_ID="<CHAT_ID>"
URL="https://api.telegram.org/bot${BOT_TOKEN}"
MSG_URL="${URL}/sendMessage?chat_id=${CHAT_ID}&parse_mode=Markdown"
MSG_ICON=""
if [[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^Monitoring\ (alert|restart).* ]]; then
MSG_ICON="🚨 "
elif [[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^Cron.* ]] ||
[[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^CRON-APT\ .* ]] ||
[[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^Anacron\ .* ]]; then
MSG_ICON="πŸ• "
elif [[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^.*SECURITY.* ]] ||
[[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^Your\ user\ account\ was\ used\ to\ log\ in\ to\ the\ openmediavault\ control\ panel\ via\ a\ web\ browser ]]; then
MSG_ICON="πŸ”’ "
elif [[ "${OMV_NOTIFICATION_SUBJECT}" =~ ^Pending\ configuration.* ]]; then
MSG_ICON="βš™οΈ "
fi
content="${MSG_ICON}*ARK*
**${OMV_NOTIFICATION_SUBJECT}**
__${OMV_NOTIFICATION_DATE}__
\`\`\`
$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})
\`\`\`"
curl --data-urlencode "text=${content[@]}" "${MSG_URL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment