Parse pagerduty response body

This commit is contained in:
Ian Gulliver
2025-08-20 23:18:40 -07:00
parent a670da769f
commit ca4b6238c0

View File

@@ -21,6 +21,12 @@ type pdPayload struct {
Severity string `json:"severity"` Severity string `json:"severity"`
} }
type pdResponse struct {
DedupKey string `json:"dedup_key"`
Message string `json:"message"`
Status string `json:"status"`
}
type pdClient struct { type pdClient struct {
c *http.Client c *http.Client
routingKey string routingKey string
@@ -72,5 +78,15 @@ func (pd *pdClient) sendAlert(msg string) error {
log.Printf("[<-pagerduty] %s", string(body)) log.Printf("[<-pagerduty] %s", string(body))
pdResp := pdResponse{}
err = json.Unmarshal(body, &pdResp)
if err != nil {
return err
}
if pdResp.Status != "success" {
return fmt.Errorf("%s: %s", pdResp.Status, pdResp.Message)
}
return nil return nil
} }