logs: add a specific log structure for successful logins

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2024-12-07 10:29:33 +01:00
parent f8bdb84e8d
commit e21c989038
8 changed files with 81 additions and 61 deletions

View File

@@ -268,6 +268,26 @@ func ConnectionFailedLog(user, ip, loginType, protocol, errorString string) {
Send()
}
// LoginLog logs successful logins.
func LoginLog(user, ip, loginMethod, protocol, connectionID, clientVersion string, encrypted bool, info string) {
ev := logger.Info()
ev.Timestamp().
Str("sender", "login").
Str("ip", ip).
Str("username", user).
Str("method", loginMethod).
Str("protocol", protocol)
if connectionID != "" {
ev.Str("connection_id", connectionID)
}
ev.Str("client", clientVersion).
Bool("encrypted", encrypted)
if info != "" {
ev.Str("info", info)
}
ev.Send()
}
func isLogFilePathValid(logFilePath string) bool {
cleanInput := filepath.Clean(logFilePath)
if cleanInput == "." || cleanInput == ".." {