diff --git a/CHANGELOG.md b/CHANGELOG.md index b693dce0e..7c25fb2a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - [#1980](https://github.com/influxdata/kapacitor/pull/1980): Fix discovery service lost config, thanks @flisky! - [#2335](https://github.com/influxdata/kapacitor/pull/2335): Fix panic when setting a zero interval for ticker, this affected deadman and stats nodes. - [#2340](https://github.com/influxdata/kapacitor/pull/2340): Fix a panic on int div-by-zero, instead return an error. +- [#2358](https://github.com/influxdata/kapacitor/pull/2360): Fix Kapacitor ignoring the pushover().userKey('') TICKScript operation ## v1.5.5 [2020-04-20] diff --git a/alert.go b/alert.go index dfd2fe426..0ca7fec70 100644 --- a/alert.go +++ b/alert.go @@ -400,6 +400,9 @@ func newAlertNode(et *ExecutingTask, n *pipeline.AlertNode, d NodeDiagnostic) (a if p.Sound != "" { c.Sound = p.Sound } + if p.UserKey != "" { + c.UserKey = p.UserKey + } h := et.tm.PushoverService.Handler(c, ctx...) an.handlers = append(an.handlers, h) } diff --git a/pipeline/alert.go b/pipeline/alert.go index 5f46a1f5a..0149dc7bf 100644 --- a/pipeline/alert.go +++ b/pipeline/alert.go @@ -1383,19 +1383,21 @@ func (s *SensuHandler) Metadata(key string, value interface{}) *SensuHandler { // [pushover] // enabled = true // token = "9hiWoDOZ9IbmHsOTeST123ABciWTIqXQVFDo63h9" -// user_key = "Pushover" +// user-key = "Pushover" // // Example: // stream // |alert() // .pushover() // .sound('siren') -// .user_key('other user') +// .userKey('other user key or delivery group key') // .device('mydev') // .title('mytitle') // .URL('myurl') // .URLTitle('mytitle') // +// If the userKey() is omitted from above, the default userKey is used from the global pushover configuration +// // Send alerts to Pushover. // // tick:property diff --git a/services/pushover/service.go b/services/pushover/service.go index e9ad87dc8..02eb467f1 100644 --- a/services/pushover/service.go +++ b/services/pushover/service.go @@ -87,6 +87,7 @@ func (s *Service) Test(options interface{}) error { o.URL, o.URLTitle, o.Sound, + o.UserKey, o.Level, ) } @@ -95,8 +96,8 @@ func (s *Service) config() Config { return s.configValue.Load().(Config) } -func (s *Service) Alert(message, device, title, URL, URLTitle, sound string, level alert.Level) error { - url, post, err := s.preparePost(message, device, title, URL, URLTitle, sound, level) +func (s *Service) Alert(message, device, title, URL, URLTitle, sound string, userKey string, level alert.Level) error { + url, post, err := s.preparePost(message, device, title, URL, URLTitle, sound, userKey, level) if err != nil { return err } @@ -166,7 +167,6 @@ type postData struct { func (p *postData) Values() url.Values { v := url.Values{} - v.Set("token", p.Token) v.Set("user", p.UserKey) v.Set("message", p.Message) @@ -196,16 +196,20 @@ func (p *postData) Values() url.Values { } -func (s *Service) preparePost(message, device, title, URL, URLTitle, sound string, level alert.Level) (string, url.Values, error) { +func (s *Service) preparePost(message, device, title, URL, URLTitle, sound string, userKey string, level alert.Level) (string, url.Values, error) { c := s.config() if !c.Enabled { return "", nil, errors.New("service is not enabled") } + if userKey == "" { + userKey = c.UserKey + } + p := postData{ Token: c.Token, - UserKey: c.UserKey, + UserKey: userKey, Message: message, } @@ -237,6 +241,9 @@ type HandlerConfig struct { // The name of one of the sounds supported by the device clients to override // the user's default sound choice Sound string `mapstructure:"sound"` + + // The User Key or Delivery Group key + UserKey string `mapstructure:"user-key"` } type handler struct { @@ -261,6 +268,7 @@ func (h *handler) Handle(event alert.Event) { h.c.URL, h.c.URLTitle, h.c.Sound, + h.c.UserKey, event.State.Level, ); err != nil { h.diag.Error("failed to send event to Pushover", err)