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
This commit is contained in:
rcourtman 2025-11-05 19:19:10 +00:00
parent b1831d7b3e
commit ddc787418b

View file

@ -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),