Skip to content

Commit

Permalink
Merge pull request #2472 from asvinours/bugfix/pd_payload
Browse files Browse the repository at this point in the history
[pagerduty] send full event payload on resolve
  • Loading branch information
docmerlin authored Feb 4, 2021
2 parents 873d93b + 9d59d57 commit 23e1d6a
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions services/pagerduty2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,35 +253,6 @@ func (s *Service) Alert(routingKey string, links []LinkTemplate, alertID, desc s
return nil
}

func (s *Service) sendResolve(c Config, routingKey, alertID string) (string, io.Reader, error) {
// create a new AlertPayload for us to fire off
type Resolve struct {
RoutingKey string `json:"routing_key"`
DedupKey string `json:"dedup_key"`
EventAction string `json:"event_action"`
}

ap := Resolve{}

if routingKey == "" {
ap.RoutingKey = c.RoutingKey
} else {
ap.RoutingKey = routingKey
}

ap.DedupKey = alertID
ap.EventAction = "resolve"

var post bytes.Buffer
enc := json.NewEncoder(&post)
err := enc.Encode(ap)
if err != nil {
return "", nil, err
}

return c.URL, &post, nil
}

// preparePost is a helper method that sets up the payload for transmission to PagerDuty
func (s *Service) preparePost(routingKey string, links []LinkTemplate, alertID, desc string, level alert.Level, timestamp time.Time, data alert.EventData) (string, io.Reader, error) {
c := s.config()
Expand All @@ -300,8 +271,10 @@ func (s *Service) preparePost(routingKey string, links []LinkTemplate, alertID,
case alert.Info:
severity = "info"
default:
// default is a 'resolve' function
return s.sendResolve(c, routingKey, alertID)
// On resolve, we also want to send the full payload
eventType = "resolve"
// the severity field is required even for resolve event
severity = "info"
}

// create a new AlertPayload for us to fire off
Expand Down

0 comments on commit 23e1d6a

Please sign in to comment.