xmpp-webhook

webhook to xmpp gateway (clone of https://github.com/opthomas-prime/xmpp-webhook/ with my own mods)
git clone https://git.e1e0.net/xmpp-webhook.git
Log | Files | Refs | README | LICENSE

commit 7dcee351496bf25c5fd2c5c1db421b2c7244bd4b
parent dc50f1b04d7e7a8d151dc7e19510c718e8640cdc
Author: Paco Esteban <paco@onna.be>
Date:   Mon, 15 Jul 2019 12:37:13 +0200

add custom alert handler

Diffstat:
Mhandler.go | 29+++++++++++++++++++++++++++++
Mmain.go | 5++++-
2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/handler.go b/handler.go @@ -70,6 +70,35 @@ func grafanaParserFunc(r *http.Request) (string, error) { return message, nil } +/************* +CUSTOM PARSER +*************/ +func customParserFunc(r *http.Request) (string, error) { + // get alert data from request + body, err := ioutil.ReadAll(r.Body) + if err != nil { + return "", err + } + + // grafana alert struct + alert := &struct { + Title string `json:"title"` + Message string `json:"message"` + }{} + + // parse body into the alert struct + err = json.Unmarshal(body, &alert) + if err != nil { + return "", err + } + + // contruct alert message + var message string + message = "!! " + alert.Title + "\n" + alert.Message + + return message, nil +} + /**************** PROMETHEUS PARSER ****************/ diff --git a/main.go b/main.go @@ -99,9 +99,12 @@ func main() { // initialize handler for grafana alerts http.Handle("/grafana", newMessageHandler(messages, grafanaParserFunc)) - // initialize handler for grafana alerts + // initialize handler for custom alerts http.Handle("/prometheus", newMessageHandler(messages, prometheusParserFunc)) + // initialize handler for custom alerts + http.Handle("/custom", newMessageHandler(messages, customParserFunc)) + // listen for requests http.ListenAndServe(":4321", nil) }