Skip to content

Commit

Permalink
better error messages for alert handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Feb 17, 2016
1 parent 407644c commit bee28ae
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
### Bugfixes
- [#199](https://github.com/influxdata/kapacitor/issues/199): BREAKING: Various fixes for the Alerta integration.
The `event` property has been removed from the Alerta node and is now set as the value of the alert ID.
- [#232](https://github.com/influxdata/kapacitor/issues/232): Better error message for alert integrations. Better error message for VictorOps 404 response.

## v0.10.1 [2013-02-08]
## v0.10.1 [2016-02-08]

### Release Notes

Expand Down
3 changes: 2 additions & 1 deletion services/alerta/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (s *Service) Alert(token, resource, event, environment, severity, status, g
type response struct {
Message string `json:"message"`
}
r := &response{Message: "failed to understand Alerta response: " + string(body)}
r := &response{Message: fmt.Sprintf("failed to understand Alerta response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
2 changes: 1 addition & 1 deletion services/deadman/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
// Default deadman's switch threshold
DefaultThreshold = float64(0)
// Default deadman's switch id
DefaultId = "node 'NODE_NAME' in task '{{ .TaskName }}'"
DefaultId = "{{ .Group }}:NODE_NAME for task '{{ .TaskName }}'"
// Default deadman's switch message
DefaultMessage = "{{ .ID }} is {{ if eq .Level \"OK\" }}alive{{ else }}dead{{ end }}: {{ index .Fields \"emitted\" | printf \"%0.3f\" }} points/INTERVAL."
)
Expand Down
3 changes: 2 additions & 1 deletion services/hipchat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (s *Service) Alert(room, token, message string, level kapacitor.AlertLevel)
type response struct {
Error string `json:"error"`
}
r := &response{Error: "failed to understand HipChat response: " + string(body)}
r := &response{Error: fmt.Sprintf("failed to understand HipChat response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
3 changes: 2 additions & 1 deletion services/opsgenie/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *Service) Alert(teams []string, recipients []string, messageType, messag
type response struct {
Message string `json:"message"`
}
r := &response{Message: "failed to understand OpsGenie response: " + string(body)}
r := &response{Message: fmt.Sprintf("failed to understand OpsGenie response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
3 changes: 2 additions & 1 deletion services/pagerduty/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (s *Service) Alert(incidentKey, desc string, details interface{}) error {
type response struct {
Message string `json:"message"`
}
r := &response{Message: "failed to understand PagerDuty response: " + string(body)}
r := &response{Message: fmt.Sprintf("failed to understand PagerDuty response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
3 changes: 2 additions & 1 deletion services/sensu/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -74,7 +75,7 @@ func (s *Service) Alert(name, output string, level kapacitor.AlertLevel) error {
type response struct {
Error string `json:"error"`
}
r := &response{Error: "failed to understand Sensu response: " + string(body)}
r := &response{Error: fmt.Sprintf("failed to understand Sensu response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
3 changes: 2 additions & 1 deletion services/slack/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (s *Service) Alert(channel, message string, level kapacitor.AlertLevel) err
type response struct {
Error string `json:"error"`
}
r := &response{Error: "failed to understand Slack response: " + string(body)}
r := &response{Error: fmt.Sprintf("failed to understand Slack response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down
8 changes: 7 additions & 1 deletion services/talk/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
)
Expand Down Expand Up @@ -49,10 +51,14 @@ func (s *Service) Alert(title, text string) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
type response struct {
Error string `json:"error"`
}
r := &response{Error: "failed to understand Talk response"}
r := &response{Error: fmt.Sprintf("failed to understand Talk response. code: %d content: %s", resp.StatusCode, string(body))}
dec := json.NewDecoder(resp.Body)
dec.Decode(r)
return errors.New(r.Error)
Expand Down
6 changes: 5 additions & 1 deletion services/victorops/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -73,14 +74,17 @@ func (s *Service) Alert(routingKey, messageType, message, entityID string, t tim
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusNotFound {
return errors.New("URL or API key not found: 404")
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
type response struct {
Message string `json:"message"`
}
r := &response{Message: "failed to understand VictorOps response: " + string(body)}
r := &response{Message: fmt.Sprintf("failed to understand VictorOps response. code: %d content: %s", resp.StatusCode, string(body))}
b := bytes.NewReader(body)
dec := json.NewDecoder(b)
dec.Decode(r)
Expand Down

0 comments on commit bee28ae

Please sign in to comment.