-
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EventManager: add an action to rotate the log file
Signed-off-by: Nicola Murino <[email protected]>
- Loading branch information
Showing
10 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7209,6 +7209,103 @@ func TestEventRuleIPBlocked(t *testing.T) { | |
assert.NoError(t, err) | ||
} | ||
|
||
func TestEventRuleRotateLog(t *testing.T) { | ||
smtpCfg := smtp.Config{ | ||
Host: "127.0.0.1", | ||
Port: 2525, | ||
From: "[email protected]", | ||
TemplatesPath: "templates", | ||
} | ||
err := smtpCfg.Initialize(configDir, true) | ||
require.NoError(t, err) | ||
|
||
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated) | ||
assert.NoError(t, err) | ||
|
||
a1 := dataprovider.BaseEventAction{ | ||
Name: "a1", | ||
Type: dataprovider.ActionTypeRotateLogs, | ||
} | ||
action1, _, err := httpdtest.AddEventAction(a1, http.StatusCreated) | ||
assert.NoError(t, err) | ||
a2 := dataprovider.BaseEventAction{ | ||
Name: "a2", | ||
Type: dataprovider.ActionTypeEmail, | ||
Options: dataprovider.BaseEventActionOptions{ | ||
EmailConfig: dataprovider.EventActionEmailConfig{ | ||
Recipients: []string{"[email protected]"}, | ||
Subject: `OK`, | ||
Body: "OK action", | ||
}, | ||
}, | ||
} | ||
action2, _, err := httpdtest.AddEventAction(a2, http.StatusCreated) | ||
assert.NoError(t, err) | ||
|
||
r1 := dataprovider.EventRule{ | ||
Name: "rule1", | ||
Status: 1, | ||
Trigger: dataprovider.EventTriggerFsEvent, | ||
Conditions: dataprovider.EventConditions{ | ||
FsEvents: []string{"mkdir"}, | ||
Options: dataprovider.ConditionOptions{ | ||
Names: []dataprovider.ConditionPattern{ | ||
{ | ||
Pattern: user.Username, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Actions: []dataprovider.EventAction{ | ||
{ | ||
BaseEventAction: dataprovider.BaseEventAction{ | ||
Name: action1.Name, | ||
}, | ||
Order: 1, | ||
}, | ||
{ | ||
BaseEventAction: dataprovider.BaseEventAction{ | ||
Name: action2.Name, | ||
}, | ||
Order: 2, | ||
}, | ||
}, | ||
} | ||
rule1, resp, err := httpdtest.AddEventRule(r1, http.StatusCreated) | ||
assert.NoError(t, err, string(resp)) | ||
conn, client, err := getSftpClient(user) | ||
if assert.NoError(t, err) { | ||
defer conn.Close() | ||
defer client.Close() | ||
|
||
lastReceivedEmail.reset() | ||
err := client.Mkdir("just a test dir") | ||
assert.NoError(t, err) | ||
// just check that the action is executed | ||
assert.Eventually(t, func() bool { | ||
return lastReceivedEmail.get().From != "" | ||
}, 1500*time.Millisecond, 100*time.Millisecond) | ||
email := lastReceivedEmail.get() | ||
assert.Len(t, email.To, 1) | ||
assert.Contains(t, email.To, "[email protected]") | ||
} | ||
|
||
_, err = httpdtest.RemoveEventRule(rule1, http.StatusOK) | ||
assert.NoError(t, err) | ||
_, err = httpdtest.RemoveEventAction(action1, http.StatusOK) | ||
assert.NoError(t, err) | ||
_, err = httpdtest.RemoveEventAction(action2, http.StatusOK) | ||
assert.NoError(t, err) | ||
_, err = httpdtest.RemoveUser(user, http.StatusOK) | ||
assert.NoError(t, err) | ||
err = os.RemoveAll(user.GetHomeDir()) | ||
assert.NoError(t, err) | ||
|
||
smtpCfg = smtp.Config{} | ||
err = smtpCfg.Initialize(configDir, true) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestEventRuleInactivityCheck(t *testing.T) { | ||
smtpCfg := smtp.Config{ | ||
Host: "127.0.0.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters