Skip to content

Commit

Permalink
refactor(plugins): remove legacy debug logging
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Jan 13, 2022
1 parent ac88ed6 commit c1469ed
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
31 changes: 0 additions & 31 deletions plugins/cloudtrail/cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"math"
"sync"

Expand Down Expand Up @@ -58,8 +57,6 @@ const (
PluginEventSource = "aws_cloudtrail"
)

const verbose bool = true

func min(a, b int) int {
if a < b {
return a
Expand Down Expand Up @@ -144,7 +141,6 @@ func (p *pluginInitConfig) setDefault() {
}

func (p *pluginContext) Info() *plugins.Info {
log.Printf("[%s] Info\n", PluginName)
return &plugins.Info{
ID: PluginID,
Name: PluginName,
Expand All @@ -158,12 +154,6 @@ func (p *pluginContext) Info() *plugins.Info {
}

func (p *pluginContext) Init(cfg string) error {
if !verbose {
log.SetOutput(ioutil.Discard)
}

log.Printf("[%s] Init, config=%s\n", PluginName, cfg)

// initialize state
p.jdataEvtnum = math.MaxUint64

Expand All @@ -178,17 +168,10 @@ func (p *pluginContext) Init(cfg string) error {

// enable/disable async extraction optimazion (enabled by default)
extract.SetAsync(p.config.UseAsync)

return nil
}

func (p *pluginContext) Destroy() {
log.Printf("[%s] Destroy\n", PluginName)
}

func (p *pluginContext) Open(params string) (source.Instance, error) {
log.Printf("[%s] Open, params=%s\n", PluginName, params)

// Allocate the context struct for this open instance
oCtx := &openContext{}

Expand All @@ -213,13 +196,7 @@ func (p *pluginContext) Open(params string) (source.Instance, error) {
return oCtx, nil
}

func (o *openContext) Close() {
log.Printf("[%s] Close\n", PluginName)
}

func (o *openContext) NextBatch(pState sdk.PluginState, evts sdk.EventWriters) (int, error) {
log.Printf("[%s] NextBatch\n", PluginName)

var n int
var err error
pCtx := pState.(*pluginContext)
Expand All @@ -230,15 +207,11 @@ func (o *openContext) NextBatch(pState sdk.PluginState, evts sdk.EventWriters) (
}

func (o *openContext) Progress(pState sdk.PluginState) (float64, string) {
log.Printf("[%s] Progress\n", PluginName)

pd := float64(o.curFileNum) / float64(len(o.files))
return pd, fmt.Sprintf("%.2f%% - %v/%v files", pd*100, o.curFileNum, len(o.files))
}

func (p *pluginContext) String(in io.ReadSeeker) (string, error) {
log.Printf("[%s] String\n", PluginName)

var src string
var user string
var err error
Expand Down Expand Up @@ -297,14 +270,10 @@ func (p *pluginContext) String(in io.ReadSeeker) (string, error) {
}

func (p *pluginContext) Fields() []sdk.FieldEntry {
log.Printf("[%s] Fields\n", PluginName)

return supportedFields
}

func (p *pluginContext) Extract(req sdk.ExtractRequest, evt sdk.EventReader) error {
log.Printf("[%s] Extract\n", PluginName)

// Decode the json, but only if we haven't done it yet for this event
if evt.EventNum() != p.jdataEvtnum {
// Read the event data
Expand Down
5 changes: 0 additions & 5 deletions plugins/cloudtrail/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -43,8 +42,6 @@ func openLocal(pCtx *pluginContext, oCtx *openContext, params string) error {
return fmt.Errorf(PluginName+" plugin error: cannot open %s", oCtx.cloudTrailFilesDir)
}

log.Printf("[%s] scanning directory %s\n", PluginName, oCtx.cloudTrailFilesDir)

err := filepath.Walk(oCtx.cloudTrailFilesDir, func(path string, info os.FileInfo, err error) error {
if info != nil && info.IsDir() {
return nil
Expand All @@ -66,7 +63,6 @@ func openLocal(pCtx *pluginContext, oCtx *openContext, params string) error {
return fmt.Errorf(PluginName + " plugin error: no json files found in " + oCtx.cloudTrailFilesDir)
}

log.Printf("[%s] found %d json files\n", PluginName, len(oCtx.files))
return nil
}

Expand Down Expand Up @@ -106,7 +102,6 @@ func openS3(pCtx *pluginContext, oCtx *openContext, input string) error {
Prefix: &prefix,
}, func(p *s3.ListObjectsOutput, last bool) (shouldContinue bool) {
for _, obj := range p.Contents {
//fmt.Printf("> %v %v\n", *obj.Size, *obj.Key)
path := obj.Key
isCompressed := strings.HasSuffix(*path, ".json.gz")
if filepath.Ext(*path) != ".json" && !isCompressed {
Expand Down
15 changes: 2 additions & 13 deletions plugins/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"strconv"
"time"
Expand Down Expand Up @@ -88,7 +87,6 @@ func (p *MyPluginConfig) setDefault() {
}

func (m *MyPlugin) Info() *plugins.Info {
log.Printf("[%s] Info\n", PluginName)
return &plugins.Info{
ID: PluginID,
Name: PluginName,
Expand All @@ -101,8 +99,6 @@ func (m *MyPlugin) Info() *plugins.Info {
}

func (m *MyPlugin) Init(cfg string) error {
log.Printf("[%s] Init, config=%s\n", PluginName, cfg)

// initialize state
m.rand = rand.New(rand.NewSource(time.Now().UnixNano()))

Expand All @@ -123,12 +119,10 @@ func (m *MyPlugin) Init(cfg string) error {
}

func (m *MyPlugin) Destroy() {
log.Printf("[%s] Destroy\n", PluginName)
// nothing to do here
}

func (m *MyPlugin) Open(prms string) (source.Instance, error) {
log.Printf("[%s] Open, params=%s\n", PluginName, prms)

// The format of params is a json object with two params:
// - "start", which denotes the initial value of sample
// - "maxEvents": which denotes the number of events to return before EOF.
Expand Down Expand Up @@ -156,12 +150,10 @@ func (m *MyPlugin) Open(prms string) (source.Instance, error) {
}

func (m *MyInstance) Close() {
log.Printf("[%s] Close\n", PluginName)
// nothing to do here
}

func (m *MyInstance) NextBatch(pState sdk.PluginState, evts sdk.EventWriters) (int, error) {
log.Printf("[%s] NextBatch\n", PluginName)

// Return EOF if reached maxEvents
if m.counter >= m.maxEvents {
return 0, sdk.ErrEOF
Expand Down Expand Up @@ -194,7 +186,6 @@ func (m *MyInstance) NextBatch(pState sdk.PluginState, evts sdk.EventWriters) (i
}

func (m *MyPlugin) String(in io.ReadSeeker) (string, error) {
log.Printf("[%s] String\n", PluginName)
evtBytes, err := ioutil.ReadAll(in)
if err != nil {
return "", err
Expand All @@ -206,7 +197,6 @@ func (m *MyPlugin) String(in io.ReadSeeker) (string, error) {
}

func (m *MyPlugin) Fields() []sdk.FieldEntry {
log.Printf("[%s] Fields\n", PluginName)
return []sdk.FieldEntry{
{Type: "uint64", Name: "dummy.divisible", ArgRequired: true, Desc: "Return 1 if the value is divisible by the provided divisor, 0 otherwise"},
{Type: "uint64", Name: "dummy.value", Desc: "The sample value in the event"},
Expand All @@ -215,7 +205,6 @@ func (m *MyPlugin) Fields() []sdk.FieldEntry {
}

func (m *MyPlugin) Extract(req sdk.ExtractRequest, evt sdk.EventReader) error {
log.Printf("[%s] Extract\n", PluginName)
evtBytes, err := ioutil.ReadAll(evt.Reader())
if err != nil {
return err
Expand Down
14 changes: 0 additions & 14 deletions plugins/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"strings"

"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
Expand All @@ -44,8 +43,6 @@ const (
PluginVersion = "0.1.0"
)

const verbose bool = false

type MyPlugin struct {
plugins.BasePlugin
jparser fastjson.Parser
Expand All @@ -69,20 +66,10 @@ func (m *MyPlugin) Info() *plugins.Info {
}

func (m *MyPlugin) Init(config string) error {
if !verbose {
log.SetOutput(ioutil.Discard)
}

log.Printf("[%s] Init, config=%s\n", PluginName, config)
return nil
}

func (m *MyPlugin) Destroy() {
log.Printf("[%s] Destroy\n", PluginName)
}

func (m *MyPlugin) Fields() []sdk.FieldEntry {
log.Printf("[%s] Fields\n", PluginName)
return []sdk.FieldEntry{
{Type: "string", Name: "json.value", ArgRequired: true, Desc: "Extracts a value from a JSON-encoded input. Syntax is json.value[<json pointer>], where <json pointer> is a json pointer (see https://datatracker.ietf.org/doc/html/rfc6901)"},
{Type: "string", Name: "json.obj", Desc: "The full json message as a text string."},
Expand All @@ -94,7 +81,6 @@ func (m *MyPlugin) Fields() []sdk.FieldEntry {
}

func (m *MyPlugin) Extract(req sdk.ExtractRequest, evt sdk.EventReader) error {
log.Printf("[%s] Extract\n", PluginName)
reader := evt.Reader()

// As a very quick sanity check, only try to extract all if
Expand Down

0 comments on commit c1469ed

Please sign in to comment.