Example #1
0
func (p *PagerDuty) Send(i *event.Incident) error {
	var pdPevent *pagerduty.Event
	switch i.Status {
	case event.CRITICAL, event.WARNING:
		pdPevent = pagerduty.NewTriggerEvent(p.conf.Key, i.FormatDescription())
	case event.OK:
		pdPevent = pagerduty.NewResolveEvent(p.conf.Key, i.FormatDescription())
	}
	pdPevent.IncidentKey = string(string(i.IndexName()))

	_, _, err := pagerduty.Submit(pdPevent)
	return err
}
Example #2
0
func (pda *pagerDutyAlerter) Alert(event *Event) {
	description := fmt.Sprintf("%s is DOWN since %s.", event.Check.AlertDescription(), event.Check.DownSince.Format(time.RFC3339))
	e := pagerduty.NewTriggerEvent(pda.serviceKey, description)
	e.Details["checked_at"] = event.Time.Format(time.RFC3339)
	e.Details["duration"] = event.Duration.String()
	e.Details["status_code"] = event.StatusCode
	e.Details["was_up_for"] = event.Check.WasUpFor.String()
	e.IncidentKey = event.Check.Key
	for {
		_, statusCode, _ := pagerduty.Submit(e)
		if statusCode < 500 {
			break
		} else {
			// Wait a bit before trying again
			time.Sleep(3 * time.Second)
		}
	}
}