Skip to content

Commit

Permalink
Support Alertmanager >=0.6.0
Browse files Browse the repository at this point in the history
Alertmanager 0.6.0 API was changed and groupKey is no longer an int, see prometheus/alertmanager#725
  • Loading branch information
prymitive authored and mattbostock committed May 10, 2017
1 parent bf6809e commit 6a86a5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,8 @@ type notification struct {
Receiver string `json:"receiver"`
Status string `json:"status"`
Version string `json:"version"`

// Elasticsearch can't cope with unsigned integers, so convert groupKey
// to a string using a custom type
// Overrides notify.WebhookMessage.GroupKey
GroupKey groupKey `json:"groupKey"`
GroupKey string `json:"groupKey"`

// Timestamp records when the alert notification was received
Timestamp string `json:"@timestamp"`
}

type groupKey uint64

func (g *groupKey) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%d"`, *g)), nil
}
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var amNotification = []byte(`{
"receiver": "alertmanager2es",
"status": "firing",
"version": "3",
"groupKey": 13493306413933147611
"groupKey": "{}/{}/{notify=\"default\":{alertname=\"Foo_Bar\", instance=\"foo\"}"
}`)

var esDocument = []byte(`{"alerts":[{"annotations":{"link":"https://example.com/Foo+Bar","summary":"Alert summary"},"endsAt":"0001-01-01T00:00:00Z","generatorURL":"https://example.com","labels":{"alertname":"Foo_Bar","instance":"foo"},"startsAt":"2017-02-02T16:51:13.507955756Z","status":"firing"}],"commonAnnotations":{"link":"https://example.com/Foo+Bar","summary":"Alert summary"},"commonLabels":{"alertname":"Foo_Bar","instance":"foo"},"externalURL":"https://alertmanager.example.com","groupLabels":{"alertname":"Foo_Bar"},"receiver":"alertmanager2es","status":"firing","version":"3","groupKey":"13493306413933147611","@timestamp":"2017-02-02T19:37:22+01:00"}`)
var esDocument = []byte(`{"alerts":[{"annotations":{"link":"https://example.com/Foo+Bar","summary":"Alert summary"},"endsAt":"0001-01-01T00:00:00Z","generatorURL":"https://example.com","labels":{"alertname":"Foo_Bar","instance":"foo"},"startsAt":"2017-02-02T16:51:13.507955756Z","status":"firing"}],"commonAnnotations":{"link":"https://example.com/Foo+Bar","summary":"Alert summary"},"commonLabels":{"alertname":"Foo_Bar","instance":"foo"},"externalURL":"https://alertmanager.example.com","groupLabels":{"alertname":"Foo_Bar"},"receiver":"alertmanager2es","status":"firing","version":"3","groupKey":"{}/{}/{notify=\"default\":{alertname=\"Foo_Bar\", instance=\"foo\"}","@timestamp":"2017-02-02T19:37:22+01:00"}`)

0 comments on commit 6a86a5c

Please sign in to comment.