From 053b958a6016335169904a88f2852c7b11945c2b Mon Sep 17 00:00:00 2001 From: Nils Date: Thu, 23 Dec 2021 01:51:13 +0100 Subject: [PATCH] add logging for successful requests --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 9a92c0b..c86188f 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,11 @@ func runner(remoteip string, command string, args... string) string{ "error": err.Error(), }).Warn("the following request failed:") } + } else { + logfile.WithFields(log.Fields{ + "remote_ip": remoteip, + "command": fmt.Sprint(command, args), + }).Info("the following request was issued without error") } return string(cmd) } @@ -52,10 +57,10 @@ func ping(w http.ResponseWriter, req *http.Request) { geturl := strings.Split(req.URL.String(), "/") target := geturl[2] pingres := runner(req.RemoteAddr, "ping", "-c5", target) - if pingres != "" { - fmt.Fprintln(w, pingres) - } else { + if pingres == "" { fmt.Fprintln(w, http.StatusInternalServerError) + } else { + fmt.Fprintln(w, pingres) } }