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(),
}).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)
}
}