Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to use new scope.Error method #2208

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ require (
www.velocidex.com/golang/go-prefetch v0.0.0-20220801101854-338dbe61982a
www.velocidex.com/golang/oleparse v0.0.0-20220617011920-94df2342d0b7
www.velocidex.com/golang/regparser v0.0.0-20221020153526-bbc758cbd18b
www.velocidex.com/golang/vfilter v0.0.0-20221020070405-7af3cd80b934
www.velocidex.com/golang/vfilter v0.0.0-20221101121437-3c06b865adbf
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1197,5 +1197,7 @@ www.velocidex.com/golang/regparser v0.0.0-20221020153526-bbc758cbd18b/go.mod h1:
www.velocidex.com/golang/vfilter v0.0.0-20220103082604-85bb38175cb7/go.mod h1:eEFMhAmoFHWGCKF39j+iOhTH8REpqBndc3OsdPsxqo8=
www.velocidex.com/golang/vfilter v0.0.0-20221020070405-7af3cd80b934 h1:vUdXxTpIjiZmSvAp3dPEZs4ZcBpQKJWh3lfmZVqYKNQ=
www.velocidex.com/golang/vfilter v0.0.0-20221020070405-7af3cd80b934/go.mod h1:R3nLf1iHcc7eezqqc68KF+SUOXaAJeFz3TV+j8xorfY=
www.velocidex.com/golang/vfilter v0.0.0-20221101121437-3c06b865adbf h1:9QCjJRFZWaXrUhcUFzld1EhgHSXywn1dpEqq25dx55Q=
www.velocidex.com/golang/vfilter v0.0.0-20221101121437-3c06b865adbf/go.mod h1:R3nLf1iHcc7eezqqc68KF+SUOXaAJeFz3TV+j8xorfY=
www.velocidex.com/golang/vtypes v0.0.0-20220816192452-6a27ae078f12 h1:8azOLd/l6sPy1/ug03ueA7jLfsVwE1sI3oHg9q/nkqQ=
www.velocidex.com/golang/vtypes v0.0.0-20220816192452-6a27ae078f12/go.mod h1:gpuRaiyhcuPmZYvI/zw+rjlDXklR2ORaLQBuzCXe84o=
2 changes: 1 addition & 1 deletion vql/aggregates/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (self _AllFunction) Call(
arg := &_AllFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("all: %v", err)
scope.Error("all: %v", err)
return vfilter.Null{}
}

Expand Down
2 changes: 1 addition & 1 deletion vql/aggregates/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (self _AnyFunction) Call(
arg := &_AllFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("any: %v", err)
scope.Error("any: %v", err)
return vfilter.Null{}
}

Expand Down
2 changes: 1 addition & 1 deletion vql/aggregates/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (self _RateFunction) Call(
arg := &_RateFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("rate: %s", err.Error())
scope.Error("rate: %s", err.Error())
return vfilter.Null{}
}

Expand Down
4 changes: 2 additions & 2 deletions vql/common/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (self BatchPlugin) Call(
arg := &BatchPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("batch: %v", err)
scope.Error("batch: %v", err)
return
}

Expand All @@ -40,7 +40,7 @@ func (self BatchPlugin) Call(
// Compile the batch lambda.
lambda, err = vfilter.ParseLambda(arg.BatchFunc)
if err != nil {
scope.Log("batch: %v", err)
scope.Error("batch: %v", err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions vql/common/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (self _CacheFunc) Call(ctx context.Context, scope vfilter.Scope,
arg := &_CacheFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("cache: %s", err.Error())
scope.Error("cache: %s", err.Error())
return vfilter.Null{}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func (self _MemoizeFunction) Call(ctx context.Context, scope vfilter.Scope,
arg := &_MemoizeFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("memoize: %s", err.Error())
scope.Error("memoize: %s", err.Error())
return vfilter.Null{}
}

Expand Down
4 changes: 2 additions & 2 deletions vql/common/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (self ClockPlugin) Call(
arg := &ClockPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("clock: %v", err)
scope.Error("clock: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are probably fine for Error - it means the args are not valid somehow and may be a syntax error (BTW these are automatically marked as error anyway here

getLogErrorRegex(config_obj).FindStringIndex(row.Message) != nil {

return
}

Expand All @@ -63,7 +63,7 @@ func (self ClockPlugin) Call(
if !utils.IsNil(arg.StartTime) {
start, err := functions.TimeFromAny(scope, arg.StartTime)
if err != nil {
scope.Log("clock: %v", err)
scope.Error("clock: %v", err)
return
}

Expand Down
6 changes: 3 additions & 3 deletions vql/common/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (self ColumnFilter) Call(
arg := &ColumnFilterArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("column_filter: %v", err)
scope.Error("column_filter: %v", err)
return
}

Expand All @@ -43,7 +43,7 @@ func (self ColumnFilter) Call(
for _, include := range arg.Include {
c, err := regexp.Compile(include)
if err != nil {
scope.Log("column_filter: %v", err)
scope.Error("column_filter: %v", err)
return
}
includes = append(includes, c)
Expand All @@ -54,7 +54,7 @@ func (self ColumnFilter) Call(
for _, exclude := range arg.Exclude {
c, err := regexp.Compile(exclude)
if err != nil {
scope.Log("column_filter: %v", err)
scope.Error("column_filter: %v", err)
return
}
excludes = append(excludes, c)
Expand Down
2 changes: 1 addition & 1 deletion vql/common/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (self _DiffPlugin) Call(ctx context.Context,
arg := &_DiffPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("diff: %v", err)
scope.Error("diff: %v", err)
return
}

Expand Down
8 changes: 4 additions & 4 deletions vql/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (self *EnvFunction) Call(ctx context.Context,

err := vql_subsystem.CheckAccess(scope, acls.MACHINE_STATE)
if err != nil {
scope.Log("environ: %s", err)
scope.Error("environ: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be a critical error - if running with lower privileges we do want to just ignore

return false
}

err = arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("environ: %s", err.Error())
scope.Error("environ: %s", err.Error())
return false
}

Expand Down Expand Up @@ -80,14 +80,14 @@ func init() {

err := vql_subsystem.CheckAccess(scope, acls.MACHINE_STATE)
if err != nil {
scope.Log("environ: %s", err)
scope.Error("environ: %s", err)
return result
}

arg := &EnvPluginArgs{}
err = arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("%s: %s", "environ", err.Error())
scope.Error("%s: %s", "environ", err.Error())
return result
}

Expand Down
4 changes: 2 additions & 2 deletions vql/common/fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewFIFOCache(
close(done)
})
if err != nil {
scope.Log("AddDestructor: %s", err)
scope.Error("AddDestructor: %s", err)
close(done)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ func (self _FIFOPlugin) Call(ctx context.Context,
arg := &_FIFOPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("fifo: %v", err)
scope.Error("fifo: %v", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion vql/common/for.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (self ForPlugin) Call(
arg := &ForPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("for: %v", err)
scope.Error("for: %v", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion vql/common/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (self ItemsPlugin) Call(
arg := &ItemsPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("items: %v", err)
scope.Error("items: %v", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion vql/common/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (self LRUFunction) Call(ctx context.Context, scope vfilter.Scope,
arg := &LRUFunctionArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("lru: %s", err.Error())
scope.Error("lru: %s", err.Error())
return vfilter.Null{}
}

Expand Down
6 changes: 3 additions & 3 deletions vql/common/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (self MailPlugin) Call(

err := vql_subsystem.CheckAccess(scope, acls.SERVER_ADMIN)
if err != nil {
scope.Log("mail: %s", err)
scope.Error("mail: %s", err)
return
}

Expand All @@ -77,7 +77,7 @@ func (self MailPlugin) Call(
arg := &MailPluginArgs{}
err = arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("mail: %v", err)
scope.Error("mail: %v", err)
return
}
if time.Since(last_mail) < time.Duration(arg.Period)*time.Second {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (self MailPlugin) Call(
// Send the email to Bob, Cora and Dan.
err = d.DialAndSend(m)
if err != nil {
scope.Log("mail: %v", err)
scope.Error("mail: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may not be critical - can be an intermittant failure

// Failed to send the mail but we should emit
// the row anyway so it gets logged in the
// artifact CSV file.
Expand Down
2 changes: 1 addition & 1 deletion vql/common/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (self _SamplerPlugin) Call(ctx context.Context,
arg := &_SamplerPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("sample: %v", err)
scope.Error("sample: %v", err)
return
}

Expand Down
10 changes: 5 additions & 5 deletions vql/common/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (self ShellPlugin) Call(

err := vql_subsystem.CheckAccess(scope, acls.EXECVE)
if err != nil {
scope.Log("shell: %v", err)
scope.Error("shell: %v", err)
return
}

Expand All @@ -76,7 +76,7 @@ func (self ShellPlugin) Call(
arg := &ShellPluginArgs{}
err = arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("shell: %v", err)
scope.Error("shell: %v", err)
return
}

Expand Down Expand Up @@ -121,19 +121,19 @@ func (self ShellPlugin) Call(

stdout_pipe, err := command.StdoutPipe()
if err != nil {
scope.Log("shell: no command to run")
scope.Error("shell: no command to run")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the wrong message :-)

IDK - is this critical or not? it might be or it might be intermittent (e.g. tool failed to download etc)

return
}

stderr_pipe, err := command.StderrPipe()
if err != nil {
scope.Log("shell: no command to run")
scope.Error("shell: no command to run")
return
}

err = command.Start()
if err != nil {
scope.Log("shell: %v", err)
scope.Error("shell: %v", err)
select {
case <-ctx.Done():
return
Expand Down
19 changes: 10 additions & 9 deletions vql/common/yara.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build cgo && yara
// +build cgo,yara

/*
Expand Down Expand Up @@ -85,7 +86,7 @@ func (self YaraScanPlugin) Call(
arg := &YaraScanPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("yarascan: %v", err)
scope.Error("yarascan: %v", err)
return
}

Expand All @@ -99,7 +100,7 @@ func (self YaraScanPlugin) Call(

err = vql_subsystem.CheckFilesystemAccess(scope, arg.Accessor)
if err != nil {
scope.Log("yara: %s", err.Error())
scope.Error("yara: %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not critical error

return
}

Expand Down Expand Up @@ -127,15 +128,15 @@ func (self YaraScanPlugin) Call(

accessor, err := accessors.GetAccessor(arg.Accessor, scope)
if err != nil {
scope.Log("yara: %v", err)
scope.Error("yara: %v", err)
return
}

for _, filename_any := range arg.Files {
filename, err := accessors.ParseOSPath(
ctx, scope, accessor, filename_any)
if err != nil {
scope.Log("yara: %v", err)
scope.Error("yara: %v", err)
return
}
matcher.filename = filename
Expand Down Expand Up @@ -212,14 +213,14 @@ func (self *scanReporter) scanFileByAccessor(

accessor, err := accessors.GetAccessor(accessor_name, self.scope)
if err != nil {
self.scope.Log("yara: %v", err)
self.scope.Error("yara: %v", err)
return
}

// Open the file with the accessor
f, err := accessor.OpenWithOSPath(self.filename)
if err != nil {
self.scope.Log("yara: Failed to open %v with accessor %v: %v",
self.scope.Error("yara: Failed to open %v with accessor %v: %v",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is definitely not a critical error - we fail to open files all the time

self.filename, accessor_name, err)
return
}
Expand Down Expand Up @@ -494,7 +495,7 @@ func (self YaraProcPlugin) Call(
arg := &YaraProcPluginArgs{}
err := arg_parser.ExtractArgsWithContext(ctx, scope, args, arg)
if err != nil {
scope.Log("proc_yara: %v", err)
scope.Error("proc_yara: %v", err)
return
}

Expand All @@ -509,7 +510,7 @@ func (self YaraProcPlugin) Call(
generated_rules := RuleGenerator(scope, arg.Rules)
rules, err = yara.Compile(generated_rules, variables)
if err != nil {
scope.Log("Failed to initialize YARA compiler: %v", err)
scope.Error("Failed to initialize YARA compiler: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is definitely critical error

return
}

Expand All @@ -520,7 +521,7 @@ func (self YaraProcPlugin) Call(
arg.Pid, yara.ScanFlagsProcessMemory,
300*time.Second)
if err != nil {
scope.Log("proc_yara: pid %v: %v", arg.Pid, err)
scope.Error("proc_yara: pid %v: %v", arg.Pid, err)
return
}

Expand Down
Loading