Update github webhook plugin.
This commit is contained in:
parent
b09f7c89c2
commit
57a12fd52f
|
@ -2,7 +2,6 @@ package github_webhooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -18,7 +17,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GithubWebhooks struct {
|
type GithubWebhooks struct {
|
||||||
ServiceAddress string
|
Path string
|
||||||
// Lock for the struct
|
// Lock for the struct
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
// Events buffer to store events between Gather calls
|
// Events buffer to store events between Gather calls
|
||||||
|
@ -32,7 +31,7 @@ func NewGithubWebhooks() *GithubWebhooks {
|
||||||
func (gh *GithubWebhooks) SampleConfig() string {
|
func (gh *GithubWebhooks) SampleConfig() string {
|
||||||
return `
|
return `
|
||||||
## Address and port to host Webhook listener on
|
## 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GithubWebhooks) Listen() {
|
func (gh *GithubWebhooks) Register(r *mux.Router, _ telegraf.Accumulator) error {
|
||||||
r := mux.NewRouter()
|
r.HandleFunc(gh.Path, gh.eventHandler).Methods("POST")
|
||||||
r.HandleFunc("/", gh.eventHandler).Methods("POST")
|
log.Printf("Registering github_webhooks on %s\n", gh.Path)
|
||||||
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)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GithubWebhooks) Stop() {
|
|
||||||
log.Println("Stopping the ghWebhooks service")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles the / route
|
// Handles the / route
|
||||||
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
|
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
Loading…
Reference in New Issue