This commit is contained in:
bui 2021-04-28 14:51:58 +02:00
parent 4bc206d9cb
commit 013699c480
3 changed files with 45 additions and 35 deletions

2
go.mod
View file

@ -56,7 +56,7 @@ require (
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/ugorji/go/codec v1.2.3 // indirect
github.com/ugorji/go v1.2.3 // indirect
github.com/vjeantet/grok v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/mod v0.4.1

View file

@ -6,6 +6,7 @@ import (
"os"
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
file_acquisition "github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/file"
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/pkg/errors"
@ -62,39 +63,39 @@ cat mode will return once source has been exhausted.
type DataSource interface {
GetMetrics() []interface{} // Returns pointers to metrics that are managed by the module
Configure([]byte, *log.Entry) error // Configure the datasource
Mode() string // Get the mode (TAIL, CAT or SERVER)
GetMode() string // Get the mode (TAIL, CAT or SERVER)
SupportedModes() []string // Returns the mode supported by the datasource
OneShotAcquisition(chan types.Event, *tomb.Tomb) error // Start one shot acquisition(eg, cat a file)
LiveAcquisition(chan types.Event, *tomb.Tomb) error // Start live acquisition (eg, tail a file)
CanRun() bool // Whether the datasource can run or not (eg, journalctl on BSD is a non-sense)
}
type FileDataSource struct {
}
// type FileDataSource struct {
// }
func (f *FileDataSource) GetMetrics() []interface{} {
return nil
}
func (f *FileDataSource) Configure([]byte, *log.Entry) error {
return nil
}
func (f *FileDataSource) Mode() string {
return ""
}
func (f *FileDataSource) SupportedModes() []string {
return nil
}
func (f *FileDataSource) OneShotAcquisition(chan types.Event, *tomb.Tomb) error {
return nil
}
// func (f *FileDataSource) GetMetrics() []interface{} {
// return nil
// }
// func (f *FileDataSource) Configure([]byte, *log.Entry) error {
// return nil
// }
// func (f *FileDataSource) Mode() string {
// return ""
// }
// func (f *FileDataSource) SupportedModes() []string {
// return nil
// }
// func (f *FileDataSource) OneShotAcquisition(chan types.Event, *tomb.Tomb) error {
// return nil
// }
func (f *FileDataSource) LiveAcquisition(chan types.Event, *tomb.Tomb) error {
return nil
}
// func (f *FileDataSource) LiveAcquisition(chan types.Event, *tomb.Tomb) error {
// return nil
// }
func (f *FileDataSource) CanRun() bool {
return true
}
// func (f *FileDataSource) CanRun() bool {
// return true
// }
var AcquisitionSources = []struct {
name string
@ -102,7 +103,7 @@ var AcquisitionSources = []struct {
}{
{
name: "file",
iface: &FileDataSource{},
iface: &file_acquisition.FileSource{},
},
}
@ -181,7 +182,7 @@ func StartAcquisition(sources []DataSource, output chan types.Event, AcquisTomb
AcquisTomb.Go(func() error {
defer types.CatchPanic("crowdsec/acquis")
var err error
if subsrc.Mode() == configuration.TAIL_MODE {
if subsrc.GetMode() == configuration.TAIL_MODE {
err = subsrc.LiveAcquisition(output, AcquisTomb)
} else {
err = subsrc.OneShotAcquisition(output, AcquisTomb)

View file

@ -22,19 +22,20 @@ type FileConfiguration struct {
}
type FileSource struct {
CommonConfig configuration.DataSourceCommonCfg
configuration.DataSourceCommonCfg
FileConfig FileConfiguration
Mode string
tails []*tail.Tail
Files []string
}
func (f *FileSource) Configure(Config []byte) error {
func (f *FileSource) Configure(Config []byte, logger *log.Entry) error {
log.Warn("Configuring FileSource")
return nil
}
func (f *FileSource) Mode() string {
return f.CommonConfig.Mode
func (f *FileSource) GetMode() string {
return f.Mode
}
func (f *FileSource) SupportedModes() []string {
@ -52,6 +53,14 @@ func (f *FileSource) OneShotAcquisition(out chan types.Event, t *tomb.Tomb) erro
return nil
}
func (f *FileSource) GetMetrics() []interface{} {
return nil
}
func (f *FileSource) CanRun() bool {
return true
}
func (f *FileSource) LiveAcquisition(out chan types.Event, t *tomb.Tomb) error {
return nil
}
@ -93,7 +102,7 @@ func (f *FileSource) readFile(filename string, out chan types.Event, t *tomb.Tom
l.Raw = scanner.Text()
l.Time = time.Now()
l.Src = filename
l.Labels = f.CommonConfig.Labels
l.Labels = f.Labels
l.Process = true
// FIXME: How to interact with prom metrics ?
//ReaderHits.With(prometheus.Labels{"source": filename}).Inc()