Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh webhooks #573

Merged
merged 11 commits into from
Jan 26, 2016
Prev Previous commit
Next Next commit
Change start implementation
jackzampolin committed Jan 20, 2016
commit 8653bae6acceada3e8ccbaa6b32828dc144d63f2
26 changes: 14 additions & 12 deletions plugins/inputs/ghwebhooks/ghwebhooks.go
Original file line number Diff line number Diff line change
@@ -70,19 +70,19 @@ func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
return nil
}

func (gh *GHWebhooks) listen() error {
r := mux.NewRouter()
r.HandleFunc("/webhooks", gh.webhookHandler).Methods("POST")
http.ListenAndServe(fmt.Sprintf(":%s", gh.ServiceAddress), r)
}

func (gh *GHWebhooks) Start() error {
gh.Lock()
defer gh.Unlock()
for {
select {
case <-gh.done:
return nil
default:
r := mux.NewRouter()
r.HandleFunc("/webhooks", gh.webhookHandler).Methods("POST")
http.ListenAndServe(fmt.Sprintf(":%s", gh.ServiceAddress), r)
}
}
gh.done = make(chan struct{})
gh.in = make(chan mod.Event)
// Start the UDP listener
go gh.listen()
// Start the line parser
log.Printf("Started the ghwebhooks service on %s\n", s.ServiceAddress)
}

func (gh *GHWebhooks) Stop() {
@@ -95,6 +95,8 @@ func (gh *GHWebhooks) Stop() {

// Handles the /webhooks route
func (gh *GHWebhooks) webhookHandler(w http.ResponseWriter, r *http.Request) {
gh.Lock()
defer gh.Unlock()
eventType := r.Header["X-Github-Event"][0]
data, err := ioutil.ReadAll(r.Body)
if err != nil {