louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
54.98k stars 4.95k forks source link

Discord notifications dont work #4940

Open phyzical opened 1 month ago

phyzical commented 1 month ago

📑 I have found these related issues/pull requests

🛡️ Security Policy

Description

No notifications are sent, test ones work fine.

On down it complains about the payload sent

👟 Reproduction steps

use docker type notification see error on down

👀 Expected behavior

should send notification

😓 Actual Behavior

it breaks

🐻 Uptime-Kuma Version

Version: 1.23.13

💻 Operating System and Arch

docker

🌐 Browser

frifox

🖥️ Deployment Environment

📝 Relevant log output

2024-07-14 14:52:35.734 logstream=stderr    
2024-07-14T14:52:35+08:00 [MONITOR] WARN: Monitor #21 'todo': Failing: Container State is exited | Interval: 60 seconds | Type: docker | Down Count: 0 | Resend Interval: 1
2024-07-14 14:52:35.734 logstream=stderr    
    at async Timeout.safeBeat [as _onTimeout] (/app/server/model/monitor.js:1032:17)
2024-07-14 14:52:35.734 logstream=stderr    
    at async beat (/app/server/model/monitor.js:986:25)
2024-07-14 14:52:35.734 logstream=stderr    
    at async Monitor.sendNotification (/app/server/model/monitor.js:1427:21)
204-07-14 14:52:35.734  logstream=stderr    
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-07-14 14:52:35.734 logstream=stderr    
    at Discord.send (/app/server/notification-providers/discord.js:117:18)
2024-07-14 14:52:35.734 logstream=stderr    
    at Discord.throwGeneralAxiosError (/app/server/notification-providers/notification-provider.js:38:15)
2024-07-14 14:52:35.734 logstream=stderr    
Error: Error: AxiosError: Request failed with status code 400 {"embeds":["0"]}
phyzical commented 1 month ago

as a workaround im just replicating the discord template in a normal webhook (missing some parts but it does what i want)

{
 "embeds": [{
                        "title": "{% if heartbeatJSON.status == 0 %}❌ Your service {{monitorJSON.name}}  went down. ❌{% else %} ✅ Your service {{monitorJSON.name}} is up! ✅{% endif %}",
                        "color": {% if heartbeatJSON.status == 0 %}16711680{% else %}65280{% endif %},
                        "timestamp": "{{heartbeatJSON.time}}",
                        "fields": [
                            {
                                "name": "Service Name",
                                "value": "{{monitorJSON.name}}"
                            },
                            {
                                "name": "Time ({{heartbeatJSON.timezone}})",
                                "value": "{{heartbeatJSON.localDateTime}}"
                            }{% if heartbeatJSON.status == 0 %},
                            {
                                "name": "Error",
                                "value": "{{heartbeatJSON.msg}}"
                            }{% endif %}
                        ]
                    }]     
}
CommanderStorm commented 1 month ago

Discord might have changed something about how embeds are handled.

Currently, we supply this embed (code has changed a bit since the last release, but nothing relevant to this issue):

https://github.com/louislam/uptime-kuma/blob/1a5a1a6e5d019b3dc58d114327f6765da0bee5f5/server/notification-providers/discord.js#L40-L62

Given that you likely have discord set up as a notification provider and that this kind of debugging does not scale well: Could you try reproducing which of the fields we supply is now not allowed or which we are missing?

phyzical commented 1 month ago

hmm thats where i got the source to supply to the generic webhook, ill give the full payload a test later in the week and get back to you

in the meantime would we expect to see {"embeds":["0"]} instead of the actual payload in the error?

GrigoryLantsov commented 1 month ago

Notifications work perfectly on my side for Docker and HTTP monitors. The same error exists only on the postgres type, where notifications are not being sent. Can you take a look on that implementation?