Skip to content

Commit

Permalink
Merge pull request influxdata#2360 from exabrial/master
Browse files Browse the repository at this point in the history
Fix influxdata#2358 - Kapacitor ignoring the pushover().userKey() TICKScript operation [All Checks/Tests pass]
  • Loading branch information
docmerlin authored Jul 14, 2020
2 parents dfb1df4 + 0420dfc commit d56aafb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions pipeline/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions services/pushover/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *Service) Test(options interface{}) error {
o.URL,
o.URLTitle,
o.Sound,
o.UserKey,
o.Level,
)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit d56aafb

Please sign in to comment.