From ebd91958636680a5d7abdf7d2b71603b5bf5bbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E9=A3=8F?= Date: Wed, 30 Oct 2024 10:32:39 +0800 Subject: [PATCH 1/2] add ebpf trigger --- test/engine/steps.go | 2 ++ test/engine/trigger/ebpf_trigger.go | 51 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/test/engine/steps.go b/test/engine/steps.go index 305e317465..1808aea2df 100644 --- a/test/engine/steps.go +++ b/test/engine/steps.go @@ -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) diff --git a/test/engine/trigger/ebpf_trigger.go b/test/engine/trigger/ebpf_trigger.go index 6b0aaa5d87..def71f7278 100644 --- a/test/engine/trigger/ebpf_trigger.go +++ b/test/engine/trigger/ebpf_trigger.go @@ -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) { From 546b762fde281de7f5fbd6cd0a7dc0da2f82b3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E9=A3=8F?= Date: Wed, 30 Oct 2024 10:53:17 +0800 Subject: [PATCH 2/2] fix lint --- test/engine/trigger/ebpf_trigger.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/engine/trigger/ebpf_trigger.go b/test/engine/trigger/ebpf_trigger.go index def71f7278..f606cc1f5e 100644 --- a/test/engine/trigger/ebpf_trigger.go +++ b/test/engine/trigger/ebpf_trigger.go @@ -53,13 +53,13 @@ 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 { + if err := curlURL(ctx, commandCnt, url); err != nil { return ctx, err } return ctx, nil } -func curlUrl(ctx context.Context, commandCnt int, url string) error { +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 {