From 327db5ad804fd8a54b72845c5caa3e6fd5229e01 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Thu, 14 Aug 2025 19:28:52 +0000 Subject: [PATCH] fix: add debug logging for Telegram webhook issues - Enhanced logging to diagnose chat_id extraction problems - Log payload being sent to Telegram for debugging - Better error messages when chat_id is missing or invalid --- internal/notifications/notifications.go | 43 +++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.go index 64c0dd86b..d4270a21b 100644 --- a/internal/notifications/notifications.go +++ b/internal/notifications/notifications.go @@ -571,6 +571,15 @@ func (n *NotificationManager) sendWebhookRequest(webhook WebhookConfig, jsonData req.Header.Set(key, value) } + // Debug log the payload for Telegram webhooks + if webhook.Service == "telegram" { + log.Debug(). + Str("webhook", webhook.Name). + Str("url", webhookURL). + Str("payload", string(jsonData)). + Msg("Sending Telegram webhook") + } + // Send request client := &http.Client{ Timeout: 30 * time.Second, @@ -663,13 +672,35 @@ func (n *NotificationManager) sendWebhook(webhook WebhookConfig, alert *alerts.A data := n.prepareWebhookData(alert, nil) // For Telegram, extract chat_id from URL if present - if webhook.Service == "telegram" && strings.Contains(webhook.URL, "chat_id=") { - // Extract chat_id from URL query params - if u, err := url.Parse(webhook.URL); err == nil { - chatID := u.Query().Get("chat_id") - if chatID != "" { - data.ChatID = chatID + if webhook.Service == "telegram" { + if strings.Contains(webhook.URL, "chat_id=") { + // Extract chat_id from URL query params + if u, err := url.Parse(webhook.URL); err == nil { + chatID := u.Query().Get("chat_id") + if chatID != "" { + data.ChatID = chatID + log.Debug(). + Str("webhook", webhook.Name). + Str("chatID", chatID). + Msg("Extracted Telegram chat_id from URL") + } else { + log.Warn(). + Str("webhook", webhook.Name). + Str("url", webhook.URL). + Msg("chat_id parameter in URL is empty") + } + } else { + log.Error(). + Err(err). + Str("webhook", webhook.Name). + Str("url", webhook.URL). + Msg("Failed to parse Telegram webhook URL") } + } else { + log.Error(). + Str("webhook", webhook.Name). + Str("url", webhook.URL). + Msg("Telegram webhook URL missing chat_id parameter - notifications will fail") } }