diff --git a/docs/generic_webhook.md b/docs/generic_webhook.md index 5769ec9..8519a9f 100644 --- a/docs/generic_webhook.md +++ b/docs/generic_webhook.md @@ -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. diff --git a/main.go b/main.go index 0713805..52ff5db 100644 --- a/main.go +++ b/main.go @@ -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, } diff --git a/rageshake.sample.yaml b/rageshake.sample.yaml index efcdb01..dcc1493 100644 --- a/rageshake.sample.yaml +++ b/rageshake.sample.yaml @@ -50,3 +50,9 @@ email_from: Rageshake 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 diff --git a/submit.go b/submit.go index def201c..e17c675 100644 --- a/submit.go +++ b/submit.go @@ -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, - } + 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 { - return err + 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 }