Skip to content

Commit e016238

Browse files
author
Ganesh Vernekar
committed
Fix arguments for notify.BuildPipeline
Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent c595cad commit e016238

File tree

11 files changed

+1850
-1
lines changed

11 files changed

+1850
-1
lines changed

pkg/alertmanager/alertmanager.go

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import (
1818
"github.com/prometheus/alertmanager/inhibit"
1919
"github.com/prometheus/alertmanager/nflog"
2020
"github.com/prometheus/alertmanager/notify"
21+
"github.com/prometheus/alertmanager/notify/email"
22+
"github.com/prometheus/alertmanager/notify/hipchat"
23+
"github.com/prometheus/alertmanager/notify/opsgenie"
24+
"github.com/prometheus/alertmanager/notify/pagerduty"
25+
"github.com/prometheus/alertmanager/notify/pushover"
26+
"github.com/prometheus/alertmanager/notify/slack"
27+
"github.com/prometheus/alertmanager/notify/victorops"
28+
"github.com/prometheus/alertmanager/notify/webhook"
29+
"github.com/prometheus/alertmanager/notify/wechat"
2130
"github.com/prometheus/alertmanager/provider/mem"
2231
"github.com/prometheus/alertmanager/silence"
2332
"github.com/prometheus/alertmanager/template"
@@ -196,8 +205,12 @@ func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config) error {
196205
return d + waitFunc()
197206
}
198207

208+
integrationsMap, err := buildIntegrationsMap(conf.Receivers, tmpl, am.logger)
209+
if err != nil {
210+
return nil
211+
}
199212
pipeline = notify.BuildPipeline(
200-
conf.Receivers,
213+
integrationsMap,
201214
waitFunc,
202215
am.inhibitor,
203216
silence.NewSilencer(am.silences, am.marker, am.logger),
@@ -231,3 +244,67 @@ func (am *Alertmanager) Stop() {
231244
func (am *Alertmanager) ServeHTTP(w http.ResponseWriter, req *http.Request) {
232245
am.router.ServeHTTP(w, req)
233246
}
247+
248+
// buildIntegrationsMap builds a map of name to the list of integration notifiers off of a
249+
// list of receiver config.
250+
func buildIntegrationsMap(nc []*config.Receiver, tmpl *template.Template, logger log.Logger) (map[string][]notify.Integration, error) {
251+
integrationsMap := make(map[string][]notify.Integration, len(nc))
252+
for _, rcv := range nc {
253+
integrations, err := buildReceiverIntegrations(rcv, tmpl, logger)
254+
if err != nil {
255+
return nil, err
256+
}
257+
integrationsMap[rcv.Name] = integrations
258+
}
259+
return integrationsMap, err
260+
}
261+
262+
// buildReceiverIntegrations builds a list of integration notifiers off of a
263+
// receiver config.
264+
// Taken from https://github.com/prometheus/alertmanager/blob/94d875f1227b29abece661db1a68c001122d1da5/cmd/alertmanager/main.go#L112-L159.
265+
func buildReceiverIntegrations(nc *config.Receiver, tmpl *template.Template, logger log.Logger) ([]notify.Integration, error) {
266+
var (
267+
errs types.MultiError
268+
integrations []notify.Integration
269+
add = func(name string, i int, rs notify.ResolvedSender, f func(l log.Logger) (notify.Notifier, error)) {
270+
n, err := f(log.With(logger, "integration", name))
271+
if err != nil {
272+
errs.Add(err)
273+
return
274+
}
275+
integrations = append(integrations, notify.NewIntegration(n, rs, name, i))
276+
}
277+
)
278+
279+
for i, c := range nc.WebhookConfigs {
280+
add("webhook", i, c, func(l log.Logger) (notify.Notifier, error) { return webhook.New(c, tmpl, l) })
281+
}
282+
for i, c := range nc.EmailConfigs {
283+
add("email", i, c, func(l log.Logger) (notify.Notifier, error) { return email.New(c, tmpl, l), nil })
284+
}
285+
for i, c := range nc.PagerdutyConfigs {
286+
add("pagerduty", i, c, func(l log.Logger) (notify.Notifier, error) { return pagerduty.New(c, tmpl, l) })
287+
}
288+
for i, c := range nc.OpsGenieConfigs {
289+
add("opsgenie", i, c, func(l log.Logger) (notify.Notifier, error) { return opsgenie.New(c, tmpl, l) })
290+
}
291+
for i, c := range nc.WechatConfigs {
292+
add("wechat", i, c, func(l log.Logger) (notify.Notifier, error) { return wechat.New(c, tmpl, l) })
293+
}
294+
for i, c := range nc.SlackConfigs {
295+
add("slack", i, c, func(l log.Logger) (notify.Notifier, error) { return slack.New(c, tmpl, l) })
296+
}
297+
for i, c := range nc.HipchatConfigs {
298+
add("hipchat", i, c, func(l log.Logger) (notify.Notifier, error) { return hipchat.New(c, tmpl, l) })
299+
}
300+
for i, c := range nc.VictorOpsConfigs {
301+
add("victorops", i, c, func(l log.Logger) (notify.Notifier, error) { return victorops.New(c, tmpl, l) })
302+
}
303+
for i, c := range nc.PushoverConfigs {
304+
add("pushover", i, c, func(l log.Logger) (notify.Notifier, error) { return pushover.New(c, tmpl, l) })
305+
}
306+
if errs.Len() > 0 {
307+
return nil, &errs
308+
}
309+
return integrations, nil
310+
}

0 commit comments

Comments
 (0)