genericWebhookURLs as a list rather than a single endpoint.

neilalexander/serverversion
Michael Kaye 2 years ago
parent 8e001408d8
commit 4e3eeec92c

@ -1,7 +1,8 @@
## Generic webhook request
If the configuration option `generic_webhook_url` is set, then a synchronous request to
the endpoint will be sent after the incoming request is parsed and the files are uploaded.
If the configuration option `generic_webhook_urls` is set, then an asynchronous request to
each endpoint listed will be sent in parallel, after the incoming request is parsed and the
files are uploaded.
The webhook is designed for notification or other tracking services, and does not contain
the original log files uploaded.
@ -36,3 +37,4 @@ A sample JSON body is as follows:
```
The log and other files can be individually downloaded by concatenating the `listing_url` and the `logs` or `files` name.
You may need to provide a HTTP basic auth user/pass if configured on your rageshake server.

@ -72,7 +72,7 @@ type config struct {
SMTPPassword string `yaml:"smtp_password"`
GenericWebhookURL string `yaml:"generic_webhook_url"`
GenericWebhookURLs []string `yaml:"generic_webhook_urls"`
}
func basicAuth(handler http.Handler, username, password, realm string) http.Handler {
@ -181,11 +181,11 @@ func main() {
}
func configureGenericWebhookClient(cfg *config) (*http.Client) {
if cfg.GenericWebhookURL == "" {
fmt.Println("No generic_webhook_url configured.")
if len(cfg.GenericWebhookURLs) == 0 {
fmt.Println("No generic_webhook_urls configured.")
return nil
}
fmt.Println("Will forward metadata of all requests to ", cfg.GenericWebhookURL)
fmt.Println("Will forward metadata of all requests to ", cfg.GenericWebhookURLs)
return &http.Client{
Timeout: time.Second * 300,
}

@ -50,3 +50,9 @@ email_from: Rageshake <rageshake@matrix.org>
smtp_server: localhost:25
smtp_username: myemailuser
smtp_password: myemailpass
# a list of webhook URLs, (see docs/generic_webhook.md)
generic_webhook_urls:
- https://server.example.com/your-server/api
- http://another-server.com/api

@ -521,24 +521,26 @@ func (s *submitServer) submitGenericWebhook(p parsedPayload, listingURL string,
if s.genericWebhookClient == nil {
return nil
}
url := s.cfg.GenericWebhookURL
log.Println("Submitting json to URL", url)
// Enrich the parsedPayload with a reportURL and listingURL, to convert a single struct
// to JSON easily
genericHookPayload := genericWebhookPayload{
parsedPayload: p,
ReportURL: reportURL,
ListingURL: listingURL,
}
payloadBuffer := new(bytes.Buffer)
json.NewEncoder(payloadBuffer).Encode(genericHookPayload)
req, err := http.NewRequest("POST", url, payloadBuffer)
req.Header.Set("Content-Type", "application/json")
if err != nil {
return err
for _, url := range s.cfg.GenericWebhookURLs {
// Enrich the parsedPayload with a reportURL and listingURL, to convert a single struct
// to JSON easily
genericHookPayload := genericWebhookPayload{
parsedPayload: p,
ReportURL: reportURL,
ListingURL: listingURL,
}
payloadBuffer := new(bytes.Buffer)
json.NewEncoder(payloadBuffer).Encode(genericHookPayload)
req, err := http.NewRequest("POST", url, payloadBuffer)
req.Header.Set("Content-Type", "application/json")
if err != nil {
log.Println("Unable to submit to URL ", url, " ", err)
return err
}
log.Println("Making generic webhook request to URL ", url)
go s.sendGenericWebhook(req)
}
go s.sendGenericWebhook(req)
return nil
}