plugins: improve notifier and searcher

This commit is contained in:
Nicola Murino
2021-10-20 19:39:49 +02:00
parent 3bbe67571f
commit 97d0a48557
18 changed files with 861 additions and 388 deletions

View File

@@ -54,7 +54,7 @@ func InitializeActionHandler(handler ActionHandler) {
func ExecutePreAction(user *dataprovider.User, operation, filePath, virtualPath, protocol, ip string, fileSize int64,
openFlags int,
) error {
plugin.Handler.NotifyFsEvent(time.Now(), operation, user.Username, filePath, "", "", protocol, ip, virtualPath, "", fileSize, nil)
plugin.Handler.NotifyFsEvent(time.Now().UnixNano(), operation, user.Username, filePath, "", "", protocol, ip, virtualPath, "", fileSize, nil)
if !util.IsStringInSlice(operation, Config.Actions.ExecuteOn) {
// for pre-delete we execute the internal handling on error, so we must return errUnconfiguredAction.
// Other pre action will deny the operation on error so if we have no configuration we must return
@@ -73,7 +73,7 @@ func ExecutePreAction(user *dataprovider.User, operation, filePath, virtualPath,
func ExecuteActionNotification(user *dataprovider.User, operation, filePath, virtualPath, target, virtualTarget, sshCmd,
protocol, ip string, fileSize int64, err error,
) {
plugin.Handler.NotifyFsEvent(time.Now(), operation, user.Username, filePath, target, sshCmd, protocol, ip, virtualPath,
plugin.Handler.NotifyFsEvent(time.Now().UnixNano(), operation, user.Username, filePath, target, sshCmd, protocol, ip, virtualPath,
virtualTarget, fileSize, err)
notification := newActionNotification(user, operation, filePath, virtualPath, target, virtualTarget, sshCmd, protocol,
ip, fileSize, 0, err)
@@ -139,9 +139,9 @@ func newActionNotification(
}
if err == ErrQuotaExceeded {
status = 2
status = 3
} else if err != nil {
status = 0
status = 2
}
return &ActionNotification{
@@ -160,7 +160,7 @@ func newActionNotification(
Protocol: protocol,
IP: ip,
OpenFlags: openFlags,
Timestamp: util.GetTimeAsMsSinceEpoch(time.Now()),
Timestamp: time.Now().UnixNano(),
}
}