make http return code for mismatched rules configurable

Signed-off-by: Mathias Merscher <Mathias.Merscher@dg-i.net>
This commit is contained in:
Mathias Merscher 2017-02-10 12:32:11 +01:00
parent 8226d5e50f
commit ddb1f2441a
4 changed files with 20 additions and 1 deletions

View file

@ -242,6 +242,17 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Check if a return code is configured for the hook
if matchedHook.TriggerRuleMismatchCode != 0 {
// Check if the configured return code is supported by the http package
// by testing if there is a StatusText for this code.
if len(http.StatusText(matchedHook.TriggerRuleMismatchCode)) > 0 {
w.WriteHeader(matchedHook.TriggerRuleMismatchCode)
} else {
log.Printf("%s got matched, but the configured return code %d is unknown - defaulting to 200\n", matchedHook.ID, matchedHook.TriggerRuleMismatchCode)
}
}
// if none of the hooks got triggered
log.Printf("%s got matched, but didn't get triggered because the trigger rules were not satisfied\n", matchedHook.ID)