Skip to content

Instantly share code, notes, and snippets.

@Xmonpl
Last active September 12, 2025 08:01
Show Gist options
  • Save Xmonpl/3c8585d34c83459ac6a3be1f8cb5d129 to your computer and use it in GitHub Desktop.
Save Xmonpl/3c8585d34c83459ac6a3be1f8cb5d129 to your computer and use it in GitHub Desktop.
Discord notification for OpenMediaVault
#!/bin/bash
#CREATED BY XMON FOR OpenMediaVault
DISCORD_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
@Xmonpl
Copy link
Author

Xmonpl commented Jun 25, 2023

Put script here nano /usr/share/openmediavault/notification/sink.d/20discord

Save it and change it to executable

chmod +x /usr/share/openmediavault/notification/sink.d/20discord

@Furtys
Copy link

Furtys commented Sep 15, 2023

Hi !

Thanks for your script. Does it work with the test email on your side ?

Because I tried it but no discord publication on my side 😢

EDIT : My bad, OMV don't have curl installed by default...
Just run apt-get install curl and this script works as expected !

Perfect for server booted notification 💪

@Xmonpl
Copy link
Author

Xmonpl commented Sep 16, 2023 via email

@AKASGaming
Copy link

Is there any way to edit what notifications it sends out? Also, is there a way to test it to make sure it actually works?

@Xmonpl
Copy link
Author

Xmonpl commented Nov 24, 2023 via email

@lotsokluze
Copy link

Hello. Cant seem to get this to work. Should it fire when the email triggers?

@kzaoaai
Copy link

kzaoaai commented Jun 26, 2024

yes. I keep email on, just disable authentication so that emails don't actually go out. The Test button should work to test the discord notification at this point.

@john470fc
Copy link

Thanks for the script! Seems to work well. I hit "Test" in openmediavault ad I get the message in Discord almost instantly. However, I don't get any of the regular system messages from openmediavault (all messages are received by email just fine). What could be blocking this?

@beppefiocco
Copy link

If you want to show the output of a file or stdin in bash, and your file includes special characters such as backticks (`) and ", then you can't simply cat filename. You will need to properly escape special characters.

One of the easiest methods to output properly escaped text from a file is to use jq, cut, and rev

Prerequisites

[jq](https://stedolan.github.io/jq/) - Character escaping
[cut](https://linux.die.net/man/1/cut) - Cut characters from string (part of [coreutils](https://www.gnu.org/software/coreutils/coreutils.html), included by default on most systems)
[rev](https://linux.die.net/man/1/rev) - Reversing of characters (part of [util-linux](https://en.wikipedia.org/wiki/Util-linux), included by default on most systems)

Usage:
Simply pass filename to the following command to escape the file contents to stdout:

jq -Rs . <filename | cut -c 2- | rev | cut -c 2- | rev

So, instead of

$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})

use this

$(jq -Rs . <${OMV_NOTIFICATION_MESSAGE_FILE} | cut -c 2- | rev | cut -c 2- | rev)

So the working bash script to put in /usr/share/openmediavault/notification/sink.d/20discord is here:

#!/bin/bash
DISCORD_WEBHOOK='PUT YOUR WEBHOOK LINK HERE'

generate_post_data() {
  cat <<EOF
{
  "content": "",
  "embeds": [{
    "title": "${OMV_NOTIFICATION_SUBJECT}",
    "description": "$(jq -Rs . <${OMV_NOTIFICATION_MESSAGE_FILE} | cut -c 2- | rev | cut -c 2- | rev)",
    "color": "45973",
    "footer": {
        "text": "${OMV_NOTIFICATION_DATE}",
        "icon_url": ""
    }
  }]
}
EOF
}

curl -H "Content-Type: application/json" -X POST -d "$(generate_post_data)" $DISCORD_WEBHOOK

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