Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn annotations with values starting with "http://" or "https://" into PagerDuty links #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"regexp"
"strings"

"github.com/PagerDuty/go-pagerduty"
"github.com/sensu-community/sensu-plugin-sdk/sensu"
Expand Down Expand Up @@ -207,6 +208,7 @@ func manageIncident(event *corev2.Event) error {
Action: action,
Payload: &pdPayload,
DedupKey: dedupKey,
Links: getPagerDutyLinks(event),
}

eventResponse, err := pagerduty.ManageEvent(pdEvent)
Expand Down Expand Up @@ -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
}