This commit is contained in:
Iru 2025-11-23 20:41:00 +01:00
commit e5a70b9e91
9 changed files with 298 additions and 31 deletions

View file

@ -1,55 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
type Alert struct {
Status string `json:"status"`
StartsAt string `json:"startsAt"`
EndsAt string `json:"endsAt"`
GeneratorURL string `json:"generatorURL"`
Fingerprint string `json:"fingerprint"`
SilenceURL string `json:"silenceURL"`
DashboardURL string `json:"dashboardURL"`
PanelURL string `json:"panelURL"`
ValueString string `json:"valueString"`
OrgId int `json:"orgId"`
Labels map[string]any `json:"labels"`
Annotations map[string]any `json:"annotations"`
values map[int]any `json:"values"`
}
type Payload struct {
Receiver string `json:"receiver"`
Status string `json:"firing"`
ExternalURL string `json:"externalURL"`
Version string `json:"version"`
GroupKey string `json:"groupKey"`
TruncatedAlerts int `json:"truncatedAlerts"`
OrgID int `json:"orgId"`
Title string `json:"title"`
State string `json"state"`
Message string `json:"message"`
Alerts []Alert `json:"alerts"`
GroupLabels map[string]any `json:"groupLabels"`
CommonLabels map[string]any `json:"groupLabels"`
CommonAnnotations map[string]any `json:"commonAnnotations"`
}
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
data, err := os.ReadFile("./alert.json")
check(err)
var payload Payload
p1 := json.Unmarshal([]byte(data), &payload)
check(p1)
fmt.Printf("Full payload: %+v\n", payload)
}