Skip to content

Commit

Permalink
Merge branch 'v1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Aug 8, 2017
2 parents afbe3c5 + 2b6a049 commit 3b873a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
- [#1500](https://github.com/influxdata/kapacitor/pull/1500): Fix bugs with stopping running UDF agent.
- [#1470](https://github.com/influxdata/kapacitor/pull/1470): Fix error messages for missing fields which are arguments to functions are not clear

## v1.3.2 [2017-08-08]

### Bugfixes
- [#1512](https://github.com/influxdata/kapacitor/pull/1512): Use details field from alert node in PagerDuty.

## v1.3.1 [2017-06-02]

### Bugfixes
Expand Down
6 changes: 4 additions & 2 deletions integrations/streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7842,6 +7842,8 @@ func TestStream_AlertPagerDuty(t *testing.T) {
ts := pagerdutytest.NewServer()
defer ts.Close()

defaultDetails := "{"Name":"cpu","TaskName":"TestStream_Alert","Group":"host=serverA","Tags":{"host":"serverA"},"ServerInfo":{"Hostname":"","ClusterID":"","ServerID":""},"ID":"kapacitor/cpu/serverA","Fields":{"count":10},"Level":"CRITICAL","Time":"1971-01-01T00:00:10Z","Message":"CRITICAL alert for kapacitor/cpu/serverA"}\n"

var script = `
stream
|from()
Expand Down Expand Up @@ -7886,7 +7888,7 @@ stream
Description: "CRITICAL alert for kapacitor/cpu/serverA",
Client: "kapacitor",
ClientURL: kapacitorURL,
Details: `{"series":[{"name":"cpu","tags":{"host":"serverA"},"columns":["time","count"],"values":[["1971-01-01T00:00:10Z",10]]}]}`,
Details: defaultDetails,
},
},
pagerdutytest.Request{
Expand All @@ -7897,7 +7899,7 @@ stream
Description: "CRITICAL alert for kapacitor/cpu/serverA",
Client: "kapacitor",
ClientURL: kapacitorURL,
Details: `{"series":[{"name":"cpu","tags":{"host":"serverA"},"columns":["time","count"],"values":[["1971-01-01T00:00:10Z",10]]}]}`,
Details: defaultDetails,
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7470,6 +7470,7 @@ func TestServer_ListServiceTests(t *testing.T) {
"incident-key": "testIncidentKey",
"description": "test pagerduty message",
"level": "CRITICAL",
"details": "",
},
},
{
Expand Down Expand Up @@ -8368,7 +8369,7 @@ func TestServer_AlertHandlers(t *testing.T) {
Description: "message",
Client: "kapacitor",
ClientURL: kapacitorURL,
Details: resultJSON,
Details: "details",
},
}}
if !reflect.DeepEqual(exp, got) {
Expand Down
18 changes: 7 additions & 11 deletions services/pagerduty/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"sync/atomic"

"github.com/influxdata/kapacitor/alert"
"github.com/influxdata/kapacitor/models"
)

type Service struct {
Expand Down Expand Up @@ -64,6 +63,7 @@ func (s *Service) Global() bool {
type testOptions struct {
IncidentKey string `json:"incident-key"`
Description string `json:"description"`
Details string `json:"details"`
Level alert.Level `json:"level"`
}

Expand All @@ -86,11 +86,11 @@ func (s *Service) Test(options interface{}) error {
o.IncidentKey,
o.Description,
o.Level,
models.Result{},
o.Details,
)
}

func (s *Service) Alert(serviceKey, incidentKey, desc string, level alert.Level, details models.Result) error {
func (s *Service) Alert(serviceKey, incidentKey, desc string, level alert.Level, details string) error {
url, post, err := s.preparePost(serviceKey, incidentKey, desc, level, details)
if err != nil {
return err
Expand Down Expand Up @@ -118,7 +118,7 @@ func (s *Service) Alert(serviceKey, incidentKey, desc string, level alert.Level,
return nil
}

func (s *Service) preparePost(serviceKey, incidentKey, desc string, level alert.Level, details models.Result) (string, io.Reader, error) {
func (s *Service) preparePost(serviceKey, incidentKey, desc string, level alert.Level, details string) (string, io.Reader, error) {

c := s.config()
if !c.Enabled {
Expand Down Expand Up @@ -147,16 +147,12 @@ func (s *Service) preparePost(serviceKey, incidentKey, desc string, level alert.
pData["client"] = "kapacitor"
pData["client_url"] = s.HTTPDService.URL()

b, err := json.Marshal(details)
if err != nil {
return "", nil, err
}
pData["details"] = string(b)
pData["details"] = details

// Post data to PagerDuty
var post bytes.Buffer
enc := json.NewEncoder(&post)
err = enc.Encode(pData)
err := enc.Encode(pData)
if err != nil {
return "", nil, err
}
Expand Down Expand Up @@ -190,7 +186,7 @@ func (h *handler) Handle(event alert.Event) {
event.State.ID,
event.State.Message,
event.State.Level,
event.Data.Result,
event.State.Details,
); err != nil {
h.logger.Println("E! failed to send event to PagerDuty", err)
}
Expand Down

0 comments on commit 3b873a2

Please sign in to comment.