Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions cmd/tracee-ebpf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,9 @@ func main() {
Usage: "control how and where output is printed. run '--output help' for more info.",
},
&cli.StringSliceFlag{
Name: "proctree",
Aliases: []string{"t"},
Value: cli.NewStringSlice("none"),
Usage: "process tree options. run '--proctree help' for more info.",
},
&cli.StringSliceFlag{
Name: "dnscache",
Value: cli.NewStringSlice("none"),
Usage: "dns cache options. run '--dnscache help' for more info",
Name: "stores",
Value: cli.NewStringSlice(),
Usage: "stores configurations. run '--stores help' for more info",
},
&cli.StringSliceFlag{
Name: flags.ContainersFlag,
Expand Down
24 changes: 6 additions & 18 deletions cmd/tracee/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,15 @@
return errfmt.WrapError(err)
}

// Process Tree flags

rootCmd.Flags().StringArrayP(
"proctree",
"t",
[]string{"source=none"},
"[source=[events|signals|both]...]\tControl process tree options",
)
err = viper.BindPFlag("proctree", rootCmd.Flags().Lookup("proctree"))
if err != nil {
return errfmt.WrapError(err)
}

// DNS Cache flags
// Stores flags

// TODO: extract flags
rootCmd.Flags().StringArray(
"dnscache",
[]string{"none"},
"\t\t\t\t\tEnable DNS Cache",
"stores",
[]string{""},
"\t\t\t\t\tStores configurations",

Check warning on line 227 in cmd/tracee/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tracee/cmd/root.go#L225-L227

Added lines #L225 - L227 were not covered by tests
)
err = viper.BindPFlag("dnscache", rootCmd.Flags().Lookup("dnscache"))
err = viper.BindPFlag("stores", rootCmd.Flags().Lookup("stores"))

Check warning on line 229 in cmd/tracee/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tracee/cmd/root.go#L229

Added line #L229 was not covered by tests
if err != nil {
return errfmt.WrapError(err)
}
Expand Down
24 changes: 5 additions & 19 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,18 @@
cfg.CgroupFSPath = res.CgroupfsPath
cfg.CgroupFSForce = res.CgroupfsForce

// Process Tree command line flags

procTreeFlags, err := GetFlagsFromViper("proctree")
if err != nil {
return runner, err
}

procTree, err := flags.PrepareProcTree(procTreeFlags)
// Stores command line flags
storesFlags, err := GetFlagsFromViper("stores")

Check warning on line 145 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L144-L145

Added lines #L144 - L145 were not covered by tests
if err != nil {
return runner, err
}
cfg.ProcTree = procTree

// DNS Cache command line flags

dnsCacheFlags, err := GetFlagsFromViper("dnscache")
stores, err := flags.PrepareStores(storesFlags)

Check warning on line 150 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L150

Added line #L150 was not covered by tests
if err != nil {
return runner, err
}

dnsCache, err := flags.PrepareDnsCache(dnsCacheFlags)
if err != nil {
return runner, err
}

cfg.DNSCacheConfig = dnsCache
cfg.DNSCacheConfig = stores.DNS
cfg.ProcTree = stores.Process

Check warning on line 155 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L154-L155

Added lines #L154 - L155 were not covered by tests

// Capture command line flags - via cobra flag

Expand Down
116 changes: 53 additions & 63 deletions pkg/cmd/cobra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ type cliFlagger interface {
func GetFlagsFromViper(key string) ([]string, error) {
var flagger cliFlagger
rawValue := viper.Get(key)

switch key {
case serverflag.ServerFlag:
flagger = &ServerConfig{}
case "proctree":
flagger = &ProcTreeConfig{}
case "stores":
flagger = &StoresConfig{}
case "capabilities":
flagger = &CapabilitiesConfig{}
case "containers":
Expand All @@ -34,8 +33,6 @@ func GetFlagsFromViper(key string) ([]string, error) {
flagger = &LogConfig{}
case "output":
flagger = &OutputConfig{}
case "dnscache":
flagger = &DnsCacheConfig{}
default:
return nil, errfmt.Errorf("unrecognized key: %s", key)
}
Expand Down Expand Up @@ -160,64 +157,6 @@ func (c *SocketConfig) flags() []string {
return flags
}

//
// proctree flag
//

type ProcTreeConfig struct {
Source string `mapstructure:"source"`
Cache ProcTreeCacheConfig `mapstructure:"cache"`
}

type ProcTreeCacheConfig struct {
Process int `mapstructure:"process"`
Thread int `mapstructure:"thread"`
}

func (c *ProcTreeConfig) flags() []string {
flags := make([]string, 0)

if c.Source != "" {
if c.Source == "none" {
flags = append(flags, "none")
} else {
flags = append(flags, fmt.Sprintf("source=%s", c.Source))
}
}
if c.Cache.Process != 0 {
flags = append(flags, fmt.Sprintf("process-cache=%d", c.Cache.Process))
}
if c.Cache.Thread != 0 {
flags = append(flags, fmt.Sprintf("thread-cache=%d", c.Cache.Thread))
}

return flags
}

//
// dnscache flag
//

type DnsCacheConfig struct {
Enable bool `mapstructure:"enable"`
Size int `mapstructure:"size"`
}

func (c *DnsCacheConfig) flags() []string {
flags := make([]string, 0)

if !c.Enable {
flags = append(flags, "none")
return flags
}

if c.Size != 0 {
flags = append(flags, fmt.Sprintf("size=%d", c.Size))
}

return flags
}

//
// capabilities flag
//
Expand Down Expand Up @@ -480,3 +419,54 @@ type OutputWebhookConfig struct {
GoTemplate string `mapstructure:"gotemplate"`
ContentType string `mapstructure:"content-type"`
}

//
// stores flag
//

type ProcessConfig struct {
Enabled bool `mapstructure:"enabled"`
Processes int `mapstructure:"processes"`
Threads int `mapstructure:"threads"`
Source string `mapstructure:"source"`
Procfs bool `mapstructure:"use-procfs"`
}

type DNSConfig struct {
Enabled bool `mapstructure:"enabled"`
Size int `mapstructure:"size"`
}

type StoresConfig struct {
DNS DNSConfig `mapstructure:"dns"`
Process ProcessConfig `mapstructure:"process"`
}

func (c *StoresConfig) flags() []string {
flags := []string{}

if c.DNS.Enabled {
flags = append(flags, fmt.Sprintf("dns.enabled=%v", c.DNS.Enabled))
}
if c.DNS.Size != 0 {
flags = append(flags, fmt.Sprintf("dns.size=%d", c.DNS.Size))
}

if c.Process.Enabled {
flags = append(flags, fmt.Sprintf("process.enabled=%v", c.Process.Enabled))
}
if c.Process.Processes != 0 {
flags = append(flags, fmt.Sprintf("process.processes=%d", c.Process.Processes))
}
if c.Process.Threads != 0 {
flags = append(flags, fmt.Sprintf("process.threads=%d", c.Process.Threads))
}
if c.Process.Source != "" {
flags = append(flags, fmt.Sprintf("process.source=%s", c.Process.Source))
}
if c.Process.Procfs {
flags = append(flags, fmt.Sprintf("process.use-procfs=%v", c.Process.Procfs))
}

return flags
}
Loading