Unverified Commit c36d105d authored by Ivar Derksen's avatar Ivar Derksen Committed by GitHub
Browse files

Merge pull request #6 from privacybydesign/add-webhooks

Support sending dangers to arbitrary HTTP endpoints (webhooks)
parents 6428b4e9 ea8bd0a9
......@@ -21,3 +21,6 @@ healthchecks:
responsebodycontains: "De stichting Privacy by Design creëert en onderhoudt gratis open source software waarbij de privacy van de gebruiker voorop staat."
bindaddr: ':8079'
interval: 5m
webhooks:
- https://example.com/?message=%s
......@@ -13,6 +13,7 @@ import (
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"path"
"strings"
......@@ -95,6 +96,7 @@ type Conf struct {
HealthChecks []HealthCheck
Interval time.Duration
SlackWebhooks []string
WebHooks []string
}
func main() {
......@@ -225,16 +227,42 @@ func runChecks(irmaConfig *irma.Configuration) {
logCurrentIssues(curIssues.messages())
newIssues, fixedIssues := difference(issues, curIssues)
if len(conf.SlackWebhooks) > 0 {
newIssues, fixedIssues := difference(issues, curIssues)
go pushToSlack(newIssues, fixedIssues, initialCheck)
}
// If this is an initial check, don't send the issues to webhooks
if len(conf.WebHooks) > 0 && !initialCheck {
go pushToWebHooks(newIssues)
}
issues = curIssues
initialCheck = false
lastCheck = time.Now()
}
func pushToWebHooks(newIssues issueEntries) {
dangers := newIssues.filter(danger)
for _, msg := range dangers {
for _, bareURL := range conf.WebHooks {
u := fmt.Sprintf(bareURL, url.QueryEscape("Watchdog: "+msg))
res, err := http.Get(u)
if err != nil {
log.Printf("SMS webhook %s: %s", u, err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Printf("Webhook response body error: %s", err)
}
if len(body) != 0 {
log.Printf("Webhook response body: %s", string(body))
}
}
}
}
func pushToSlack(newIssues, fixedIssues issueEntries, initial bool) {
strGood := "good"
strWarning := "warning"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment