Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #536 from palourde/per-client-subscriptions
Browse files Browse the repository at this point in the history
Do not include per-client subscriptions in the subscriptions filter
  • Loading branch information
palourde authored Aug 4, 2016
2 parents 9f6e856 + f900224 commit caafa49
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions uchiwa/daemon/subscriptions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package daemon

import (
"strings"

"github.com/mitchellh/mapstructure"
"github.com/sensu/uchiwa/uchiwa/helpers"
"github.com/sensu/uchiwa/uchiwa/logger"
Expand All @@ -18,6 +20,13 @@ func (d *Daemon) BuildSubscriptions() {
}

for _, subscription := range generic.Subscriptions {
// Do not add per-client subscriptions to the slice so we don't pollute
// the subscriptions filter in the frontend.
// See https://github.com/sensu/sensu-settings/pull/40.
if strings.HasPrefix(strings.ToLower(subscription), "client:") {
continue
}

if !helpers.IsStringInArray(subscription, d.Data.Subscriptions) {
d.Data.Subscriptions = append(d.Data.Subscriptions, subscription)
}
Expand Down
32 changes: 32 additions & 0 deletions uchiwa/daemon/subscriptions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package daemon

import (
"testing"

"github.com/sensu/uchiwa/uchiwa/structs"
"github.com/stretchr/testify/assert"
)

func TestBuildSubscriptions(t *testing.T) {
// Test basic subscriptions
data := structs.Data{
Clients: []interface{}{
map[string]interface{}{"subscriptions": []string{"foo", "bar"}},
map[string]interface{}{"subscriptions": []string{"foo", "qux"}},
},
}
d := Daemon{Data: &data}
d.BuildSubscriptions()
assert.Equal(t, 3, len(d.Data.Subscriptions))

// Test per-client subscriptions
data = structs.Data{
Clients: []interface{}{
map[string]interface{}{"subscriptions": []string{"foo", "client:foobar"}},
map[string]interface{}{"subscriptions": []string{"CLIENT:BAZ", "qux"}},
},
}
d = Daemon{Data: &data}
d.BuildSubscriptions()
assert.Equal(t, 2, len(d.Data.Subscriptions))
}

0 comments on commit caafa49

Please sign in to comment.