Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: missing receivers in json payload for legacy postableAlert (#7603)

Srikanth Chekuriee70474cc75f
diff --git a/pkg/alertmanager/legacyalertmanager/provider.go b/pkg/alertmanager/legacyalertmanager/provider.go
index 0b31c03492..f61d8c3720 100644
--- a/pkg/alertmanager/legacyalertmanager/provider.go
+++ b/pkg/alertmanager/legacyalertmanager/provider.go
@@ -25,6 +25,25 @@ type postableAlert struct {
Receivers []string `json:"receivers"`
}
+func (pa *postableAlert) MarshalJSON() ([]byte, error) {
+ // Marshal the embedded PostableAlert to get its JSON representation.
+ alertJSON, err := json.Marshal(pa.PostableAlert)
+ if err != nil {
+ return nil, err
+ }
+
+ // Unmarshal that JSON into a map so we can add extra fields.
+ var m map[string]interface{}
+ if err := json.Unmarshal(alertJSON, &m); err != nil {
+ return nil, err
+ }
+
+ // Add the Receivers field.
+ m["receivers"] = pa.Receivers
+
+ return json.Marshal(m)
+}
+
const (
alertsPath string = "/v1/alerts"
routesPath string = "/v1/routes"
diff --git a/pkg/alertmanager/legacyalertmanager/provider_test.go b/pkg/alertmanager/legacyalertmanager/provider_test.go
new file mode 100644
index 0000000000..e6f2138be3
--- /dev/null
+++ b/pkg/alertmanager/legacyalertmanager/provider_test.go
@@ -0,0 +1,35 @@
+package legacyalertmanager
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/SigNoz/signoz/pkg/types/alertmanagertypes"
+ "github.com/prometheus/alertmanager/api/v2/models"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestProvider_TestAlert(t *testing.T) {
+ pa := &postableAlert{
+ PostableAlert: &alertmanagertypes.PostableAlert{
+ Alert: models.Alert{
+ Labels: models.LabelSet{
+ "alertname": "test",
+ },
+ GeneratorURL: "http://localhost:9090/graph?g0.expr=up&g0.tab=1",
+ },
+ Annotations: models.LabelSet{
+ "summary": "test",
+ },
+ },
+ Receivers: []string{"receiver1", "receiver2"},
+ }
+
+ body, err := json.Marshal(pa)
+ if err != nil {
+ t.Fatalf("failed to marshal postable alert: %v", err)
+ }
+
+ assert.Contains(t, string(body), "receiver1")
+ assert.Contains(t, string(body), "receiver2")
+}