Skip to content

Commit

Permalink
fix: external BigPanda testability (#2504)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Závora <[email protected]>
  • Loading branch information
rhajek and sranka authored May 7, 2021
1 parent f6f7229 commit 1f2c956
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 19 deletions.
103 changes: 99 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7854,6 +7854,91 @@ func TestServer_UpdateConfig(t *testing.T) {
},
},
},
{
section: "bigpanda",
setDefaults: func(c *server.Config) {
c.BigPanda.URL = "https://api.bigpanda.io/data/v2/alerts"
},
expDefaultSection: client.ConfigSection{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda"},
Elements: []client.ConfigElement{{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda/"},
Options: map[string]interface{}{
"enabled": false,
"global": false,
"state-changes-only": false,
"url": "https://api.bigpanda.io/data/v2/alerts",
"insecure-skip-verify": false,
"token": false,
"app-key": "",
},
Redacted: []string{
"token",
},
}},
},
expDefaultElement: client.ConfigElement{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda/"},
Options: map[string]interface{}{
"enabled": false,
"global": false,
"state-changes-only": false,
"url": "https://api.bigpanda.io/data/v2/alerts",
"insecure-skip-verify": false,
"token": false,
"app-key": "",
},
Redacted: []string{
"token",
},
},
updates: []updateAction{
{
updateAction: client.ConfigUpdateAction{
Set: map[string]interface{}{
"enabled": true,
"url": "https://dev123456.bigpanda.io/data/v2/alerts",
"app-key": "appkey-123",
"token": "token-123",
},
},
expSection: client.ConfigSection{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda"},
Elements: []client.ConfigElement{{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda/"},
Options: map[string]interface{}{
"enabled": true,
"global": false,
"state-changes-only": false,
"url": "https://dev123456.bigpanda.io/data/v2/alerts",
"token": true,
"app-key": "appkey-123",
"insecure-skip-verify": false,
},
Redacted: []string{
"token",
},
}},
},
expElement: client.ConfigElement{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/bigpanda/"},
Options: map[string]interface{}{
"enabled": true,
"global": false,
"state-changes-only": false,
"url": "https://dev123456.bigpanda.io/data/v2/alerts",
"app-key": "appkey-123",
"token": true,
"insecure-skip-verify": false,
},
Redacted: []string{
"token",
},
},
},
},
},

{
section: "slack",
setDefaults: func(c *server.Config) {
Expand Down Expand Up @@ -8998,10 +9083,12 @@ func TestServer_ListServiceTests(t *testing.T) {
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/service-tests/bigpanda"},
Name: "bigpanda",
Options: client.ServiceTestOptions{
"app_key": "my-app-key-123456",
"level": "CRITICAL",
"message": "test bigpanda message",
"timestamp": "1970-01-01T00:00:01Z",
"app_key": "my-app-key-123456",
"level": "CRITICAL",
"message": "test bigpanda message",
"timestamp": "1970-01-01T00:00:01Z",
"primary_property": "",
"secondary_property": "",
"event_data": map[string]interface{}{
"Fields": map[string]interface{}{},
"Result": map[string]interface{}{
Expand Down Expand Up @@ -9524,6 +9611,14 @@ func TestServer_DoServiceTest(t *testing.T) {
Message: "service is not enabled",
},
},
{
service: "bigpanda",
options: client.ServiceTestOptions{},
exp: client.ServiceTestResult{
Success: false,
Message: "service is not enabled",
},
},
{
service: "hipchat",
options: client.ServiceTestOptions{},
Expand Down
20 changes: 11 additions & 9 deletions services/bigpanda/bigpandatest/bigpandatest.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ type Request struct {

// PostData is the default struct to send an element through to BigPanda
type PostData struct {
AppKey string `json:"app_key"`
Status string `json:"status"`
Host string `json:"host"`
Timestamp int64 `json:"timestamp"`
Check string `json:"check"`
Description string `json:"description"`
Cluster string `json:"cluster"`
Task string `json:"task"`
Details string `json:"details"`
AppKey string `json:"app_key"`
Status string `json:"status"`
Host string `json:"host"`
Timestamp int64 `json:"timestamp"`
Check string `json:"check"`
Description string `json:"description"`
Cluster string `json:"cluster"`
Task string `json:"task"`
Details string `json:"details"`
PrimaryProperty string `json:"primary_property"`
SecondaryProperty string `json:"secondary_property"`
}
16 changes: 10 additions & 6 deletions services/bigpanda/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ func (s *Service) StateChangesOnly() bool {
}

type testOptions struct {
AppKey string `json:"app_key"`
Message string `json:"message"`
Level alert.Level `json:"level"`
Data alert.EventData `json:"event_data"`
Timestamp time.Time `json:"timestamp"`
AppKey string `json:"app_key"`
Message string `json:"message"`
Level alert.Level `json:"level"`
Data alert.EventData `json:"event_data"`
Timestamp time.Time `json:"timestamp"`
PrimaryProperty string `json:"primary_property"`
SecondaryProperty string `json:"secondary_property"`
}

func (s *Service) TestOptions() interface{} {
Expand All @@ -114,7 +116,9 @@ func (s *Service) Test(options interface{}) error {
return fmt.Errorf("unexpected options type %T", options)
}
hc := &HandlerConfig{
AppKey: o.AppKey,
AppKey: o.AppKey,
PrimaryProperty: o.PrimaryProperty,
SecondaryProperty: o.SecondaryProperty,
}
return s.Alert("", o.Message, "", o.Level, o.Timestamp, o.Data, hc)
}
Expand Down

0 comments on commit 1f2c956

Please sign in to comment.