Skip to content

Instantly share code, notes, and snippets.

@hydrosquall
Last active March 25, 2024 14:30
Show Gist options
  • Save hydrosquall/e9d264e7a4afc0ecafa0aa6c361a3e7a to your computer and use it in GitHub Desktop.
Save hydrosquall/e9d264e7a4afc0ecafa0aa6c361a3e7a to your computer and use it in GitHub Desktop.
Webhook Payload: Datadog Graphs -> Discord Bot
{
"embeds":[
{
"title":"$EVENT_TITLE",
"url":"$LINK",
"description":"$EVENT_MSG",
"thumbnail":{
"url":"$SNAPSHOT"
}
},
{
"fields":[
{
"name":"tags",
"value":"$TAGS",
"inline":true
}
]
}
]
}
@hydrosquall
Copy link
Author

Ah, I'm sorry to hear that @coder4temp - are you getting any specific error messages?

@hasan4temp
Copy link

hasan4temp commented Feb 28, 2024

Ah, I'm sorry to hear that @coder4temp - are you getting any specific error messages?

no im not getting any error but the webhook alert looks ugly. i have shared an image and as you can see the graph link isnt showing as an example. I could like to show the graph link as an embeded image.



System load crossed 2


@webhook-discord

[![Metric Graph](https://p.us5.datadoghq.com/snapshot/view/dd-snapshots-us5-prod/org_1300144564/2024-02-28/873aa431eede7d3389a62c82c823bd6f514b6cb5.png)](https://us5.datadoghq.com/monitors/428395?group=host%3Arpi3&from_ts=1709098855000&to_ts=1709100055000&event_id=7463125596723904026&source=monitor_notif)

system.load.5 over host:rpi3 was > 2.0 at least once during the last 5m.

The monitor was last triggered at Wed Feb 28 2024 05:55:55 UTC.

-```

@hydrosquall
Copy link
Author

Hm, I'm not sure that I understand what the bug is. It looks like the webhook is returning markdown syntax for a picture, which if clicked would open a link to your monitor.

Metric Graph

Can you clarify the difference between what you're hoping for, and what you're currently getting instead?

@coder4temp
Copy link

coder4temp commented Feb 29, 2024

Hm, I'm not sure that I understand what the bug is. It looks like the webhook is returning markdown syntax for a picture, which if clicked would open a link to your monitor.

Metric Graph

Can you clarify the difference between what you're hoping for, and what you're currently getting instead?

I was hoping if there was an option to load the image in discord an embedded image isn't of clicking the link

@hydrosquall
Copy link
Author

Oh, I see - you are hoping for the embed image or thumbnail ( https://birdie0.github.io/discord-webhooks-guide/structure/embed/thumbnail.html ).

That should still be working, sometimes it takes a few minutes for the snapshot URL to generate. To debug, I suggest putting the $SNAPSHOT variable into your message, and checking how long it takes for that to start pointing to a valid URL.

@hasan4temp
Copy link

hasan4temp commented Mar 6, 2024

Oh, I see - you are hoping for the embed image or thumbnail ( https://birdie0.github.io/discord-webhooks-guide/structure/embed/thumbnail.html ).

That should still be working, sometimes it takes a few minutes for the snapshot URL to generate. To debug, I suggest putting the $SNAPSHOT variable into your message, and checking how long it takes for that to start pointing to a valid URL.

Ah i see in my test notification for couple i got the thumbnail image but most of the time it doesnt show. so do you have any suggestions? how can i fix it ?

{
"embeds":[
{
"title":"$EVENT_TITLE",
"url":"$LINK",
"description":"$EVENT_MSG",
"thumbnail":{
"url":"$SNAPSHOT"
}
},
{
"fields":[
{
"name":"tags",
"value":"$TAGS",
"inline":true
}
]
}
]
}

this is the payload im using

@hydrosquall
Copy link
Author

hydrosquall commented Mar 7, 2024 via email

@coder4temp
Copy link

It's hard to know what. most of the time means, I can't tell if that's an issue on Discord or Datadog's side. For cases when it doesn't show, does the clickable link still work, or is that broken too?

On Wed, Mar 6, 2024 at 3:51 PM hasan4temp @.> wrote: @.* commented on this gist. ------------------------------ Oh, I see - you are hoping for the embed image or thumbnail ( https://birdie0.github.io/discord-webhooks-guide/structure/embed/thumbnail.html ). That should still be working, sometimes it takes a few minutes for the snapshot URL to generate. To debug, I suggest putting the $SNAPSHOT variable into your message, and checking how long it takes for that to start pointing to a valid URL. Ah i see in my test notification for couple i got the thumbnail image but most of the time it doesnt show. so do you have any suggestions? how can i fix it ? — Reply to this email directly, view it on GitHub https://gist.github.com/hydrosquall/e9d264e7a4afc0ecafa0aa6c361a3e7a#gistcomment-4973801 or unsubscribe https://github.com/notifications/unsubscribe-auth/ACE2MMYVC2YERMXHHQSJLKDYW56V5BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTANZUG4ZDCNJXU52HE2LHM5SXFJTDOJSWC5DF . You are receiving this email because you authored the thread. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

Yeah the link works. Then I'll have to settle with this. Thanks for your help

@timetinytim
Copy link

Chiming in here as I'm encountering similar issues.

While investigating, I found out that discord's support of markdown is somewhat limited, and doesn't include images. The $EVENT_MSG and $INCIDENT_MSG vars in datadog both include an image markdown link, but since discord doesn't support it, it will instead always display that ugly [![Metric Graph](https://...)

Additionally after doing some additional testing, I confirmed that sometimes the thumbnail image won't display because $SNAPSHOT URL will point to an image that hasn't been generated yet. The solution would be to wait a little bit before displaying the message, but I don't think there's a way to do that with discord (I'm considering creating a simple app that waits/processes the message before it reaches discord to fix the issue...).

For now, I'm using this setup, which is admittedly less "complete", but is concise & clear at a glance, even without the image. Somehow in my testing the image seems to render much more often, though I could have just been lucky:

{
   "avatar_url": "https://cdn-1.webcatalog.io/catalog/datadog/datadog-icon.png",
   "embeds": [
      {
         "title": "$ALERT_TITLE",
         "color": 6499494,
         "url": "$LINK",
         "description": "### $EVENT_TITLE\n$ALERT_STATUS",
         "image": {
            "url": "$SNAPSHOT"
         }
      },
      {
         "fields": [
            {
               "name": "tags",
               "value": "$TAGS",
               "inline": true
            }
         ]
      }
   ]
}

@Prisoner2-6-7
Copy link

Chiming in here as I'm encountering similar issues.

While investigating, I found out that discord's support of markdown is somewhat limited, and doesn't include images. The $EVENT_MSG and $INCIDENT_MSG vars in datadog both include an image markdown link, but since discord doesn't support it, it will instead always display that ugly [![Metric Graph](https://...)

Additionally after doing some additional testing, I confirmed that sometimes the thumbnail image won't display because $SNAPSHOT URL will point to an image that hasn't been generated yet. The solution would be to wait a little bit before displaying the message, but I don't think there's a way to do that with discord (I'm considering creating a simple app that waits/processes the message before it reaches discord to fix the issue...).

For now, I'm using this setup, which is admittedly less "complete", but is concise & clear at a glance, even without the image. Somehow in my testing the image seems to render much more often, though I could have just been lucky:

{
   "avatar_url": "https://cdn-1.webcatalog.io/catalog/datadog/datadog-icon.png",
   "embeds": [
      {
         "title": "$ALERT_TITLE",
         "color": 6499494,
         "url": "$LINK",
         "description": "### $EVENT_TITLE\n$ALERT_STATUS",
         "image": {
            "url": "$SNAPSHOT"
         }
      },
      {
         "fields": [
            {
               "name": "tags",
               "value": "$TAGS",
               "inline": true
            }
         ]
      }
   ]
}

image

the avatar is nice but i still dont see graph image.

@timetinytim
Copy link

Yeah it's a dice roll whether Datadog creates the image in time before discord receives & shows the post. I don't think there's a way around that at the moment.

I really do need to create middleman app to fix this.

@hydrosquall
Copy link
Author

hydrosquall commented Mar 25, 2024 via email

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