Skip to content

Commit

Permalink
feat: add ebpf security e2e trigger (#1843)
Browse files Browse the repository at this point in the history
* add ebpf  trigger

* fix lint
  • Loading branch information
Takuka0311 authored Oct 30, 2024
1 parent 5a168f8 commit 095d89c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/engine/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func ScenarioInitializer(ctx *godog.ScenarioContext) {
ctx.When(`^generate \{(\d+)\} delimiter logs to file \{(.*)\}, with interval \{(\d+)\}ms$`, trigger.DelimiterSingle)
ctx.When(`^query through \{(.*)\}`, control.SetQuery)
ctx.When(`^begin trigger`, trigger.BeginTrigger)
ctx.When(`^execute \{(\d+)\} commands to generate process security events`, trigger.TrigerProcessSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate network security events on url \{(.*)\}$`, trigger.TrigerNetworksSecurityEvents)
ctx.When(`^execute \{(\d+)\} commands to generate file security events on files \{(.*)\}$`, trigger.TrigerFileSecurityEvents)
ctx.When(`^generate random nginx logs to file, speed \{(\d+)\}MB/s, total \{(\d+)\}min, to file \{(.*)\}`, trigger.GenerateRandomNginxLogToFile)
ctx.When(`^start monitor \{(\S+)\}`, monitor.StartMonitor)
Expand Down
51 changes: 51 additions & 0 deletions test/engine/trigger/ebpf_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,57 @@ import (
"github.com/alibaba/ilogtail/test/engine/setup"
)

/*
********************
input_process_security
********************
*/
func TrigerProcessSecurityEvents(ctx context.Context, commandCnt int) (context.Context, error) {
time.Sleep(5 * time.Second)
if err := execveCommands(ctx, commandCnt); err != nil {
return ctx, err
}
return ctx, nil
}

func execveCommands(ctx context.Context, commandCnt int) error {
execveCommand := "ps -ef | grep loongcollector-e2e-test"
for i := 0; i < commandCnt; i++ {
if err := setup.Env.ExecOnSource(ctx, execveCommand); err != nil {
return err
}
}
return nil
}

/*
********************
input_network_security
********************
*/
func TrigerNetworksSecurityEvents(ctx context.Context, commandCnt int, url string) (context.Context, error) {
time.Sleep(5 * time.Second)
if err := curlURL(ctx, commandCnt, url); err != nil {
return ctx, err
}
return ctx, nil
}

func curlURL(ctx context.Context, commandCnt int, url string) error {
curlCommand := "curl --connect-timeout 1 " + url + ";"
for i := 0; i < commandCnt; i++ {
if err := setup.Env.ExecOnSource(ctx, curlCommand); err != nil {
return err
}
}
return nil
}

/*
********************
input_file_security
********************
*/
const triggerFileSecurityTemplate = "cd {{.WorkDir}} && COMMAND_CNT={{.CommandCnt}} FILE_NAME={{.FileName}} {{.Command}}"

func TrigerFileSecurityEvents(ctx context.Context, commandCnt int, filenames string) (context.Context, error) {
Expand Down

0 comments on commit 095d89c

Please sign in to comment.