From b09f7c89c2dc066b3b3de549a79ef93a9d699a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Wed, 25 May 2016 19:38:44 +0200 Subject: [PATCH] Update rollbar webhook plugin. --- .../rollbar_webhooks/rollbar_webhooks.go | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/plugins/inputs/rollbar_webhooks/rollbar_webhooks.go b/plugins/inputs/rollbar_webhooks/rollbar_webhooks.go index 5e7dc8847..7e6d36fbe 100644 --- a/plugins/inputs/rollbar_webhooks/rollbar_webhooks.go +++ b/plugins/inputs/rollbar_webhooks/rollbar_webhooks.go @@ -3,7 +3,6 @@ package rollbar_webhooks import ( "encoding/json" "errors" - "fmt" "io/ioutil" "log" "net/http" @@ -20,7 +19,7 @@ func init() { } type RollbarWebhooks struct { - ServiceAddress string + Path string // Lock for the struct sync.Mutex // Events buffer to store events between Gather calls @@ -33,8 +32,8 @@ func NewRollbarWebhooks() *RollbarWebhooks { func (rb *RollbarWebhooks) SampleConfig() string { return ` - ## Address and port to host Webhook listener on - service_address = ":1619" + ## Path of the global server + path = "/rollbar" ` } @@ -52,25 +51,12 @@ func (rb *RollbarWebhooks) Gather(acc telegraf.Accumulator) error { return nil } -func (rb *RollbarWebhooks) Listen() { - r := mux.NewRouter() - r.HandleFunc("/", rb.eventHandler).Methods("POST") - err := http.ListenAndServe(fmt.Sprintf("%s", rb.ServiceAddress), r) - if err != nil { - log.Printf("Error starting server: %v", err) - } -} - -func (rb *RollbarWebhooks) Start(_ telegraf.Accumulator) error { - go rb.Listen() - log.Printf("Started the rollbar_webhooks service on %s\n", rb.ServiceAddress) +func (rb *RollbarWebhooks) Register(r *mux.Router, _ telegraf.Accumulator) error { + r.HandleFunc(rb.Path, rb.eventHandler).Methods("POST") + log.Printf("Register the rollbar_webhooks router on %s\n", rb.Path) return nil } -func (rb *RollbarWebhooks) Stop() { - log.Println("Stopping the rbWebhooks service") -} - func (rb *RollbarWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() data, err := ioutil.ReadAll(r.Body)