Merge pull request #16 from crowdsecurity/lint_all_the_things
Linter fixes
This commit is contained in:
commit
bbb19539c2
23
.github/workflows/golangci-lint.yml
vendored
Normal file
23
.github/workflows/golangci-lint.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
name: golangci-lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v1
|
||||||
|
with:
|
||||||
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
version: v1.26
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
only-new-issues: true
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/outputs"
|
"github.com/crowdsecurity/crowdsec/pkg/outputs"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/sqlite"
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
|
|
||||||
"github.com/denisbrodbeck/machineid"
|
"github.com/denisbrodbeck/machineid"
|
||||||
|
@ -28,13 +27,10 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
apiConfigFile = "api.yaml"
|
apiConfigFile = "api.yaml"
|
||||||
|
userID string // for flag parsing
|
||||||
|
outputCTX *outputs.Output
|
||||||
)
|
)
|
||||||
|
|
||||||
var userID string // for flag parsing
|
|
||||||
var dbctx *sqlite.Context
|
|
||||||
|
|
||||||
var outputCTX *outputs.Output
|
|
||||||
|
|
||||||
func dumpCredentials() error {
|
func dumpCredentials() error {
|
||||||
if config.output == "json" {
|
if config.output == "json" {
|
||||||
credsYaml, err := json.Marshal(&outputCTX.API.Creds)
|
credsYaml, err := json.Marshal(&outputCTX.API.Creds)
|
||||||
|
@ -189,7 +185,6 @@ cscli api credentials # Display your API credentials
|
||||||
}
|
}
|
||||||
fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User)
|
fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User)
|
||||||
fmt.Printf("password: %s\n", outputCTX.API.Creds.Password)
|
fmt.Printf("password: %s\n", outputCTX.API.Creds.Password)
|
||||||
return
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +201,6 @@ cscli api credentials # Display your API credentials
|
||||||
if err := outputCTX.API.Enroll(userID); err != nil {
|
if err := outputCTX.API.Enroll(userID); err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
return
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +221,6 @@ cscli api credentials # Display your API credentials
|
||||||
}
|
}
|
||||||
fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User)
|
fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User)
|
||||||
fmt.Printf("password: %s\n", outputCTX.API.Creds.Password)
|
fmt.Printf("password: %s\n", outputCTX.API.Creds.Password)
|
||||||
return
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +238,6 @@ cscli api credentials # Display your API credentials
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
return
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,13 +251,14 @@ cscli api credentials # Display your API credentials
|
||||||
if err := dumpCredentials(); err != nil {
|
if err := dumpCredentials(); err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
return
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdAPI.AddCommand(cmdAPICreds)
|
cmdAPI.AddCommand(cmdAPICreds)
|
||||||
cmdAPIEnroll.Flags().StringVarP(&userID, "user", "u", "", "User ID (required)")
|
cmdAPIEnroll.Flags().StringVarP(&userID, "user", "u", "", "User ID (required)")
|
||||||
cmdAPIEnroll.MarkFlagRequired("user")
|
if err := cmdAPIEnroll.MarkFlagRequired("user"); err != nil {
|
||||||
|
log.Errorf("'user' flag : %s", err)
|
||||||
|
}
|
||||||
cmdAPI.AddCommand(cmdAPIEnroll)
|
cmdAPI.AddCommand(cmdAPIEnroll)
|
||||||
cmdAPI.AddCommand(cmdAPIResetPassword)
|
cmdAPI.AddCommand(cmdAPIResetPassword)
|
||||||
cmdAPI.AddCommand(cmdAPIRegister)
|
cmdAPI.AddCommand(cmdAPIRegister)
|
||||||
|
|
|
@ -164,15 +164,6 @@ func BanAdd(target string, duration string, reason string, action string) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func banFlush() error {
|
|
||||||
allBa := types.BanApplication{}
|
|
||||||
records := dbctx.Db.Delete(&allBa)
|
|
||||||
if records.Error != nil {
|
|
||||||
return records.Error
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBanCmds() *cobra.Command {
|
func NewBanCmds() *cobra.Command {
|
||||||
/*TODO : add a remediation type*/
|
/*TODO : add a remediation type*/
|
||||||
var cmdBan = &cobra.Command{
|
var cmdBan = &cobra.Command{
|
||||||
|
|
|
@ -16,10 +16,8 @@ import (
|
||||||
/*CliCfg is the cli configuration structure, might be unexported*/
|
/*CliCfg is the cli configuration structure, might be unexported*/
|
||||||
type cliConfig struct {
|
type cliConfig struct {
|
||||||
configured bool
|
configured bool
|
||||||
simulation bool /*are we in simulation mode*/
|
configFolder string `yaml:"cliconfig,omitempty"` /*overload ~/.cscli/*/
|
||||||
configFolder string `yaml:"cliconfig,omitempty"` /*overload ~/.cscli/*/
|
output string /*output is human, json*/
|
||||||
output string /*output is human, json*/
|
|
||||||
logLevel log.Level /*debug,info,warning,error*/
|
|
||||||
hubFolder string
|
hubFolder string
|
||||||
InstallFolder string `yaml:"installdir"` /*/etc/crowdsec/*/
|
InstallFolder string `yaml:"installdir"` /*/etc/crowdsec/*/
|
||||||
BackendPluginFolder string `yaml:"backend"`
|
BackendPluginFolder string `yaml:"backend"`
|
||||||
|
|
|
@ -128,7 +128,7 @@ func downloadMetabaseDB(force bool) error {
|
||||||
metabaseDBSubpath := path.Join(metabaseDbPath, "metabase.db")
|
metabaseDBSubpath := path.Join(metabaseDbPath, "metabase.db")
|
||||||
|
|
||||||
_, err := os.Stat(metabaseDBSubpath)
|
_, err := os.Stat(metabaseDBSubpath)
|
||||||
if err == nil && force == false {
|
if err == nil && !force {
|
||||||
log.Printf("%s exists, skip.", metabaseDBSubpath)
|
log.Printf("%s exists, skip.", metabaseDBSubpath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,23 +41,6 @@ func InstallItem(name string, obtype string) {
|
||||||
/*iterate of pkg index data*/
|
/*iterate of pkg index data*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallScenario(name string) {
|
|
||||||
InstallItem(name, cwhub.SCENARIOS)
|
|
||||||
}
|
|
||||||
|
|
||||||
func InstallCollection(name string) {
|
|
||||||
InstallItem(name, cwhub.COLLECTIONS)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func InstallParser(name string) {
|
|
||||||
InstallItem(name, cwhub.PARSERS)
|
|
||||||
}
|
|
||||||
|
|
||||||
func InstallPostoverflow(name string) {
|
|
||||||
InstallItem(name, cwhub.PARSERS_OVFLW)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewInstallCmd() *cobra.Command {
|
func NewInstallCmd() *cobra.Command {
|
||||||
/* ---- INSTALL COMMAND */
|
/* ---- INSTALL COMMAND */
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,9 @@ API interaction:
|
||||||
Args: cobra.ExactArgs(0),
|
Args: cobra.ExactArgs(0),
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
doc.GenMarkdownTree(rootCmd, "./doc/")
|
if err := doc.GenMarkdownTree(rootCmd, "./doc/"); err != nil {
|
||||||
|
log.Fatalf("Failed to generate cobra doc")
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
rootCmd.AddCommand(cmdDocGen)
|
rootCmd.AddCommand(cmdDocGen)
|
||||||
|
@ -135,5 +137,7 @@ API interaction:
|
||||||
rootCmd.AddCommand(NewDashboardCmd())
|
rootCmd.AddCommand(NewDashboardCmd())
|
||||||
rootCmd.AddCommand(NewInspectCmd())
|
rootCmd.AddCommand(NewInspectCmd())
|
||||||
|
|
||||||
rootCmd.Execute()
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
log.Fatalf("While executing root command : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,9 @@ func UpgradeConfig(ttype string, name string) {
|
||||||
}
|
}
|
||||||
cwhub.HubIdx[ttype][v.Name] = v
|
cwhub.HubIdx[ttype][v.Name] = v
|
||||||
}
|
}
|
||||||
if found == false {
|
if !found {
|
||||||
log.Errorf("Didn't find %s", name)
|
log.Errorf("Didn't find %s", name)
|
||||||
} else if updated == 0 && found == true {
|
} else if updated == 0 && found {
|
||||||
log.Errorf("Nothing to update")
|
log.Errorf("Nothing to update")
|
||||||
} else if updated != 0 {
|
} else if updated != 0 {
|
||||||
log.Infof("Upgraded %d items", updated)
|
log.Infof("Upgraded %d items", updated)
|
||||||
|
@ -93,14 +93,14 @@ cscli upgrade --force # Overwrite tainted configuration
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if upgrade_all == false && len(args) < 2 {
|
if !upgrade_all && len(args) < 2 {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := cwhub.GetHubIdx(); err != nil {
|
if err := cwhub.GetHubIdx(); err != nil {
|
||||||
log.Fatalf("Failed to get Hub index : %v", err)
|
log.Fatalf("Failed to get Hub index : %v", err)
|
||||||
}
|
}
|
||||||
if upgrade_all == true && len(args) == 0 {
|
if upgrade_all && len(args) == 0 {
|
||||||
log.Warningf("Upgrade all : parsers, scenarios, collections.")
|
log.Warningf("Upgrade all : parsers, scenarios, collections.")
|
||||||
UpgradeConfig(cwhub.PARSERS, "")
|
UpgradeConfig(cwhub.PARSERS, "")
|
||||||
UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
||||||
|
@ -127,7 +127,7 @@ cscli upgrade --force # Overwrite tainted configuration
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
UpgradeConfig(cwhub.PARSERS, args[0])
|
UpgradeConfig(cwhub.PARSERS, args[0])
|
||||||
//UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
//UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
||||||
} else if upgrade_all == true {
|
} else if upgrade_all {
|
||||||
UpgradeConfig(cwhub.PARSERS, "")
|
UpgradeConfig(cwhub.PARSERS, "")
|
||||||
} else {
|
} else {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
|
@ -148,7 +148,7 @@ cscli upgrade --force # Overwrite tainted configuration
|
||||||
}
|
}
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
UpgradeConfig(cwhub.SCENARIOS, args[0])
|
UpgradeConfig(cwhub.SCENARIOS, args[0])
|
||||||
} else if upgrade_all == true {
|
} else if upgrade_all {
|
||||||
UpgradeConfig(cwhub.SCENARIOS, "")
|
UpgradeConfig(cwhub.SCENARIOS, "")
|
||||||
} else {
|
} else {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
|
@ -170,7 +170,7 @@ cscli upgrade --force # Overwrite tainted configuration
|
||||||
}
|
}
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
UpgradeConfig(cwhub.COLLECTIONS, args[0])
|
UpgradeConfig(cwhub.COLLECTIONS, args[0])
|
||||||
} else if upgrade_all == true {
|
} else if upgrade_all {
|
||||||
UpgradeConfig(cwhub.COLLECTIONS, "")
|
UpgradeConfig(cwhub.COLLECTIONS, "")
|
||||||
} else {
|
} else {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
|
@ -193,7 +193,7 @@ cscli upgrade --force # Overwrite tainted configuration
|
||||||
}
|
}
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
UpgradeConfig(cwhub.PARSERS_OVFLW, args[0])
|
UpgradeConfig(cwhub.PARSERS_OVFLW, args[0])
|
||||||
} else if upgrade_all == true {
|
} else if upgrade_all {
|
||||||
UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
||||||
} else {
|
} else {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition"
|
"github.com/crowdsecurity/crowdsec/pkg/acquisition"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ func loadAcquisition() (*acquisition.FileAcquisCtx, error) {
|
||||||
if acquisitionCTX == nil {
|
if acquisitionCTX == nil {
|
||||||
return nil, fmt.Errorf("no inputs to process")
|
return nil, fmt.Errorf("no inputs to process")
|
||||||
}
|
}
|
||||||
if cConfig.Profiling == true {
|
if cConfig.Profiling {
|
||||||
acquisitionCTX.Profiling = true
|
acquisitionCTX.Profiling = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ func main() {
|
||||||
|
|
||||||
log.Infof("Crowdwatch %s", cwversion.VersionStr())
|
log.Infof("Crowdwatch %s", cwversion.VersionStr())
|
||||||
|
|
||||||
if cConfig.Prometheus == true {
|
if cConfig.Prometheus {
|
||||||
registerPrometheus()
|
registerPrometheus()
|
||||||
cConfig.Profiling = true
|
cConfig.Profiling = true
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*enable profiling*/
|
/*enable profiling*/
|
||||||
if cConfig.Profiling == true {
|
if cConfig.Profiling {
|
||||||
go runTachymeter(cConfig.HTTPListen)
|
go runTachymeter(cConfig.HTTPListen)
|
||||||
parserCTX.Profiling = true
|
parserCTX.Profiling = true
|
||||||
postOverflowCTX.Profiling = true
|
postOverflowCTX.Profiling = true
|
||||||
|
@ -233,7 +233,7 @@ func main() {
|
||||||
log.Fatalf("unable to restore buckets : %s", err)
|
log.Fatalf("unable to restore buckets : %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cConfig.Profiling == true {
|
if cConfig.Profiling {
|
||||||
//force the profiling in all buckets
|
//force the profiling in all buckets
|
||||||
for holderIndex := range holders {
|
for holderIndex := range holders {
|
||||||
holders[holderIndex].Profiling = true
|
holders[holderIndex].Profiling = true
|
||||||
|
|
|
@ -10,9 +10,10 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ var globalBucketPourOk = prometheus.NewCounter(
|
||||||
|
|
||||||
func dumpMetrics() {
|
func dumpMetrics() {
|
||||||
|
|
||||||
if cConfig.DumpBuckets == true {
|
if cConfig.DumpBuckets {
|
||||||
log.Infof("!! Dumping buckets state")
|
log.Infof("!! Dumping buckets state")
|
||||||
if err := leaky.DumpBucketsStateAt("buckets_state.json", time.Now(), buckets); err != nil {
|
if err := leaky.DumpBucketsStateAt("buckets_state.json", time.Now(), buckets); err != nil {
|
||||||
log.Fatalf("Failed dumping bucket state : %s", err)
|
log.Fatalf("Failed dumping bucket state : %s", err)
|
||||||
|
@ -98,7 +99,9 @@ func dumpMetrics() {
|
||||||
log.Infof("Lines never poured : %d (%.2f%%)", linesPouredKO, float64(linesPouredKO)/float64(linesPouredOK)*100.0)
|
log.Infof("Lines never poured : %d (%.2f%%)", linesPouredKO, float64(linesPouredKO)/float64(linesPouredOK)*100.0)
|
||||||
}
|
}
|
||||||
log.Infof("Writting metrics dump to %s", cConfig.WorkingFolder+"/crowdsec.profile")
|
log.Infof("Writting metrics dump to %s", cConfig.WorkingFolder+"/crowdsec.profile")
|
||||||
prometheus.WriteToTextfile(cConfig.WorkingFolder+"/crowdsec.profile", prometheus.DefaultGatherer)
|
if err := prometheus.WriteToTextfile(cConfig.WorkingFolder+"/crowdsec.profile", prometheus.DefaultGatherer); err != nil {
|
||||||
|
log.Errorf("failed to write metrics to %s : %s", cConfig.WorkingFolder+"/crowdsec.profile", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ LOOP:
|
||||||
if cConfig.Profiling {
|
if cConfig.Profiling {
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
}
|
}
|
||||||
if event.Process == false {
|
if !event.Process {
|
||||||
if cConfig.Profiling {
|
if cConfig.Profiling {
|
||||||
atomic.AddUint64(&linesReadKO, 1)
|
atomic.AddUint64(&linesReadKO, 1)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ LOOP:
|
||||||
log.Errorf("failed parsing : %v\n", error)
|
log.Errorf("failed parsing : %v\n", error)
|
||||||
return errors.New("parsing failed :/")
|
return errors.New("parsing failed :/")
|
||||||
}
|
}
|
||||||
if parsed.Process == false {
|
if !parsed.Process {
|
||||||
if cConfig.Profiling {
|
if cConfig.Profiling {
|
||||||
globalParserHitsKo.With(prometheus.Labels{"source": event.Line.Src}).Inc()
|
globalParserHitsKo.With(prometheus.Labels{"source": event.Line.Src}).Inc()
|
||||||
atomic.AddUint64(&linesParsedKO, 1)
|
atomic.AddUint64(&linesParsedKO, 1)
|
||||||
|
@ -57,7 +57,7 @@ LOOP:
|
||||||
atomic.AddUint64(&linesParsedOK, 1)
|
atomic.AddUint64(&linesParsedOK, 1)
|
||||||
}
|
}
|
||||||
processCPT++
|
processCPT++
|
||||||
if parsed.Whitelisted == true {
|
if parsed.Whitelisted {
|
||||||
log.Debugf("event whitelisted, discard")
|
log.Debugf("event whitelisted, discard")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,9 @@ LOOP:
|
||||||
log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err)
|
log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err)
|
||||||
} else {
|
} else {
|
||||||
log.Warningf("Starting buckets garbage collection ...")
|
log.Warningf("Starting buckets garbage collection ...")
|
||||||
leaky.GarbageCollectBuckets(*z, buckets)
|
if err = leaky.GarbageCollectBuckets(*z, buckets); err != nil {
|
||||||
|
return fmt.Errorf("failed to start bucket GC : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +59,9 @@ LOOP:
|
||||||
if cConfig.Profiling {
|
if cConfig.Profiling {
|
||||||
bucketStat.AddTime(time.Since(start))
|
bucketStat.AddTime(time.Since(start))
|
||||||
}
|
}
|
||||||
lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime))
|
if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal item : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Infof("Sending signal Bucketify")
|
log.Infof("Sending signal Bucketify")
|
||||||
|
|
|
@ -69,7 +69,7 @@ func serveDaemon() error {
|
||||||
if d != nil {
|
if d != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer daemonCTX.Release()
|
defer daemonCTX.Release() //nolint:errcheck // won't bother checking this error in defer statement
|
||||||
err = daemon.ServeSignals()
|
err = daemon.ServeSignals()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("serveDaemon error : %s", err.Error())
|
return fmt.Errorf("serveDaemon error : %s", err.Error())
|
||||||
|
@ -117,7 +117,7 @@ func serveOneTimeRun(outputRunner outputs.Output) error {
|
||||||
|
|
||||||
func serve(outputRunner outputs.Output) error {
|
func serve(outputRunner outputs.Output) error {
|
||||||
var err error
|
var err error
|
||||||
if cConfig.Daemonize == true {
|
if cConfig.Daemonize {
|
||||||
if err = serveDaemon(); err != nil {
|
if err = serveDaemon(); err != nil {
|
||||||
return fmt.Errorf(err.Error())
|
return fmt.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ func AcquisStartReading(ctx *FileAcquisCtx, output chan types.Event, AcquisTomb
|
||||||
/* start one go routine reading for each file, and pushing to chan output */
|
/* start one go routine reading for each file, and pushing to chan output */
|
||||||
for idx, fctx := range ctx.Files {
|
for idx, fctx := range ctx.Files {
|
||||||
log.Printf("starting reader file %d/%d : %s", idx, len(ctx.Files), fctx.Filename)
|
log.Printf("starting reader file %d/%d : %s", idx, len(ctx.Files), fctx.Filename)
|
||||||
if ctx.Profiling == true {
|
if ctx.Profiling {
|
||||||
fctx.Profiling = true
|
fctx.Profiling = true
|
||||||
}
|
}
|
||||||
fctx := fctx
|
fctx := fctx
|
||||||
|
@ -190,7 +190,6 @@ func AcquisStartReading(ctx *FileAcquisCtx, output chan types.Event, AcquisTomb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("Started %d routines for polling/read", len(ctx.Files))
|
log.Printf("Started %d routines for polling/read", len(ctx.Files))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*A tail-mode file reader (tail) */
|
/*A tail-mode file reader (tail) */
|
||||||
|
@ -227,7 +226,7 @@ LOOP:
|
||||||
if line.Text == "" { //skip empty lines
|
if line.Text == "" { //skip empty lines
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ctx.Profiling == true {
|
if ctx.Profiling {
|
||||||
ReaderHits.With(prometheus.Labels{"source": ctx.Filename}).Inc()
|
ReaderHits.With(prometheus.Labels{"source": ctx.Filename}).Inc()
|
||||||
}
|
}
|
||||||
l.Raw = line.Text
|
l.Raw = line.Text
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (c *Crowdwatch) GetOPT() error {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *printVersion == true {
|
if *printVersion {
|
||||||
cwversion.Show()
|
cwversion.Show()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (c *Crowdwatch) GetOPT() error {
|
||||||
if *AcquisitionFile != "" {
|
if *AcquisitionFile != "" {
|
||||||
c.AcquisitionFile = *AcquisitionFile
|
c.AcquisitionFile = *AcquisitionFile
|
||||||
}
|
}
|
||||||
if *dumpMode == true {
|
if *dumpMode {
|
||||||
c.DumpBuckets = true
|
c.DumpBuckets = true
|
||||||
}
|
}
|
||||||
if *prometheus {
|
if *prometheus {
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (ctx *ApiCtx) Init(cfg string, profile string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//start the background go-routine
|
//start the background go-routine
|
||||||
go ctx.pushLoop()
|
go ctx.pushLoop() //nolint:errcheck // runs into the background, we can't check error with chan or such
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if it's not a symlink and not in hub, it's a local file, don't bother
|
//if it's not a symlink and not in hub, it's a local file, don't bother
|
||||||
if local == true && inhub == false {
|
if local && !inhub {
|
||||||
log.Debugf("%s is a local file, skip", path)
|
log.Debugf("%s is a local file, skip", path)
|
||||||
skippedLocal++
|
skippedLocal++
|
||||||
// log.Printf("local scenario, skip.")
|
// log.Printf("local scenario, skip.")
|
||||||
|
@ -252,8 +252,7 @@ func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
/*we got an exact match, update struct*/
|
/*we got an exact match, update struct*/
|
||||||
// log.Printf("got exact match")
|
if !inhub {
|
||||||
if inhub == false {
|
|
||||||
log.Debugf("found exact match for %s, version is %s, latest is %s", v.Name, version, v.Version)
|
log.Debugf("found exact match for %s, version is %s, latest is %s", v.Name, version, v.Version)
|
||||||
v.LocalPath = path
|
v.LocalPath = path
|
||||||
v.LocalVersion = version
|
v.LocalVersion = version
|
||||||
|
@ -275,11 +274,11 @@ func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match == false {
|
if !match {
|
||||||
log.Debugf("got tainted match for %s : %s", v.Name, path)
|
log.Debugf("got tainted match for %s : %s", v.Name, path)
|
||||||
skippedTainted += 1
|
skippedTainted += 1
|
||||||
//the file and the stage is right, but the hash is wrong, it has been tainted by user
|
//the file and the stage is right, but the hash is wrong, it has been tainted by user
|
||||||
if inhub == false {
|
if !inhub {
|
||||||
v.LocalPath = path
|
v.LocalPath = path
|
||||||
v.Installed = true
|
v.Installed = true
|
||||||
}
|
}
|
||||||
|
@ -321,13 +320,13 @@ func CollecDepsCheck(v *Item) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//propagate the state of sub-items to set
|
//propagate the state of sub-items to set
|
||||||
if val.Tainted == true {
|
if val.Tainted {
|
||||||
v.Tainted = true
|
v.Tainted = true
|
||||||
return fmt.Errorf("tainted %s %s, tainted.", ptrtype, p)
|
return fmt.Errorf("tainted %s %s, tainted.", ptrtype, p)
|
||||||
} else if val.Installed == false && v.Installed == true {
|
} else if !val.Installed && v.Installed {
|
||||||
v.Tainted = true
|
v.Tainted = true
|
||||||
return fmt.Errorf("missing %s %s, tainted.", ptrtype, p)
|
return fmt.Errorf("missing %s %s, tainted.", ptrtype, p)
|
||||||
} else if val.UpToDate == false {
|
} else if !val.UpToDate {
|
||||||
v.UpToDate = false
|
v.UpToDate = false
|
||||||
return fmt.Errorf("outdated %s %s", ptrtype, p)
|
return fmt.Errorf("outdated %s %s", ptrtype, p)
|
||||||
}
|
}
|
||||||
|
@ -553,14 +552,14 @@ func DisableItem(target Item, tdir string, hdir string, purge bool) (Item, error
|
||||||
func EnableItem(target Item, tdir string, hdir string) (Item, error) {
|
func EnableItem(target Item, tdir string, hdir string) (Item, error) {
|
||||||
parent_dir := filepath.Clean(tdir + "/" + target.Type + "/" + target.Stage + "/")
|
parent_dir := filepath.Clean(tdir + "/" + target.Type + "/" + target.Stage + "/")
|
||||||
/*create directories if needed*/
|
/*create directories if needed*/
|
||||||
if target.Installed == true {
|
if target.Installed {
|
||||||
if target.Tainted == true {
|
if target.Tainted {
|
||||||
return target, fmt.Errorf("%s is tainted, won't enable unless --force", target.Name)
|
return target, fmt.Errorf("%s is tainted, won't enable unless --force", target.Name)
|
||||||
}
|
}
|
||||||
if target.Local == true {
|
if target.Local {
|
||||||
return target, fmt.Errorf("%s is local, won't enable", target.Name)
|
return target, fmt.Errorf("%s is local, won't enable", target.Name)
|
||||||
}
|
}
|
||||||
if target.UpToDate == true {
|
if target.UpToDate {
|
||||||
log.Debugf("%s is installed and up-to-date, skip.", target.Name)
|
log.Debugf("%s is installed and up-to-date, skip.", target.Name)
|
||||||
return target, nil
|
return target, nil
|
||||||
}
|
}
|
||||||
|
@ -690,7 +689,9 @@ func DownloadItem(target Item, tdir string, overwrite bool) (Item, error) {
|
||||||
return target, err
|
return target, err
|
||||||
}
|
}
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(body))
|
if _, err := h.Write([]byte(body)); err != nil {
|
||||||
|
return target, fmt.Errorf("%s : failed to write : %s", target.Name, err)
|
||||||
|
}
|
||||||
meow := fmt.Sprintf("%x", h.Sum(nil))
|
meow := fmt.Sprintf("%x", h.Sum(nil))
|
||||||
if meow != target.Versions[target.Version].Digest {
|
if meow != target.Versions[target.Version].Digest {
|
||||||
log.Errorf("Downloaded version doesn't match index, please 'hub update'")
|
log.Errorf("Downloaded version doesn't match index, please 'hub update'")
|
||||||
|
@ -737,7 +738,7 @@ func ItemStatus(v Item) (string, bool, bool, bool) {
|
||||||
var Ok, Warning, Managed bool
|
var Ok, Warning, Managed bool
|
||||||
var strret string
|
var strret string
|
||||||
|
|
||||||
if v.Installed == false {
|
if !v.Installed {
|
||||||
strret = "disabled"
|
strret = "disabled"
|
||||||
Ok = false
|
Ok = false
|
||||||
} else {
|
} else {
|
||||||
|
@ -745,7 +746,7 @@ func ItemStatus(v Item) (string, bool, bool, bool) {
|
||||||
strret = "enabled"
|
strret = "enabled"
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Local == true {
|
if v.Local {
|
||||||
Managed = false
|
Managed = false
|
||||||
strret += ",local"
|
strret += ",local"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -134,7 +134,9 @@ func (b *BackendManager) DeleteAll() error {
|
||||||
// Insert the signal for the plugin specified in the config["plugin"] parameter
|
// Insert the signal for the plugin specified in the config["plugin"] parameter
|
||||||
func (b *BackendManager) InsertOnePlugin(sig types.SignalOccurence, pluginName string) error {
|
func (b *BackendManager) InsertOnePlugin(sig types.SignalOccurence, pluginName string) error {
|
||||||
if val, ok := b.backendPlugins[pluginName]; ok {
|
if val, ok := b.backendPlugins[pluginName]; ok {
|
||||||
val.funcs.Insert(sig)
|
if err := val.funcs.Insert(sig); err != nil {
|
||||||
|
return fmt.Errorf("failed to load %s : %s", pluginName, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("plugin '%s' not loaded", pluginName)
|
return fmt.Errorf("plugin '%s' not loaded", pluginName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ func FromFactory(g BucketFactory) *Leaky {
|
||||||
} else {
|
} else {
|
||||||
limiter = rate.NewLimiter(rate.Every(g.leakspeed), g.Capacity)
|
limiter = rate.NewLimiter(rate.Every(g.leakspeed), g.Capacity)
|
||||||
}
|
}
|
||||||
if g.Profiling == true {
|
if g.Profiling {
|
||||||
BucketsInstanciation.With(prometheus.Labels{"name": g.Name}).Inc()
|
BucketsInstanciation.With(prometheus.Labels{"name": g.Name}).Inc()
|
||||||
}
|
}
|
||||||
//create the leaky bucket per se
|
//create the leaky bucket per se
|
||||||
|
@ -208,7 +208,7 @@ func LeakRoutine(l *Leaky) {
|
||||||
l.logger.Tracef("Pour event: %s", spew.Sdump(msg))
|
l.logger.Tracef("Pour event: %s", spew.Sdump(msg))
|
||||||
l.logger.Debugf("Pouring event.")
|
l.logger.Debugf("Pouring event.")
|
||||||
|
|
||||||
if l.Profiling == true {
|
if l.Profiling {
|
||||||
BucketsPour.With(prometheus.Labels{"name": l.Name, "source": msg.Line.Src}).Inc()
|
BucketsPour.With(prometheus.Labels{"name": l.Name, "source": msg.Line.Src}).Inc()
|
||||||
}
|
}
|
||||||
l.Pour(l, msg) // glue for now
|
l.Pour(l, msg) // glue for now
|
||||||
|
@ -236,7 +236,7 @@ func LeakRoutine(l *Leaky) {
|
||||||
l.logger.Tracef("Overflow event: %s", spew.Sdump(types.Event{Overflow: sig}))
|
l.logger.Tracef("Overflow event: %s", spew.Sdump(types.Event{Overflow: sig}))
|
||||||
mt, _ := l.Ovflw_ts.MarshalText()
|
mt, _ := l.Ovflw_ts.MarshalText()
|
||||||
l.logger.Tracef("overflow time : %s", mt)
|
l.logger.Tracef("overflow time : %s", mt)
|
||||||
if l.Profiling == true {
|
if l.Profiling {
|
||||||
BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc()
|
BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc()
|
||||||
}
|
}
|
||||||
l.AllOut <- types.Event{Overflow: sig, Type: types.OVFLW, MarshaledTime: string(mt)}
|
l.AllOut <- types.Event{Overflow: sig, Type: types.OVFLW, MarshaledTime: string(mt)}
|
||||||
|
@ -249,7 +249,7 @@ func LeakRoutine(l *Leaky) {
|
||||||
sig := types.SignalOccurence{MapKey: l.Mapkey}
|
sig := types.SignalOccurence{MapKey: l.Mapkey}
|
||||||
|
|
||||||
if l.timedOverflow {
|
if l.timedOverflow {
|
||||||
if l.Profiling == true {
|
if l.Profiling {
|
||||||
BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc()
|
BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc()
|
||||||
}
|
}
|
||||||
sig = FormatOverflow(l, ofw)
|
sig = FormatOverflow(l, ofw)
|
||||||
|
@ -405,9 +405,9 @@ func FormatOverflow(l *Leaky, queue *Queue) types.SignalOccurence {
|
||||||
am = fmt.Sprintf("%d IPs", len(sig.Sources))
|
am = fmt.Sprintf("%d IPs", len(sig.Sources))
|
||||||
} else if len(sig.Sources) == 1 {
|
} else if len(sig.Sources) == 1 {
|
||||||
if sig.Source != nil {
|
if sig.Source != nil {
|
||||||
am = fmt.Sprintf("%s", sig.Source.Ip.String())
|
am = sig.Source.Ip.String()
|
||||||
} else {
|
} else {
|
||||||
am = fmt.Sprintf("??")
|
am = "??"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
am = "UNKNOWN"
|
am = "UNKNOWN"
|
||||||
|
|
|
@ -22,11 +22,6 @@ type TestFile struct {
|
||||||
Results []types.Event `yaml:"results,omitempty"`
|
Results []types.Event `yaml:"results,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBucketStates() {
|
|
||||||
//same as a scenario, but load a bucket state first ?
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBucket(t *testing.T) {
|
func TestBucket(t *testing.T) {
|
||||||
|
|
||||||
var envSetting = os.Getenv("TEST_ONLY")
|
var envSetting = os.Getenv("TEST_ONLY")
|
||||||
|
@ -82,7 +77,10 @@ func testOneBucket(t *testing.T, dir string) error {
|
||||||
files = append(files, x.Filename)
|
files = append(files, x.Filename)
|
||||||
}
|
}
|
||||||
holders, response, err := LoadBuckets(files)
|
holders, response, err := LoadBuckets(files)
|
||||||
if testFile(t, dir+"/test.yaml", dir+"/in-buckets_state.json", holders, response) == false {
|
if err != nil {
|
||||||
|
t.Fatalf("failed loading bucket : %s", err)
|
||||||
|
}
|
||||||
|
if !testFile(t, dir+"/test.yaml", dir+"/in-buckets_state.json", holders, response) {
|
||||||
t.Fatalf("the test failed")
|
t.Fatalf("the test failed")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -218,7 +216,6 @@ POLL_AGAIN:
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Infof("(scenario) %s == %s", out.Overflow.Scenario, expected.Overflow.Scenario)
|
log.Infof("(scenario) %s == %s", out.Overflow.Scenario, expected.Overflow.Scenario)
|
||||||
valid = true
|
|
||||||
}
|
}
|
||||||
//Events_count
|
//Events_count
|
||||||
if out.Overflow.Events_count != expected.Overflow.Events_count {
|
if out.Overflow.Events_count != expected.Overflow.Events_count {
|
||||||
|
@ -227,7 +224,6 @@ POLL_AGAIN:
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Infof("(Events_count) %d == %d", out.Overflow.Events_count, expected.Overflow.Events_count)
|
log.Infof("(Events_count) %d == %d", out.Overflow.Events_count, expected.Overflow.Events_count)
|
||||||
valid = true
|
|
||||||
}
|
}
|
||||||
//Source_ip
|
//Source_ip
|
||||||
if out.Overflow.Source_ip != expected.Overflow.Source_ip {
|
if out.Overflow.Source_ip != expected.Overflow.Source_ip {
|
||||||
|
@ -236,12 +232,11 @@ POLL_AGAIN:
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Infof("(Source_ip) %s == %s", out.Overflow.Source_ip, expected.Overflow.Source_ip)
|
log.Infof("(Source_ip) %s == %s", out.Overflow.Source_ip, expected.Overflow.Source_ip)
|
||||||
valid = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//CheckFailed:
|
//CheckFailed:
|
||||||
|
|
||||||
if valid == true {
|
if valid {
|
||||||
log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx)
|
log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx)
|
||||||
//don't do this at home : delete current element from list and redo
|
//don't do this at home : delete current element from list and redo
|
||||||
results[eidx] = results[len(results)-1]
|
results[eidx] = results[len(results)-1]
|
||||||
|
@ -252,13 +247,11 @@ POLL_AGAIN:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if valid == false {
|
if !valid {
|
||||||
t.Fatalf("mismatching entries left")
|
t.Fatalf("mismatching entries left")
|
||||||
} else {
|
} else {
|
||||||
log.Warningf("entry valid at end of loop")
|
log.Warningf("entry valid at end of loop")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Errorf("failed test")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ func LoadBucketDir(dir string) ([]BucketFactory, chan types.Event, error) {
|
||||||
/* Init recursively process yaml files from a directory and loads them as BucketFactory */
|
/* Init recursively process yaml files from a directory and loads them as BucketFactory */
|
||||||
func LoadBucket(g *BucketFactory) error {
|
func LoadBucket(g *BucketFactory) error {
|
||||||
var err error
|
var err error
|
||||||
if g.Debug == true {
|
if g.Debug {
|
||||||
var clog = logrus.New()
|
var clog = logrus.New()
|
||||||
clog.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
clog.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
||||||
clog.SetLevel(log.DebugLevel)
|
clog.SetLevel(log.DebugLevel)
|
||||||
|
@ -326,12 +326,12 @@ func LoadBucketsState(file string, buckets *Buckets, holders []BucketFactory) er
|
||||||
tbucket.Total_count = v.Total_count
|
tbucket.Total_count = v.Total_count
|
||||||
buckets.Bucket_map.Store(k, tbucket)
|
buckets.Bucket_map.Store(k, tbucket)
|
||||||
go LeakRoutine(tbucket)
|
go LeakRoutine(tbucket)
|
||||||
_ = <-tbucket.Signal
|
<-tbucket.Signal
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found == false {
|
if !found {
|
||||||
log.Fatalf("Unable to find holder for bucket %s : %s", k, spew.Sdump(v))
|
log.Fatalf("Unable to find holder for bucket %s : %s", k, spew.Sdump(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ func PourItemToHolders(parsed types.Event, holders []BucketFactory, buckets *Buc
|
||||||
go LeakRoutine(fresh_bucket)
|
go LeakRoutine(fresh_bucket)
|
||||||
log.Debugf("Created new bucket %s", buckey)
|
log.Debugf("Created new bucket %s", buckey)
|
||||||
//wait for signal to be opened
|
//wait for signal to be opened
|
||||||
_ = <-fresh_bucket.Signal
|
<-fresh_bucket.Signal
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (u *OverflowFilter) OnBucketOverflow(Bucket *BucketFactory) func(*Leaky, ty
|
||||||
return s, q
|
return s, q
|
||||||
}
|
}
|
||||||
/*filter returned false, event is blackholded*/
|
/*filter returned false, event is blackholded*/
|
||||||
if element == false {
|
if !element {
|
||||||
l.logger.Infof("Event is discard by overflow filter (%s)", u.Filter)
|
l.logger.Infof("Event is discard by overflow filter (%s)", u.Filter)
|
||||||
return types.SignalOccurence{
|
return types.SignalOccurence{
|
||||||
MapKey: l.Mapkey,
|
MapKey: l.Mapkey,
|
||||||
|
|
|
@ -35,11 +35,11 @@ func OvflwToOrder(sig types.SignalOccurence, prof types.Profile) (*types.BanOrde
|
||||||
var warn error
|
var warn error
|
||||||
|
|
||||||
//Identify remediation type
|
//Identify remediation type
|
||||||
if prof.Remediation.Ban == true {
|
if prof.Remediation.Ban {
|
||||||
ordr.MeasureType = "ban"
|
ordr.MeasureType = "ban"
|
||||||
} else if prof.Remediation.Slow == true {
|
} else if prof.Remediation.Slow {
|
||||||
ordr.MeasureType = "slow"
|
ordr.MeasureType = "slow"
|
||||||
} else if prof.Remediation.Captcha == true {
|
} else if prof.Remediation.Captcha {
|
||||||
ordr.MeasureType = "captcha"
|
ordr.MeasureType = "captcha"
|
||||||
} else {
|
} else {
|
||||||
/*if the profil has no remediation, no order */
|
/*if the profil has no remediation, no order */
|
||||||
|
@ -120,10 +120,10 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi
|
||||||
logger.Warningf("failed to run filter : %v", err)
|
logger.Warningf("failed to run filter : %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch output.(type) {
|
switch out := output.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
/* filter returned false, don't process Node */
|
/* filter returned false, don't process Node */
|
||||||
if output.(bool) == false {
|
if !out {
|
||||||
logger.Debugf("eval(FALSE) '%s'", profile.Filter)
|
logger.Debugf("eval(FALSE) '%s'", profile.Filter)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,9 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi
|
||||||
// if ApiPush is nil (not specified in profile configuration) we use global api config (from default.yaml)
|
// if ApiPush is nil (not specified in profile configuration) we use global api config (from default.yaml)
|
||||||
if profile.ApiPush == nil {
|
if profile.ApiPush == nil {
|
||||||
if o.API != nil { // if API is not nil, we can push
|
if o.API != nil { // if API is not nil, we can push
|
||||||
o.API.AppendSignal((sig))
|
if err = o.API.AppendSignal((sig)); err != nil {
|
||||||
|
return fmt.Errorf("failed to append signal : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, outputConfig := range profile.OutputConfigs {
|
for _, outputConfig := range profile.OutputConfigs {
|
||||||
|
@ -173,7 +175,9 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
o.bManager.InsertOnePlugin(sig, pluginName)
|
if err = o.bManager.InsertOnePlugin(sig, pluginName); err != nil {
|
||||||
|
return fmt.Errorf("failed to insert plugin %s : %s", pluginName, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (n *Node) validate(pctx *UnixParserCtx) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if method_found == false {
|
if !method_found {
|
||||||
return fmt.Errorf("the method '%s' doesn't exist", static.Method)
|
return fmt.Errorf("the method '%s' doesn't exist", static.Method)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,7 +108,7 @@ func (n *Node) validate(pctx *UnixParserCtx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
var NodeState bool = true
|
var NodeState bool
|
||||||
clog := n.logger
|
clog := n.logger
|
||||||
|
|
||||||
clog.Debugf("Event entering node")
|
clog.Debugf("Event entering node")
|
||||||
|
@ -120,11 +120,10 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
clog.Debugf("Event leaving node : ko")
|
clog.Debugf("Event leaving node : ko")
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
switch output.(type) {
|
switch out := output.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
/* filter returned false, don't process Node */
|
/* filter returned false, don't process Node */
|
||||||
if output.(bool) == false {
|
if !out {
|
||||||
NodeState = false
|
|
||||||
clog.Debugf("eval(FALSE) '%s'", n.Filter)
|
clog.Debugf("eval(FALSE) '%s'", n.Filter)
|
||||||
clog.Debugf("Event leaving node : ko")
|
clog.Debugf("Event leaving node : ko")
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -132,7 +131,6 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
default:
|
default:
|
||||||
clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output)
|
clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output)
|
||||||
clog.Debugf("Event leaving node : ko")
|
clog.Debugf("Event leaving node : ko")
|
||||||
NodeState = false
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
NodeState = true
|
NodeState = true
|
||||||
|
@ -142,7 +140,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
NodeState = true
|
NodeState = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Profiling == true && n.Name != "" {
|
if n.Profiling && n.Name != "" {
|
||||||
NodesHits.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
NodesHits.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
||||||
}
|
}
|
||||||
set := false
|
set := false
|
||||||
|
@ -185,17 +183,17 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
clog.Debugf("Event leaving node : ko")
|
clog.Debugf("Event leaving node : ko")
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
switch output.(type) {
|
switch out := output.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
/* filter returned false, don't process Node */
|
/* filter returned false, don't process Node */
|
||||||
if output.(bool) == true {
|
if out {
|
||||||
clog.Infof("Event is whitelisted by Expr !")
|
clog.Infof("Event is whitelisted by Expr !")
|
||||||
p.Whitelisted = true
|
p.Whitelisted = true
|
||||||
set = true
|
set = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if set == true {
|
if set {
|
||||||
p.WhiteListReason = n.Whitelist.Reason
|
p.WhiteListReason = n.Whitelist.Reason
|
||||||
/*huglily wipe the ban order if the event is whitelisted and it's an overflow */
|
/*huglily wipe the ban order if the event is whitelisted and it's an overflow */
|
||||||
if p.Type == types.OVFLW { /*don't do this at home kids */
|
if p.Type == types.OVFLW { /*don't do this at home kids */
|
||||||
|
@ -217,7 +215,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
|
clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
|
||||||
if ret == true {
|
if ret {
|
||||||
NodeState = true
|
NodeState = true
|
||||||
/* if chil is successful, stop processing */
|
/* if chil is successful, stop processing */
|
||||||
if n.OnSuccess == "next_stage" {
|
if n.OnSuccess == "next_stage" {
|
||||||
|
@ -280,15 +278,15 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//grok or leafs failed, don't process statics
|
//grok or leafs failed, don't process statics
|
||||||
if NodeState == false {
|
if !NodeState {
|
||||||
if n.Profiling == true && n.Name != "" {
|
if n.Profiling && n.Name != "" {
|
||||||
NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
||||||
}
|
}
|
||||||
clog.Debugf("Event leaving node : ko")
|
clog.Debugf("Event leaving node : ko")
|
||||||
return NodeState, nil
|
return NodeState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Profiling == true && n.Name != "" {
|
if n.Profiling && n.Name != "" {
|
||||||
NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
|
||||||
}
|
}
|
||||||
if len(n.Statics) > 0 {
|
if len(n.Statics) > 0 {
|
||||||
|
@ -302,7 +300,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
|
||||||
clog.Tracef("! No node statics")
|
clog.Tracef("! No node statics")
|
||||||
}
|
}
|
||||||
|
|
||||||
if NodeState == true {
|
if NodeState {
|
||||||
clog.Debugf("Event leaving node : ok")
|
clog.Debugf("Event leaving node : ok")
|
||||||
log.Tracef("node is successful, check strategy")
|
log.Tracef("node is successful, check strategy")
|
||||||
if n.OnSuccess == "next_stage" {
|
if n.OnSuccess == "next_stage" {
|
||||||
|
@ -336,7 +334,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
|
||||||
log.Debugf("compile, node is %s", n.Stage)
|
log.Debugf("compile, node is %s", n.Stage)
|
||||||
/* if the node has debugging enabled, create a specific logger with debug
|
/* if the node has debugging enabled, create a specific logger with debug
|
||||||
that will be used only for processing this node ;) */
|
that will be used only for processing this node ;) */
|
||||||
if n.Debug == true {
|
if n.Debug {
|
||||||
var clog = logrus.New()
|
var clog = logrus.New()
|
||||||
clog.SetLevel(log.DebugLevel)
|
clog.SetLevel(log.DebugLevel)
|
||||||
n.logger = clog.WithFields(log.Fields{
|
n.logger = clog.WithFields(log.Fields{
|
||||||
|
@ -399,7 +397,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
|
||||||
/* load grok statics */
|
/* load grok statics */
|
||||||
if len(n.Grok.Statics) > 0 {
|
if len(n.Grok.Statics) > 0 {
|
||||||
//compile expr statics if present
|
//compile expr statics if present
|
||||||
for idx, _ := range n.Grok.Statics {
|
for idx := range n.Grok.Statics {
|
||||||
if n.Grok.Statics[idx].ExpValue != "" {
|
if n.Grok.Statics[idx].ExpValue != "" {
|
||||||
n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
|
n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
|
||||||
expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
|
expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
|
||||||
|
@ -412,27 +410,24 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
|
||||||
}
|
}
|
||||||
/* compile leafs if present */
|
/* compile leafs if present */
|
||||||
if len(n.SuccessNodes) > 0 {
|
if len(n.SuccessNodes) > 0 {
|
||||||
for idx, _ := range n.SuccessNodes {
|
for idx := range n.SuccessNodes {
|
||||||
/*propagate debug/stats to child nodes*/
|
/*propagate debug/stats to child nodes*/
|
||||||
if n.SuccessNodes[idx].Debug == false && n.Debug == true {
|
if !n.SuccessNodes[idx].Debug && n.Debug {
|
||||||
n.SuccessNodes[idx].Debug = true
|
n.SuccessNodes[idx].Debug = true
|
||||||
}
|
}
|
||||||
if n.SuccessNodes[idx].Profiling == false && n.Profiling == true {
|
if !n.SuccessNodes[idx].Profiling && n.Profiling {
|
||||||
n.SuccessNodes[idx].Profiling = true
|
n.SuccessNodes[idx].Profiling = true
|
||||||
}
|
}
|
||||||
n.SuccessNodes[idx].Stage = n.Stage
|
n.SuccessNodes[idx].Stage = n.Stage
|
||||||
err = n.SuccessNodes[idx].compile(pctx)
|
err = n.SuccessNodes[idx].compile(pctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
//n.logger.Debugf("Leaf compilation suceeded: %v\n", n.SuccessNodes[idx])
|
|
||||||
}
|
}
|
||||||
//set child node to parent stage
|
|
||||||
}
|
}
|
||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
/* load statics if present */
|
/* load statics if present */
|
||||||
for idx, _ := range n.Statics {
|
for idx := range n.Statics {
|
||||||
if n.Statics[idx].ExpValue != "" {
|
if n.Statics[idx].ExpValue != "" {
|
||||||
n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
|
n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -468,7 +463,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
|
||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if valid == false {
|
if !valid {
|
||||||
/* node is empty, error force return */
|
/* node is empty, error force return */
|
||||||
n.logger.Infof("Node is empty: %s", spew.Sdump(n))
|
n.logger.Infof("Node is empty: %s", spew.Sdump(n))
|
||||||
n.Stage = ""
|
n.Stage = ""
|
||||||
|
|
|
@ -48,7 +48,7 @@ func testOneParser(t *testing.T, dir string) error {
|
||||||
var p UnixParser
|
var p UnixParser
|
||||||
var pctx *UnixParserCtx
|
var pctx *UnixParserCtx
|
||||||
var err error
|
var err error
|
||||||
var pnodes []Node = make([]Node, 0)
|
var pnodes []Node
|
||||||
|
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func testOneParser(t *testing.T, dir string) error {
|
||||||
//Init the enricher
|
//Init the enricher
|
||||||
pplugins, err := Loadplugin(datadir)
|
pplugins, err := Loadplugin(datadir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to load plugin geoip : %v", err)
|
return fmt.Errorf("failed to load plugin geoip : %v", err)
|
||||||
}
|
}
|
||||||
ECTX = append(ECTX, pplugins)
|
ECTX = append(ECTX, pplugins)
|
||||||
log.Debugf("Geoip ctx : %v", ECTX)
|
log.Debugf("Geoip ctx : %v", ECTX)
|
||||||
|
@ -92,7 +92,7 @@ func testOneParser(t *testing.T, dir string) error {
|
||||||
|
|
||||||
pnodes, err = LoadStages(parser_configs, pctx)
|
pnodes, err = LoadStages(parser_configs, pctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to load parser config : %s", err)
|
return fmt.Errorf("unable to load parser config : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TBD: Load post overflows
|
//TBD: Load post overflows
|
||||||
|
@ -238,7 +238,7 @@ func testFile(t *testing.T, file string, pctx UnixParserCtx, nodes []Node) bool
|
||||||
|
|
||||||
CheckFailed:
|
CheckFailed:
|
||||||
|
|
||||||
if valid == true {
|
if valid {
|
||||||
//log.Infof("Found result [%s], skip", spew.Sdump(tf.Results[ridx]))
|
//log.Infof("Found result [%s], skip", spew.Sdump(tf.Results[ridx]))
|
||||||
log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx)
|
log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx)
|
||||||
//don't do this at home : delete current element from list and redo
|
//don't do this at home : delete current element from list and redo
|
||||||
|
|
|
@ -39,10 +39,9 @@ func SetTargetByName(target string, value string, evt *types.Event) bool {
|
||||||
if evt == nil {
|
if evt == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//it's a hack, we do it for the user
|
//it's a hack, we do it for the user
|
||||||
if strings.HasPrefix(target, "evt.") {
|
target = strings.TrimPrefix(target, "evt.")
|
||||||
target = target[4:]
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("setting target %s to %s", target, value)
|
log.Debugf("setting target %s to %s", target, value)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -68,7 +67,6 @@ func SetTargetByName(target string, value string, evt *types.Event) bool {
|
||||||
/*if we're in a map and the field doesn't exist, the user wants to add it :) */
|
/*if we're in a map and the field doesn't exist, the user wants to add it :) */
|
||||||
if (tmp == reflect.Value{}) || tmp.IsZero() {
|
if (tmp == reflect.Value{}) || tmp.IsZero() {
|
||||||
log.Debugf("map entry is zero in '%s'", target)
|
log.Debugf("map entry is zero in '%s'", target)
|
||||||
//return false
|
|
||||||
}
|
}
|
||||||
iter.SetMapIndex(reflect.ValueOf(f), reflect.ValueOf(value))
|
iter.SetMapIndex(reflect.ValueOf(f), reflect.ValueOf(value))
|
||||||
return true
|
return true
|
||||||
|
@ -130,11 +128,11 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent
|
||||||
clog.Warningf("failed to run RunTimeValue : %v", err)
|
clog.Warningf("failed to run RunTimeValue : %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch output.(type) {
|
switch out := output.(type) {
|
||||||
case string:
|
case string:
|
||||||
value = output.(string)
|
value = out
|
||||||
case int:
|
case int:
|
||||||
value = strconv.Itoa(output.(int))
|
value = strconv.Itoa(out)
|
||||||
default:
|
default:
|
||||||
clog.Fatalf("unexpected return type for RunTimeValue : %T", output)
|
clog.Fatalf("unexpected return type for RunTimeValue : %T", output)
|
||||||
return errors.New("unexpected return type for RunTimeValue")
|
return errors.New("unexpected return type for RunTimeValue")
|
||||||
|
@ -170,7 +168,7 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent
|
||||||
clog.Warningf("method '%s' doesn't exist", static.Method)
|
clog.Warningf("method '%s' doesn't exist", static.Method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if processed == false {
|
if !processed {
|
||||||
clog.Warningf("method '%s' doesn't exist", static.Method)
|
clog.Warningf("method '%s' doesn't exist", static.Method)
|
||||||
}
|
}
|
||||||
} else if static.Parsed != "" {
|
} else if static.Parsed != "" {
|
||||||
|
@ -230,8 +228,8 @@ func stageidx(stage string, stages []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []Node) (types.Event, error) {
|
func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []Node) (types.Event, error) {
|
||||||
var event types.Event
|
var event types.Event = xp
|
||||||
event = xp
|
|
||||||
/* the stage is undefined, probably line is freshly acquired, set to first stage !*/
|
/* the stage is undefined, probably line is freshly acquired, set to first stage !*/
|
||||||
if event.Stage == "" && len(ctx.Stages) > 0 {
|
if event.Stage == "" && len(ctx.Stages) > 0 {
|
||||||
event.Stage = ctx.Stages[0]
|
event.Stage = ctx.Stages[0]
|
||||||
|
@ -278,7 +276,7 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
clog.Tracef("Processing node %d/%d -> %s", idx, len(nodes), node.rn)
|
clog.Tracef("Processing node %d/%d -> %s", idx, len(nodes), node.rn)
|
||||||
if ctx.Profiling == true {
|
if ctx.Profiling {
|
||||||
node.Profiling = true
|
node.Profiling = true
|
||||||
}
|
}
|
||||||
ret, err := node.process(&event, ctx)
|
ret, err := node.process(&event, ctx)
|
||||||
|
@ -286,10 +284,10 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N
|
||||||
clog.Fatalf("Error while processing node : %v", err)
|
clog.Fatalf("Error while processing node : %v", err)
|
||||||
}
|
}
|
||||||
clog.Tracef("node (%s) ret : %v", node.rn, ret)
|
clog.Tracef("node (%s) ret : %v", node.rn, ret)
|
||||||
if ret == true {
|
if ret {
|
||||||
isStageOK = true
|
isStageOK = true
|
||||||
}
|
}
|
||||||
if ret == true && node.OnSuccess == "next_stage" {
|
if ret && node.OnSuccess == "next_stage" {
|
||||||
clog.Debugf("node successful, stop end stage %s", stage)
|
clog.Debugf("node successful, stop end stage %s", stage)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -299,7 +297,7 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isStageOK == false {
|
if !isStageOK {
|
||||||
log.Debugf("Log didn't finish stage %s", event.Stage)
|
log.Debugf("Log didn't finish stage %s", event.Stage)
|
||||||
event.Process = false
|
event.Process = false
|
||||||
return event, nil
|
return event, nil
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
|
||||||
bancom["source"] = ba.MeasureSource
|
bancom["source"] = ba.MeasureSource
|
||||||
bancom["events_count"] = "0"
|
bancom["events_count"] = "0"
|
||||||
bancom["action"] = ba.MeasureType
|
bancom["action"] = ba.MeasureType
|
||||||
bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
|
bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
|
||||||
bancom["reason"] = ba.Reason
|
bancom["reason"] = ba.Reason
|
||||||
rets = append(rets, bancom)
|
rets = append(rets, bancom)
|
||||||
continue
|
continue
|
||||||
|
@ -134,7 +134,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
|
||||||
bancom["scenario"] = "?"
|
bancom["scenario"] = "?"
|
||||||
bancom["events_count"] = "0"
|
bancom["events_count"] = "0"
|
||||||
bancom["action"] = ba.MeasureType
|
bancom["action"] = ba.MeasureType
|
||||||
bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
|
bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
|
||||||
bancom["reason"] = ba.Reason
|
bancom["reason"] = ba.Reason
|
||||||
rets = append(rets, bancom)
|
rets = append(rets, bancom)
|
||||||
continue
|
continue
|
||||||
|
@ -155,7 +155,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
|
||||||
bancom["events_count"] = fmt.Sprintf("%d", evtCount)
|
bancom["events_count"] = fmt.Sprintf("%d", evtCount)
|
||||||
bancom["action"] = ba.MeasureType
|
bancom["action"] = ba.MeasureType
|
||||||
bancom["source"] = ba.MeasureSource
|
bancom["source"] = ba.MeasureSource
|
||||||
bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
|
bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
|
||||||
bancom["reason"] = so.Scenario
|
bancom["reason"] = so.Scenario
|
||||||
rets = append(rets, bancom)
|
rets = append(rets, bancom)
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,7 +400,7 @@ type wait struct {
|
||||||
func runWait(t *testing.T, lim *Limiter, w wait) {
|
func runWait(t *testing.T, lim *Limiter, w wait) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := lim.WaitN(w.ctx, w.n)
|
err := lim.WaitN(w.ctx, w.n)
|
||||||
delay := time.Now().Sub(start)
|
delay := time.Since(start)
|
||||||
if (w.nilErr && err != nil) || (!w.nilErr && err == nil) || w.delay != dFromDuration(delay) {
|
if (w.nilErr && err != nil) || (!w.nilErr && err == nil) || w.delay != dFromDuration(delay) {
|
||||||
errString := "<nil>"
|
errString := "<nil>"
|
||||||
if !w.nilErr {
|
if !w.nilErr {
|
||||||
|
@ -472,6 +472,8 @@ func BenchmarkWaitNNoDelay(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
lim.WaitN(ctx, 1)
|
if err := lim.WaitN(ctx, 1); err != nil {
|
||||||
|
b.Errorf("failed limiter : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:unused // pluginDB is the interface for sqlite output plugin
|
||||||
type pluginDB struct {
|
type pluginDB struct {
|
||||||
CTX *sqlite.Context
|
CTX *sqlite.Context
|
||||||
}
|
}
|
||||||
|
@ -28,7 +29,7 @@ func (p *pluginDB) Delete(target string) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
log.Debugf("deleted '%s' entry from database", nbDel)
|
log.Debugf("deleted '%d' entry from database", nbDel)
|
||||||
return nbDel, nil
|
return nbDel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ func (p *pluginDB) ReadAT(timeAT time.Time) ([]map[string]string, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:deadcode,unused // New is used by the plugin system
|
||||||
func New() interface{} {
|
func New() interface{} {
|
||||||
return &pluginDB{}
|
return &pluginDB{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue