Setting up Discord Notifications for OpenMediaVault đź””
OpenMediaVault (OMV) is a powerful network-attached storage solution that typically relies on email for system notifications. However, many users prefer instant messaging platforms like Discord for monitoring their systems. This guide will walk you through setting up Discord notifications for OpenMediaVault, providing real-time system alerts directly in your Discord server.
Prerequisites
- A running OpenMediaVault installation
- Administrative access to your OMV system
- A Discord server where you have permission to create webhooks
- Basic familiarity with the Linux command line
- SSH access to your OpenMediaVault system
Discord Webhook Setup
- Open Discord and navigate to your server
- Right-click on the desired notification channel
- Select “Edit Channel” → “Integrations” → “Create Webhook”
- Name your webhook (e.g., “OMV Notifications”)
- Copy the webhook URL for later use
- Click “Save Changes”
Installation
Create Notification Script
Create a new file for the Discord notification script in OpenMediaVault:
nano /usr/share/openmediavault/notification/sink.d/20discord
Add Script Content
Copy this script into the file, replacing the webhook URL placeholder:
#!/bin/bash#CREATED BY XMON FOR OpenMediaVaultDISCORD_WEBHOOK='PUT YOUR WEBHOOK LINK HERE'
generate_post_data() { cat <<EOF{ "content": "", "embeds": [{ "title": "${OMV_NOTIFICATION_SUBJECT}", "description": "$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})", "color": "45973", "footer": { "text": "${OMV_NOTIFICATION_DATE}", "icon_url": "" } }]}EOF}
curl -H "Content-Type: application/json" -X POST -d "$(generate_post_data)" $DISCORD_WEBHOOK
Make Script Executable
After saving the file, make it executable with:
chmod +x /usr/share/openmediavault/notification/sink.d/20discord
Configuration
- Log into your OpenMediaVault web interface
- Navigate to System → Notification
- Keep email notifications enabled but disable authentication
- Click “Save”
- Test the setup using the “Test” button
Troubleshooting
If you encounter issues, here’s a debugging version of the script that includes logging:
#!/bin/bashDISCORD_WEBHOOK='YOUR_WEBHOOK_HERE'LOG_FILE="/var/log/discord_notification.log"
# Log functionlog_message() { echo "$(date): $1" >> $LOG_FILE}
log_message "Script triggered"log_message "Subject: ${OMV_NOTIFICATION_SUBJECT}"log_message "Message file: ${OMV_NOTIFICATION_MESSAGE_FILE}"
# Check variablesif [ -z "$OMV_NOTIFICATION_SUBJECT" ]; then log_message "ERROR: Subject is empty"fi
if [ ! -f "$OMV_NOTIFICATION_MESSAGE_FILE" ]; then log_message "ERROR: Message file does not exist"fi
generate_post_data() { cat <<EOF{ "content": "", "embeds": [{ "title": "${OMV_NOTIFICATION_SUBJECT}", "description": "$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})", "color": "45973", "footer": { "text": "${OMV_NOTIFICATION_DATE}", "icon_url": "" } }]}EOF}
# Log the curl attemptlog_message "Attempting to send to Discord"RESPONSE=$(curl -H "Content-Type: application/json" -X POST -d "$(generate_post_data)" $DISCORD_WEBHOOK 2>&1)log_message "Curl response: $RESPONSE"
Common Issues
-
File Permissions: Check permissions with:
ls -l /usr/share/openmediavault/notification/sink.d/20discordShould show:
-rwxr-xr-x 1 root root
-
System Logs: Review notification errors:
grep -i notification /var/log/syslog -
Test Webhook: Verify webhook functionality:
curl -H "Content-Type: application/json" -X POST -d '{"content":"Test message"}' YOUR_WEBHOOK_URL
Security Notes
- Keep your webhook URL private and secure
- Monitor notification logs regularly
- Consider implementing rate limiting for high-volume notifications
- Update webhook URL if Discord server configurations change
Customization
The script can be customized by modifying:
- Embed color (change the “color” value)
- Footer icon (add an “icon_url”)
- Message format
- Additional embed fields
Remember to check the debug log at /var/log/discord_notification.log
if you make any modifications to ensure everything works as expected.