From 57a12fd52fd33ab1f0d64a4c432ad22700b854ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Wed, 25 May 2016 19:42:14 +0200 Subject: [PATCH] Update github webhook plugin. --- .../inputs/github_webhooks/github_webhooks.go | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/plugins/inputs/github_webhooks/github_webhooks.go b/plugins/inputs/github_webhooks/github_webhooks.go index 9e8fc22cd..2c5241b29 100644 --- a/plugins/inputs/github_webhooks/github_webhooks.go +++ b/plugins/inputs/github_webhooks/github_webhooks.go @@ -2,7 +2,6 @@ package github_webhooks import ( "encoding/json" - "fmt" "io/ioutil" "log" "net/http" @@ -18,7 +17,7 @@ func init() { } type GithubWebhooks struct { - ServiceAddress string + Path string // Lock for the struct sync.Mutex // Events buffer to store events between Gather calls @@ -32,7 +31,7 @@ func NewGithubWebhooks() *GithubWebhooks { func (gh *GithubWebhooks) SampleConfig() string { return ` ## Address and port to host Webhook listener on - service_address = ":1618" + path = "/github" ` } @@ -52,25 +51,12 @@ func (gh *GithubWebhooks) Gather(acc telegraf.Accumulator) error { return nil } -func (gh *GithubWebhooks) Listen() { - r := mux.NewRouter() - r.HandleFunc("/", gh.eventHandler).Methods("POST") - err := http.ListenAndServe(fmt.Sprintf("%s", gh.ServiceAddress), r) - if err != nil { - log.Printf("Error starting server: %v", err) - } -} - -func (gh *GithubWebhooks) Start(_ telegraf.Accumulator) error { - go gh.Listen() - log.Printf("Started the github_webhooks service on %s\n", gh.ServiceAddress) +func (gh *GithubWebhooks) Register(r *mux.Router, _ telegraf.Accumulator) error { + r.HandleFunc(gh.Path, gh.eventHandler).Methods("POST") + log.Printf("Registering github_webhooks on %s\n", gh.Path) return nil } -func (gh *GithubWebhooks) Stop() { - log.Println("Stopping the ghWebhooks service") -} - // Handles the / route func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close()