Pushover: support HTML, URL title and custom sounds (#1634)

* Support HTML inside Pushover message

Signed-off-by: Tomas Dabasinskas <tomas@dabasinskas.net>
This commit is contained in:
Tomas Dabasinskas 2018-12-18 16:15:30 +02:00 committed by Max Leonard Inden
parent 91306b8ec5
commit a87e81dd2c
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
2 changed files with 18 additions and 2 deletions

View File

@ -135,6 +135,7 @@ var (
Priority: `{{ if eq .Status "firing" }}2{{ else }}0{{ end }}`, // emergency (firing) or normal
Retry: duration(1 * time.Minute),
Expire: duration(1 * time.Hour),
HTML: false,
}
)
@ -532,9 +533,12 @@ type PushoverConfig struct {
Title string `yaml:"title,omitempty" json:"title,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
URL string `yaml:"url,omitempty" json:"url,omitempty"`
URLTitle string `yaml:"url_title,omitempty" json:"url_title,omitempty`
Sound string `yaml:"sound,omitempty" json:"sound,omitempty"`
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"`
Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"`
HTML bool `yaml:"html,omitempty" json:"html,omitempty"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.

View File

@ -1396,8 +1396,12 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
level.Debug(n.logger).Log("msg", "Notifying Pushover", "incident", key)
var err error
var (
err error
message string
)
tmpl := tmplText(n.tmpl, data, &err)
tmplHTML := tmplHTML(n.tmpl, data, &err)
parameters := url.Values{}
parameters.Add("token", tmpl(string(n.conf.Token)))
@ -1410,7 +1414,13 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}
parameters.Add("title", title)
message := tmpl(n.conf.Message)
if n.conf.HTML {
parameters.Add("html", "1")
message = tmplHTML(n.conf.Message)
} else {
message = tmpl(n.conf.Message)
}
if len(message) > 1024 {
message = message[:1021] + "..."
level.Debug(n.logger).Log("msg", "Truncated message due to Pushover message limit", "truncated_message", message, "incident", key)
@ -1428,10 +1438,12 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
level.Debug(n.logger).Log("msg", "Truncated URL due to Pushover url limit", "truncated_url", supplementaryURL, "incident", key)
}
parameters.Add("url", supplementaryURL)
parameters.Add("url_title", tmpl(n.conf.URLTitle))
parameters.Add("priority", tmpl(n.conf.Priority))
parameters.Add("retry", fmt.Sprintf("%d", int64(time.Duration(n.conf.Retry).Seconds())))
parameters.Add("expire", fmt.Sprintf("%d", int64(time.Duration(n.conf.Expire).Seconds())))
parameters.Add("sound", tmpl(n.conf.Sound))
if err != nil {
return false, err
}