add logging for successful requests

This commit is contained in:
Nils 2021-12-23 01:51:13 +01:00
parent 2b54af9b4b
commit 053b958a60
Signed by: byreqz
GPG Key ID: 396A62D7D436749E

11
main.go
View File

@ -40,6 +40,11 @@ func runner(remoteip string, command string, args... string) string{
"error": err.Error(), "error": err.Error(),
}).Warn("the following request failed:") }).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) return string(cmd)
} }
@ -52,10 +57,10 @@ func ping(w http.ResponseWriter, req *http.Request) {
geturl := strings.Split(req.URL.String(), "/") geturl := strings.Split(req.URL.String(), "/")
target := geturl[2] target := geturl[2]
pingres := runner(req.RemoteAddr, "ping", "-c5", target) pingres := runner(req.RemoteAddr, "ping", "-c5", target)
if pingres != "" { if pingres == "" {
fmt.Fprintln(w, pingres)
} else {
fmt.Fprintln(w, http.StatusInternalServerError) fmt.Fprintln(w, http.StatusInternalServerError)
} else {
fmt.Fprintln(w, pingres)
} }
} }