diff --git a/alert.go b/alert.go
index 7c7f0aba2..c0c96a31d 100644
--- a/alert.go
+++ b/alert.go
@@ -19,7 +19,6 @@ import (
alertservice "github.com/influxdata/kapacitor/services/alert"
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/discord"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/kafka"
"github.com/influxdata/kapacitor/services/mqtt"
@@ -317,24 +316,8 @@ func newAlertNode(et *ExecutingTask, n *pipeline.AlertNode, d NodeDiagnostic) (a
n.IsStateChangesOnly = true
}
- for _, hc := range n.HipChatHandlers {
- c := hipchat.HandlerConfig{
- Room: hc.Room,
- Token: hc.Token,
- }
- h := et.tm.HipChatService.Handler(c, ctx...)
- an.handlers = append(an.handlers, h)
- }
- if len(n.HipChatHandlers) == 0 && (et.tm.HipChatService != nil && et.tm.HipChatService.Global()) {
- c := hipchat.HandlerConfig{}
- h := et.tm.HipChatService.Handler(c, ctx...)
- an.handlers = append(an.handlers, h)
- }
- // If HipChat has been configured with state changes only set it.
- if et.tm.HipChatService != nil &&
- et.tm.HipChatService.Global() &&
- et.tm.HipChatService.StateChangesOnly() {
- n.IsStateChangesOnly = true
+ if len(n.HipChatHandlers) > 1 {
+ d.Error("HipChat support has been removed please update your scripts and config", errors.New("HipChat support removed"))
}
for _, k := range n.KafkaHandlers {
diff --git a/integrations/streamer_test.go b/integrations/streamer_test.go
index 9d3e9fcaf..abd353ad1 100644
--- a/integrations/streamer_test.go
+++ b/integrations/streamer_test.go
@@ -45,8 +45,6 @@ import (
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/bigpanda/bigpandatest"
"github.com/influxdata/kapacitor/services/diagnostic"
- "github.com/influxdata/kapacitor/services/hipchat"
- "github.com/influxdata/kapacitor/services/hipchat/hipchattest"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/httppost/httpposttest"
k8s "github.com/influxdata/kapacitor/services/k8s/client"
@@ -88,7 +86,7 @@ import (
"github.com/influxdata/kapacitor/services/zenoss/zenosstest"
"github.com/influxdata/kapacitor/udf"
"github.com/influxdata/kapacitor/udf/agent"
- udf_test "github.com/influxdata/kapacitor/udf/test"
+ "github.com/influxdata/kapacitor/udf/test"
"github.com/influxdata/wlog"
"github.com/k-sone/snmpgo"
)
@@ -9046,76 +9044,6 @@ stream
}
}
-func TestStream_AlertHipChat(t *testing.T) {
- ts := hipchattest.NewServer()
- defer ts.Close()
-
- var script = `
-stream
- |from()
- .measurement('cpu')
- .where(lambda: "host" == 'serverA')
- .groupBy('host')
- |window()
- .period(10s)
- .every(10s)
- |count('value')
- |alert()
- .id('kapacitor/{{ .Name }}/{{ index .Tags "host" }}')
- .info(lambda: "count" > 6.0)
- .warn(lambda: "count" > 7.0)
- .crit(lambda: "count" > 8.0)
- .hipChat()
- .room('1234567')
- .token('testtoken1234567')
- .hipChat()
- .room('Test Room')
- .token('testtokenTestRoom')
-`
- tmInit := func(tm *kapacitor.TaskMaster) {
-
- c := hipchat.NewConfig()
- c.Enabled = true
- c.URL = ts.URL
- c.Room = "1231234"
- c.Token = "testtoken1231234"
- sl := hipchat.NewService(c, diagService.NewHipChatHandler())
- tm.HipChatService = sl
- }
- testStreamerNoOutput(t, "TestStream_Alert", script, 13*time.Second, tmInit)
-
- exp := []interface{}{
- hipchattest.Request{
- URL: "/1234567/notification?auth_token=testtoken1234567",
- PostData: hipchattest.PostData{
- From: "kapacitor",
- Message: "kapacitor/cpu/serverA is CRITICAL",
- Color: "red",
- Notify: true,
- },
- },
- hipchattest.Request{
- URL: "/Test%20Room/notification?auth_token=testtokenTestRoom",
- PostData: hipchattest.PostData{
- From: "kapacitor",
- Message: "kapacitor/cpu/serverA is CRITICAL",
- Color: "red",
- Notify: true,
- },
- },
- }
-
- ts.Close()
- var got []interface{}
- for _, g := range ts.Requests() {
- got = append(got, g)
- }
-
- if err := compareListIgnoreOrder(got, exp, nil); err != nil {
- t.Error(err)
- }
-}
-
func TestStream_AlertAlerta(t *testing.T) {
ts := alertatest.NewServer()
defer ts.Close()
@@ -10727,9 +10655,9 @@ Value: {{ index .Fields "count" }}
"Mime-Version": []string{"1.0"},
"Content-Type": []string{"text/html; charset=UTF-8"},
"Content-Transfer-Encoding": []string{"quoted-printable"},
- "To": []string{"user1@example.com, user2@example.com"},
- "From": []string{"test@example.com"},
- "Subject": []string{"kapacitor.cpu.serverA is CRITICAL"},
+ "To": []string{"user1@example.com, user2@example.com"},
+ "From": []string{"test@example.com"},
+ "Subject": []string{"kapacitor.cpu.serverA is CRITICAL"},
},
Body: `
kapacitor.cpu.serverA is CRITICAL
@@ -10743,9 +10671,9 @@ Value: 10
"Mime-Version": []string{"1.0"},
"Content-Type": []string{"text/html; charset=UTF-8"},
"Content-Transfer-Encoding": []string{"quoted-printable"},
- "To": []string{"user1@example.com, user2@example.com"},
- "From": []string{"test@example.com"},
- "Subject": []string{"kapacitor.cpu.serverA is CRITICAL"},
+ "To": []string{"user1@example.com, user2@example.com"},
+ "From": []string{"test@example.com"},
+ "Subject": []string{"kapacitor.cpu.serverA is CRITICAL"},
},
Body: `
kapacitor.cpu.serverA is CRITICAL
diff --git a/pipeline/alert.go b/pipeline/alert.go
index fc51cd0c3..c15acad65 100644
--- a/pipeline/alert.go
+++ b/pipeline/alert.go
@@ -1101,58 +1101,7 @@ func (pd2 *PagerDuty2Handler) Link(url string, text ...string) *PagerDuty2Handle
return pd2
}
-// Send the alert to HipChat.
-// For step-by-step instructions on setting up Kapacitor with HipChat, see the [Event Handler Setup Guide](https://docs.influxdata.com//kapacitor/latest/guides/event-handler-setup/#hipchat-setup).
-// To allow Kapacitor to post to HipChat,
-// go to the URL https://www.hipchat.com/docs/apiv2 for
-// information on how to get your room id and tokens.
-//
-// Example:
-// [hipchat]
-// enabled = true
-// url = "https://orgname.hipchat.com/v2/room"
-// room = "4189212"
-// token = "9hiWoDOZ9IbmHsOTeST123ABciWTIqXQVFDo63h9"
-//
-// In order to not post a message every alert interval
-// use AlertNode.StateChangesOnly so that only events
-// where the alert changed state are posted to the room.
-//
-// Example:
-// stream
-// |alert()
-// .hipChat()
-//
-// Send alerts to HipChat room in the configuration file.
-//
-// Example:
-// stream
-// |alert()
-// .hipChat()
-// .room('Kapacitor')
-//
-// Send alerts to HipChat room 'Kapacitor'
-//
-//
-// If the 'hipchat' section in the configuration has the option: global = true
-// then all alerts are sent to HipChat without the need to explicitly state it
-// in the TICKscript.
-//
-// Example:
-// [hipchat]
-// enabled = true
-// url = "https://orgname.hipchat.com/v2/room"
-// room = "Test Room"
-// token = "9hiWoDOZ9IbmHsOTeST123ABciWTIqXQVFDo63h9"
-// global = true
-// state-changes-only = true
-//
-// Example:
-// stream
-// |alert()
-//
-// Send alert to HipChat using default room 'Test Room'.
-// tick:property
+// HipChat is removed but this has to be kept as is to not break current alert marshalling
func (n *AlertNodeData) HipChat() *HipChatHandler {
hipchat := &HipChatHandler{
AlertNodeData: n,
@@ -1161,6 +1110,7 @@ func (n *AlertNodeData) HipChat() *HipChatHandler {
return hipchat
}
+// HipchatHandler has been removed but this struct is kept around for compatibility purposes.
// tick:embedded:AlertNode.HipChat
type HipChatHandler struct {
*AlertNodeData `json:"-"`
diff --git a/pipeline/tick/alert_test.go b/pipeline/tick/alert_test.go
index 1802fde0f..efa4808fd 100644
--- a/pipeline/tick/alert_test.go
+++ b/pipeline/tick/alert_test.go
@@ -568,6 +568,7 @@ func TestAlertTelegram(t *testing.T) {
PipelineTickTestHelper(t, pipe, want)
}
+// TestAlertHipchat must be kept to ensure we don't break marshaling of current alerts
func TestAlertHipchat(t *testing.T) {
pipe, _, from := StreamFrom()
handler := from.Alert().HipChat()
diff --git a/server/config.go b/server/config.go
index 7a3bc574e..14ebbdfa6 100644
--- a/server/config.go
+++ b/server/config.go
@@ -30,7 +30,6 @@ import (
"github.com/influxdata/kapacitor/services/ec2"
"github.com/influxdata/kapacitor/services/file_discovery"
"github.com/influxdata/kapacitor/services/gce"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httpd"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/influxdb"
diff --git a/server/server.go b/server/server.go
index 8833fd300..797f4a0c9 100644
--- a/server/server.go
+++ b/server/server.go
@@ -36,7 +36,6 @@ import (
"github.com/influxdata/kapacitor/services/ec2"
"github.com/influxdata/kapacitor/services/file_discovery"
"github.com/influxdata/kapacitor/services/gce"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httpd"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/influxdb"
diff --git a/server/server_test.go b/server/server_test.go
index eaa7ee457..89b5ae904 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -26,7 +26,6 @@ import (
"time"
"github.com/davecgh/go-spew/spew"
- "github.com/dgrijalva/jwt-go"
"github.com/google/go-cmp/cmp"
iclient "github.com/influxdata/influxdb/client/v2"
"github.com/influxdata/influxdb/influxql"
@@ -44,7 +43,6 @@ import (
"github.com/influxdata/kapacitor/services/auth/meta"
"github.com/influxdata/kapacitor/services/bigpanda/bigpandatest"
"github.com/influxdata/kapacitor/services/discord/discordtest"
- "github.com/influxdata/kapacitor/services/hipchat/hipchattest"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/httppost/httpposttest"
"github.com/influxdata/kapacitor/services/k8s"
@@ -60,6 +58,7 @@ import (
"github.com/influxdata/kapacitor/services/pagerduty2"
"github.com/influxdata/kapacitor/services/pagerduty2/pagerduty2test"
"github.com/influxdata/kapacitor/services/pushover/pushovertest"
+ "github.com/influxdata/kapacitor/services/removed/hipchat/hipchattest"
"github.com/influxdata/kapacitor/services/sensu/sensutest"
"github.com/influxdata/kapacitor/services/servicenow"
"github.com/influxdata/kapacitor/services/servicenow/servicenowtest"
@@ -6763,12 +6762,12 @@ func TestServer_UpdateConfig(t *testing.T) {
Elements: []client.ConfigElement{{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/alerta/"},
Options: map[string]interface{}{
- "enabled": false,
- "environment": "",
- "origin": "",
- "token": false,
- "token-prefix": "",
- "url": "http://alerta.example.com",
+ "enabled": false,
+ "environment": "",
+ "origin": "",
+ "token": false,
+ "token-prefix": "",
+ "url": "http://alerta.example.com",
"insecure-skip-verify": false,
"timeout": "0s",
},
@@ -6780,12 +6779,12 @@ func TestServer_UpdateConfig(t *testing.T) {
expDefaultElement: client.ConfigElement{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/alerta/"},
Options: map[string]interface{}{
- "enabled": false,
- "environment": "",
- "origin": "",
- "token": false,
- "token-prefix": "",
- "url": "http://alerta.example.com",
+ "enabled": false,
+ "environment": "",
+ "origin": "",
+ "token": false,
+ "token-prefix": "",
+ "url": "http://alerta.example.com",
"insecure-skip-verify": false,
"timeout": "0s",
},
@@ -6807,12 +6806,12 @@ func TestServer_UpdateConfig(t *testing.T) {
Elements: []client.ConfigElement{{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/alerta/"},
Options: map[string]interface{}{
- "enabled": false,
- "environment": "",
- "origin": "kapacitor",
- "token": true,
- "token-prefix": "",
- "url": "http://alerta.example.com",
+ "enabled": false,
+ "environment": "",
+ "origin": "kapacitor",
+ "token": true,
+ "token-prefix": "",
+ "url": "http://alerta.example.com",
"insecure-skip-verify": false,
"timeout": "3h0m0s",
},
@@ -6824,12 +6823,12 @@ func TestServer_UpdateConfig(t *testing.T) {
expElement: client.ConfigElement{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/config/alerta/"},
Options: map[string]interface{}{
- "enabled": false,
- "environment": "",
- "origin": "kapacitor",
- "token": true,
- "token-prefix": "",
- "url": "http://alerta.example.com",
+ "enabled": false,
+ "environment": "",
+ "origin": "kapacitor",
+ "token": true,
+ "token-prefix": "",
+ "url": "http://alerta.example.com",
"insecure-skip-verify": false,
"timeout": "3h0m0s",
},
@@ -10786,9 +10785,9 @@ func TestServer_AlertHandlers(t *testing.T) {
"Mime-Version": []string{"1.0"},
"Content-Type": []string{"text/html; charset=UTF-8"},
"Content-Transfer-Encoding": []string{"quoted-printable"},
- "To": []string{"oncall@example.com, backup@example.com"},
- "From": []string{"test@example.com"},
- "Subject": []string{"message"},
+ "To": []string{"oncall@example.com, backup@example.com"},
+ "From": []string{"test@example.com"},
+ "Subject": []string{"message"},
},
Body: "details\n",
}}
diff --git a/services/alert/service.go b/services/alert/service.go
index 749dfbd8e..d2a7cf0dc 100644
--- a/services/alert/service.go
+++ b/services/alert/service.go
@@ -16,7 +16,6 @@ import (
"github.com/influxdata/kapacitor/services/alerta"
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/discord"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httpd"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/kafka"
diff --git a/services/diagnostic/handlers.go b/services/diagnostic/handlers.go
index 37c53bc47..1f8c55baa 100644
--- a/services/diagnostic/handlers.go
+++ b/services/diagnostic/handlers.go
@@ -20,7 +20,6 @@ import (
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/discord"
"github.com/influxdata/kapacitor/services/ec2"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httppost"
"github.com/influxdata/kapacitor/services/influxdb"
"github.com/influxdata/kapacitor/services/k8s"
diff --git a/services/hipchat/hipchattest/hipchattest.go b/services/hipchat/hipchattest/hipchattest.go
deleted file mode 100644
index 111e83011..000000000
--- a/services/hipchat/hipchattest/hipchattest.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package hipchattest
-
-import (
- "encoding/json"
- "net/http"
- "net/http/httptest"
- "sync"
-)
-
-type Server struct {
- mu sync.Mutex
- ts *httptest.Server
- URL string
- requests []Request
- closed bool
-}
-
-func NewServer() *Server {
- s := new(Server)
- ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- hr := Request{
- URL: r.URL.String(),
- }
- dec := json.NewDecoder(r.Body)
- dec.Decode(&hr.PostData)
- s.mu.Lock()
- s.requests = append(s.requests, hr)
- s.mu.Unlock()
- }))
- s.ts = ts
- s.URL = ts.URL
- return s
-}
-
-func (s *Server) Requests() []Request {
- s.mu.Lock()
- defer s.mu.Unlock()
- return s.requests
-}
-func (s *Server) Close() {
- if s.closed {
- return
- }
- s.closed = true
- s.ts.Close()
-}
-
-type Request struct {
- URL string
- PostData PostData
-}
-
-type PostData struct {
- From string `json:"from"`
- Message string `json:"message"`
- Color string `json:"color"`
- Notify bool `json:"notify"`
-}
diff --git a/services/hipchat/service.go b/services/hipchat/service.go
deleted file mode 100644
index aa7d925a2..000000000
--- a/services/hipchat/service.go
+++ /dev/null
@@ -1,204 +0,0 @@
-package hipchat
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "io"
- "io/ioutil"
- "net/http"
- "net/url"
- "path"
- "sync/atomic"
-
- "github.com/influxdata/kapacitor/alert"
- "github.com/influxdata/kapacitor/keyvalue"
-)
-
-type Diagnostic interface {
- WithContext(ctx ...keyvalue.T) Diagnostic
- Error(msg string, err error)
-}
-
-type Service struct {
- configValue atomic.Value
- diag Diagnostic
-}
-
-func NewService(c Config, d Diagnostic) *Service {
- s := &Service{
- diag: d,
- }
- s.configValue.Store(c)
- return s
-}
-
-func (s *Service) Open() error {
- return nil
-}
-
-func (s *Service) Close() error {
- return nil
-}
-
-func (s *Service) config() Config {
- return s.configValue.Load().(Config)
-}
-
-func (s *Service) Update(newConfig []interface{}) error {
- if l := len(newConfig); l != 1 {
- return fmt.Errorf("expected only one new config object, got %d", l)
- }
- if c, ok := newConfig[0].(Config); !ok {
- return fmt.Errorf("expected config object to be of type %T, got %T", c, newConfig[0])
- } else {
- s.configValue.Store(c)
- }
- return nil
-}
-
-func (s *Service) Global() bool {
- c := s.config()
- return c.Global
-}
-
-func (s *Service) StateChangesOnly() bool {
- c := s.config()
- return c.StateChangesOnly
-}
-
-type testOptions struct {
- Room string `json:"room"`
- Message string `json:"message"`
- Level alert.Level `json:"level"`
-}
-
-func (s *Service) TestOptions() interface{} {
- c := s.config()
- return &testOptions{
- Room: c.Room,
- Message: "test hipchat message",
- Level: alert.Critical,
- }
-}
-
-func (s *Service) Test(options interface{}) error {
- o, ok := options.(*testOptions)
- if !ok {
- return fmt.Errorf("unexpected options type %T", options)
- }
- c := s.config()
- return s.Alert(o.Room, c.Token, o.Message, o.Level)
-}
-
-func (s *Service) Alert(room, token, message string, level alert.Level) error {
- url, post, err := s.preparePost(room, token, message, level)
- if err != nil {
- return err
- }
-
- resp, err := http.Post(url, "application/json", post)
- if err != nil {
- return err
- }
- defer resp.Body.Close()
- if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return err
- }
- type response struct {
- Error string `json:"error"`
- }
- 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)
- return errors.New(r.Error)
- }
- return nil
-}
-
-func (s *Service) preparePost(room, token, message string, level alert.Level) (string, io.Reader, error) {
- c := s.config()
-
- if !c.Enabled {
- return "", nil, errors.New("service is not enabled")
- }
- //Generate HipChat API URL including room and authentication token
- if room == "" {
- room = c.Room
- }
- if token == "" {
- token = c.Token
- }
-
- u, err := url.Parse(c.URL)
- if err != nil {
- return "", nil, err
- }
- u.Path = path.Join(u.Path, room, "notification")
- v := url.Values{}
- v.Set("auth_token", token)
- u.RawQuery = v.Encode()
-
- var color string
- switch level {
- case alert.Warning:
- color = "yellow"
- case alert.Critical:
- color = "red"
- default:
- color = "green"
- }
-
- postData := make(map[string]interface{})
- postData["from"] = "kapacitor"
- postData["color"] = color
- postData["message"] = message
- postData["notify"] = true
-
- var post bytes.Buffer
- enc := json.NewEncoder(&post)
- err = enc.Encode(postData)
- if err != nil {
- return "", nil, err
- }
- return u.String(), &post, nil
-}
-
-type HandlerConfig struct {
- // HipChat room in which to post messages.
- // If empty uses the channel from the configuration.
- Room string `mapstructure:"room"`
-
- // HipChat authentication token.
- // If empty uses the token from the configuration.
- Token string `mapstructure:"token"`
-}
-
-type handler struct {
- s *Service
- c HandlerConfig
- diag Diagnostic
-}
-
-func (s *Service) Handler(c HandlerConfig, ctx ...keyvalue.T) alert.Handler {
- return &handler{
- s: s,
- c: c,
- diag: s.diag.WithContext(ctx...),
- }
-}
-
-func (h *handler) Handle(event alert.Event) {
- if err := h.s.Alert(
- h.c.Room,
- h.c.Token,
- event.State.Message,
- event.State.Level,
- ); err != nil {
- h.diag.Error("failed to send event to Alerta", err)
- }
-}
diff --git a/services/hipchat/config.go b/services/removed/hipchat/config.go
similarity index 79%
rename from services/hipchat/config.go
rename to services/removed/hipchat/config.go
index d2ba56d61..eafd52dd9 100644
--- a/services/hipchat/config.go
+++ b/services/removed/hipchat/config.go
@@ -1,10 +1,8 @@
package hipchat
-import (
- "net/url"
+import "errors"
- "github.com/pkg/errors"
-)
+var configerr = errors.New("HipChat has been removed, please update your configs")
type Config struct {
// Whether HipChat integration is enabled.
@@ -28,11 +26,5 @@ func NewConfig() Config {
}
func (c Config) Validate() error {
- if c.Enabled && c.URL == "" {
- return errors.New("must specify url")
- }
- if _, err := url.Parse(c.URL); err != nil {
- return errors.Wrapf(err, "invalid url %q", c.URL)
- }
- return nil
+ return configerr
}
diff --git a/services/removed/hipchat/hipchattest/hipchattest.go b/services/removed/hipchat/hipchattest/hipchattest.go
new file mode 100644
index 000000000..53229a2cc
--- /dev/null
+++ b/services/removed/hipchat/hipchattest/hipchattest.go
@@ -0,0 +1 @@
+package hipchattest
diff --git a/services/removed/hipchat/service.go b/services/removed/hipchat/service.go
new file mode 100644
index 000000000..58c03fbf2
--- /dev/null
+++ b/services/removed/hipchat/service.go
@@ -0,0 +1,95 @@
+package hipchat
+
+import (
+ "sync/atomic"
+
+ "github.com/influxdata/kapacitor/alert"
+ "github.com/influxdata/kapacitor/keyvalue"
+)
+
+type Diagnostic interface {
+ WithContext(ctx ...keyvalue.T) Diagnostic
+ Error(msg string, err error)
+}
+
+type Service struct {
+ configValue atomic.Value
+ diag Diagnostic
+}
+
+func NewService(c Config, d Diagnostic) *Service {
+ s := &Service{
+ diag: d,
+ }
+ s.configValue.Store(c)
+ return s
+}
+
+func (s *Service) Open() error {
+ return nil
+}
+
+func (s *Service) Close() error {
+ return nil
+}
+
+func (s *Service) config() Config {
+ return s.configValue.Load().(Config)
+}
+
+func (s *Service) Update(newConfig []interface{}) error {
+ s.diag.Error("HipChat support has been removed", configerr)
+ return nil
+}
+
+func (s *Service) Global() bool {
+ c := s.config()
+ return c.Global
+}
+
+func (s *Service) StateChangesOnly() bool {
+ c := s.config()
+ return c.StateChangesOnly
+}
+
+type testOptions struct {
+ Room string `json:"room"`
+ Message string `json:"message"`
+ Level alert.Level `json:"level"`
+}
+
+func (s *Service) TestOptions() interface{} {
+ c := s.config()
+ return &testOptions{
+ Room: c.Room,
+ Message: "test removed message",
+ Level: alert.Critical,
+ }
+}
+
+func (s *Service) Test(options interface{}) error {
+ s.diag.Error("HipChat support has been removed", configerr)
+ return configerr
+}
+
+func (s *Service) Alert(room, token, message string, level alert.Level) error {
+ s.diag.Error("HipChat support has been removed", configerr)
+ return nil
+}
+
+type HandlerConfig struct {
+}
+
+type handler struct {
+ diag Diagnostic
+}
+
+func (s *Service) Handler(c HandlerConfig, ctx ...keyvalue.T) alert.Handler {
+ return &handler{
+ diag: s.diag.WithContext(ctx...),
+ }
+}
+
+func (h *handler) Handle(event alert.Event) {
+ h.diag.Error("HipChat support has been removed")
+}
diff --git a/services/sideload/service.go b/services/sideload/service.go
index a1b1a5661..de521da9a 100644
--- a/services/sideload/service.go
+++ b/services/sideload/service.go
@@ -203,7 +203,9 @@ func (s *fileSource) Close() {
}
func (s *fileSource) UpdateCache() error {
+ s.mu.Lock()
s.cache = make(map[string]map[string]interface{})
+ s.mu.Unlock()
err := filepath.Walk(s.dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@@ -225,7 +227,9 @@ func (s *fileSource) UpdateCache() error {
if len(rel) == 0 || rel[0] == '.' {
return errors.New("invalid relative path")
}
+ s.mu.Lock()
s.cache[rel] = values
+ s.mu.Unlock()
return nil
})
return errors.Wrapf(err, "failed to update sideload cache for source file %q", s.dir)
@@ -258,7 +262,10 @@ type httpSource struct {
}
func (s *httpSource) UpdateCache() error {
- s.cache = make(map[string]map[string]interface{})
+ s.fileSource.mu.Lock()
+ s.fileSource.cache = make(map[string]map[string]interface{})
+ s.fileSource.mu.Unlock()
+
req, err := http.NewRequest("GET", s.dir, nil)
if err != nil {
return errors.Wrapf(err, "failed to generate request to update sideload cache for source %q", s.dir)
@@ -281,7 +288,9 @@ func (s *httpSource) UpdateCache() error {
return errors.Wrapf(err, "failed to load body to update sideload cache for source %q", s.dir)
}
for k, v := range values {
- s.cache[k] = v
+ s.fileSource.mu.Lock()
+ s.fileSource.cache[k] = v
+ s.fileSource.mu.Unlock()
}
return nil
}
diff --git a/services/sideload/service_test.go b/services/sideload/service_test.go
index 250338e5e..470765993 100644
--- a/services/sideload/service_test.go
+++ b/services/sideload/service_test.go
@@ -78,10 +78,14 @@ func TestService_Source_Lookup(t *testing.T) {
for i, tc := range testCases {
tc := tc
t.Run(strconv.Itoa(i), func(t *testing.T) {
+ t.Parallel()
got := src.Lookup(tc.order, tc.key)
if !cmp.Equal(got, tc.want) {
t.Errorf("unexpected values: -want/+got:\n%s", cmp.Diff(tc.want, got))
}
+ if err := e.Update(conf); err != nil {
+ t.Fatal(err)
+ }
})
}
}
diff --git a/task_master.go b/task_master.go
index 694bda9f1..8710f76d0 100644
--- a/task_master.go
+++ b/task_master.go
@@ -22,7 +22,6 @@ import (
"github.com/influxdata/kapacitor/services/bigpanda"
"github.com/influxdata/kapacitor/services/discord"
ec2 "github.com/influxdata/kapacitor/services/ec2/client"
- "github.com/influxdata/kapacitor/services/hipchat"
"github.com/influxdata/kapacitor/services/httpd"
"github.com/influxdata/kapacitor/services/httppost"
k8s "github.com/influxdata/kapacitor/services/k8s/client"
@@ -33,6 +32,7 @@ import (
"github.com/influxdata/kapacitor/services/pagerduty"
"github.com/influxdata/kapacitor/services/pagerduty2"
"github.com/influxdata/kapacitor/services/pushover"
+ "github.com/influxdata/kapacitor/services/removed/hipchat"
"github.com/influxdata/kapacitor/services/sensu"
"github.com/influxdata/kapacitor/services/servicenow"
"github.com/influxdata/kapacitor/services/sideload"