From ddc787418badd6896121bce0bfd7373240e83c82 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 5 Nov 2025 19:19:10 +0000 Subject: [PATCH] Round float values in webhook payloads to 1 decimal place Webhook alert payloads now round Value and Threshold fields to 1 decimal place before template rendering. This eliminates excessive precision in webhook messages (e.g., 62.27451680630036 becomes 62.3). The fix is applied in prepareWebhookData() so all webhook templates benefit automatically, including Google Space webhooks, generic JSON webhooks, and custom templates. Related to #619 --- internal/notifications/notifications.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.go index dbd049f..70f1bcc 100644 --- a/internal/notifications/notifications.go +++ b/internal/notifications/notifications.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "math" "net/http" "net/url" "os/exec" @@ -1615,6 +1616,10 @@ func (n *NotificationManager) prepareWebhookData(alert *alerts.Alert, customFiel ackTime = alert.AckTime.Format(time.RFC3339) } + // Round Value and Threshold to 1 decimal place for cleaner webhook payloads + roundedValue := math.Round(alert.Value*10) / 10 + roundedThreshold := math.Round(alert.Threshold*10) / 10 + return WebhookPayloadData{ ID: alert.ID, Level: string(alert.Level), @@ -1624,8 +1629,8 @@ func (n *NotificationManager) prepareWebhookData(alert *alerts.Alert, customFiel Node: alert.Node, Instance: instance, Message: alert.Message, - Value: alert.Value, - Threshold: alert.Threshold, + Value: roundedValue, + Threshold: roundedThreshold, ValueFormatted: formatMetricValue(alert.Type, alert.Value), ThresholdFormatted: formatMetricThreshold(alert.Type, alert.Threshold), StartTime: alert.StartTime.Format(time.RFC3339),