crazy-max / diun

Receive notifications when an image is updated on a Docker registry
https://crazymax.dev/diun/
MIT License
3.12k stars 116 forks source link

Discord notification without Embed when "renderFields" option set to false #614

Open BDDam opened 2 years ago

BDDam commented 2 years ago

Hi,

I've recently set up Diun with Discord notifications and it's been a real life-changer for monitoring tag versions. Thanks for the great job !

Now, in a similar fashion to (now closed) issue #468, I am looking to have short and concise notification messages on Discord.

I was able to customize the message and set the renderFields option to false, but I notice on Discord the notification still uses a rather empty Embed :

diun

I would have expected and preferred that by disabling fields rendering, there would only the text message without additional content.

Suggestions:

Thank you !

m1cypher commented 2 years ago

@BDDam I am new to this docker world and am not sure how to setup the discord notifications. Can you point me in the right direction? Do I need to add a file to the container or to the host? Thank you.

BDDam commented 2 years ago

@BDDam I am new to this docker world and am not sure how to setup the discord notifications. Can you point me in the right direction? Do I need to add a file to the container or to the host? Thank you.

@odintheravenking Depends if you want it based on configuration file or on environnment variables (see https://crazymax.dev/diun/config/) I use the diun.yml configuration file, which is read within the container. So in essence, it must be present in your container.

But by mounting it as a volume when building your container, it will be present on your host system (think of it as some kind of "shared folder" between the container and the host, so don't delete that file on your host).

Here's an example of my mounts for the container: on my host system, file is located at /volume1/docker/diun/diun.yml and in the container, file is at root level /diun.yml (inspired from the documentation page : https://crazymax.dev/diun/install/docker/#usage)

  diun:
    [...]
    volumes:
      - /volume1/docker/diun/data:/data
      - /volume1/docker/diun/diun.yml:/diun.yml:ro
      - /volume1/docker/diun/docker-images.yml:/docker-images.yml:ro
      - /var/run/docker.sock:/var/run/docker.sock

Above is using docker-compose (recommanded) but if using docker run command (not tested): -v /volume1/docker/diun/diun.yml:/diun.yml:ro

Obviously, make sure it matches your file paths !

As for the actual Discord notification settings, it's all here really: https://crazymax.dev/diun/notif/discord/ Again as example, here are my settings in that same configuration file:

notif:
  discord:
    webhookURL: https://discord.com/api/webhooks/<replace by your own Discord server webhook>
    renderFields: false
    templateBody: |
      Image {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image.Path }}:{{ .Entry.Image.Tag }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image.Path }}:{{ .Entry.Image.Tag }}**{{ end }} available ({{ if (eq .Entry.Provider "docker") }}**container update**{{ else }}{{ if (eq .Entry.Status "new") }}**new tag**{{ else }}**tag update**{{ end }}{{ end }})

Hoping this will help you !

No0Vad commented 1 year ago

Having renderFields set to false, I also expected the Discord embed body to not be shown. image

A example after I remove them manually in Discord image

I'm currently experimenting and trying Diun myself and I like it so far! 🙂

xanty9 commented 1 week ago

Dont know if this is still an issue for you, but you can use a script to send notifications. I was running into the same problem, not wanting the embed to show and this fixed it.

make sure to mount the script in your compose and chmod +x the script In your config.yml for diun

script:
   cmd: "/scripts/diun_notification.sh"
   args:

here is the script I am using. Make sure to change the https://discord.com/api/webhooks line to your actual webhook url also if you would like to customize what is sent with the message. follow docs to find the info you want to send over, https://crazymax.dev/diun/notif/script/ then for example you want to send over DIUN_VERSION add to the script under env variables VERSION=DIUN_VERSION and in the message add MESSAGE=" $VERSION"

#!/bin/sh

# Read environment variables passed by Diun
IMAGE="$DIUN_ENTRY_IMAGE"
HUB_LINK="$DIUN_ENTRY_HUBLINK"
HOSTNAME="$DIUN_HOSTNAME"

# Message
MESSAGE="<@357640811199856641> Docker Image ($IMAGE) has been released. $HUB_LINK Hosted on $HOSTNAME"

# Send to Discord
wget --post-data "{\"content\": \"$MESSAGE\"}" \
     --header="Content-Type: application/json" \
     "https://discord.com/api/webhooks"

Discord_xQLwzFTzKs