Skip to content

Commit

Permalink
Fix pushover limits (title, message, url) (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
josedonizetti authored and stuartnelson3 committed Oct 25, 2017
1 parent 0fa8522 commit 0a16b09
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,17 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
parameters := url.Values{}
parameters.Add("token", tmpl(string(n.conf.Token)))
parameters.Add("user", tmpl(string(n.conf.UserKey)))

title := tmpl(n.conf.Title)
message := tmpl(n.conf.Message)
parameters.Add("title", title)
if len(title) > 512 {
title = title[:512]
level.Debug(n.logger).Log("msg", "Truncated title due to Pushover message limit", "truncated_title", title, "incident", key)
if len(title) > 250 {
title = title[:247] + "..."
level.Debug(n.logger).Log("msg", "Truncated title due to Pushover title limit", "truncated_title", title, "incident", key)
}
if len(title)+len(message) > 512 {
message = message[:512-len(title)]
parameters.Add("title", title)

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)
}
message = strings.TrimSpace(message)
Expand All @@ -991,7 +993,14 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
message = "(no details)"
}
parameters.Add("message", message)
parameters.Add("url", tmpl(n.conf.URL))

supplementaryUrl := tmpl(n.conf.URL)
if len(supplementaryUrl) > 512 {
supplementaryUrl = supplementaryUrl[:509] + "..."
level.Debug(n.logger).Log("msg", "Truncated URL due to Pushover url limit", "truncated_url", supplementaryUrl, "incident", key)
}
parameters.Add("url", supplementaryUrl)

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())))
Expand Down

0 comments on commit 0a16b09

Please sign in to comment.