diff --git a/main.go b/main.go index bdbd0e9..9f090d1 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "regexp" + "strings" "github.com/PagerDuty/go-pagerduty" "github.com/sensu-community/sensu-plugin-sdk/sensu" @@ -207,6 +208,7 @@ func manageIncident(event *corev2.Event) error { Action: action, Payload: &pdPayload, DedupKey: dedupKey, + Links: getPagerDutyLinks(event), } eventResponse, err := pagerduty.ManageEvent(pdEvent) @@ -324,3 +326,24 @@ func getDetails(event *corev2.Event) (interface{}, error) { } return details, nil } + +type Link struct { + Text string `json:"text"` + Href string `json:"href"` +} + +func getPagerDutyLinks(event *corev2.Event) []interface{} { + var output []interface{} + output = make([]interface{}, 0, len(event.Check.Annotations)) + + for name, value := range event.Check.Annotations { + if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") { // value seems to be a link + output = append(output, Link{ + Text: name, + Href: value, + }) + } + } + + return output +}