From b364ca535e7f62df23f6f538d8bba66c7ca868eb Mon Sep 17 00:00:00 2001 From: Alexis Savin Date: Tue, 16 Feb 2016 11:54:30 +0100 Subject: [PATCH] Adding support for slack icon_emoji in slack config. ``` slack_configs: - send_resolved: true username: 'Prometheus' channel: '#monitoring' icon_emoji: ':prometheus:' api_url: 'https://hooks.slack.com/services/' ``` --- config/notifiers.go | 2 ++ notify/impl.go | 2 ++ template/default.tmpl | 1 + 3 files changed, 5 insertions(+) diff --git a/config/notifiers.go b/config/notifiers.go index 51303d74..1f5736f1 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -62,6 +62,7 @@ var ( Username: `{{ template "slack.default.username" . }}`, Title: `{{ template "slack.default.title" . }}`, TitleLink: `{{ template "slack.default.titlelink" . }}`, + IconEmoji: `{{ template "slack.default.iconemoji" . }}`, Pretext: `{{ template "slack.default.pretext" . }}`, Text: `{{ template "slack.default.text" . }}`, Fallback: `{{ template "slack.default.fallback" . }}`, @@ -182,6 +183,7 @@ type SlackConfig struct { Pretext string `yaml:"pretext"` Text string `yaml:"text"` Fallback string `yaml:"fallback"` + IconEmoji string `yaml:"icon_emoji"` // Catches all undefined fields and must be empty after parsing. XXX map[string]interface{} `yaml:",inline"` diff --git a/notify/impl.go b/notify/impl.go index b7c53c1f..a10054c3 100644 --- a/notify/impl.go +++ b/notify/impl.go @@ -450,6 +450,7 @@ func (*Slack) name() string { return "slack" } type slackReq struct { Channel string `json:"channel,omitempty"` Username string `json:"username,omitempty"` + IconEmoji string `json:"icon_emoji,omitempty"` Attachments []slackAttachment `json:"attachments"` } @@ -492,6 +493,7 @@ func (n *Slack) Notify(ctx context.Context, as ...*types.Alert) error { req := &slackReq{ Channel: tmplText(n.conf.Channel), Username: tmplText(n.conf.Username), + IconEmoji: tmplText(n.conf.IconEmoji), Attachments: []slackAttachment{*attachment}, } if err != nil { diff --git a/template/default.tmpl b/template/default.tmpl index 45c18d49..54ddb468 100644 --- a/template/default.tmpl +++ b/template/default.tmpl @@ -17,6 +17,7 @@ {{ define "slack.default.fallback" }}{{ template "slack.default.title" . }} | {{ template "slack.default.titlelink" . }}{{ end }} {{ define "slack.default.pretext" }}{{ end }} {{ define "slack.default.titlelink" }}{{ template "__alertmanagerURL" . }}{{ end }} +{{ define "slack.default.iconemoji" }}{{ end }} {{ define "slack.default.text" }}{{ end }}