add --failures to explain feature : only display failed lines (#1048)
* add --failures to explain feature : only display failed lines * no error no problem
This commit is contained in:
parent
a4998913d8
commit
7362828a3b
3 changed files with 18 additions and 10 deletions
|
@ -17,7 +17,7 @@ func NewExplainCmd() *cobra.Command {
|
|||
var dsn string
|
||||
var logLine string
|
||||
var logType string
|
||||
var details bool
|
||||
var opts cstest.DumpOpts
|
||||
|
||||
var cmdExplain = &cobra.Command{
|
||||
Use: "explain",
|
||||
|
@ -96,16 +96,15 @@ cscli explain -dsn "file://myfile.log" --type nginx
|
|||
log.Fatalf("unable to load bucket dump result: %s", err)
|
||||
}
|
||||
|
||||
if err := cstest.DumpTree(*parserDump, *bucketStateDump, details); err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
}
|
||||
cstest.DumpTree(*parserDump, *bucketStateDump, opts)
|
||||
},
|
||||
}
|
||||
cmdExplain.PersistentFlags().StringVarP(&logFile, "file", "f", "", "Log file to test")
|
||||
cmdExplain.PersistentFlags().StringVarP(&dsn, "dsn", "d", "", "DSN to test")
|
||||
cmdExplain.PersistentFlags().StringVarP(&logLine, "log", "l", "", "Lgg line to test")
|
||||
cmdExplain.PersistentFlags().StringVarP(&logType, "type", "t", "", "Type of the acquisition to test")
|
||||
cmdExplain.PersistentFlags().BoolVarP(&details, "verbose", "v", false, "Display individual changes")
|
||||
cmdExplain.PersistentFlags().BoolVarP(&opts.Details, "verbose", "v", false, "Display individual changes")
|
||||
cmdExplain.PersistentFlags().BoolVar(&opts.SkipOk, "failures", false, "Only show failed lines")
|
||||
|
||||
return cmdExplain
|
||||
}
|
||||
|
|
|
@ -574,8 +574,8 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
|||
log.Fatalf("unable to load scenario result after run: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
cstest.DumpTree(*test.ParserAssert.TestData, *test.ScenarioAssert.PourData, false)
|
||||
opts := cstest.DumpOpts{}
|
||||
cstest.DumpTree(*test.ParserAssert.TestData, *test.ScenarioAssert.PourData, opts)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -271,7 +271,12 @@ func LoadParserDump(filepath string) (*ParserResults, error) {
|
|||
return &pdump, nil
|
||||
}
|
||||
|
||||
func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, details bool) error {
|
||||
type DumpOpts struct {
|
||||
Details bool
|
||||
SkipOk bool
|
||||
}
|
||||
|
||||
func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, opts DumpOpts) {
|
||||
//note : we can use line -> time as the unique identifier (of acquisition)
|
||||
|
||||
state := make(map[time.Time]map[string]map[string]ParserResult)
|
||||
|
@ -317,6 +322,11 @@ func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, details
|
|||
green := color.New(color.FgGreen).SprintFunc()
|
||||
//get each line
|
||||
for tstamp, rawstr := range assoc {
|
||||
if opts.SkipOk {
|
||||
if _, ok := state[tstamp]["buckets"]["OK"]; ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
fmt.Printf("line: %s\n", rawstr)
|
||||
skeys := make([]string, 0, len(state[tstamp]))
|
||||
for k := range state[tstamp] {
|
||||
|
@ -409,7 +419,7 @@ func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, details
|
|||
}
|
||||
if res {
|
||||
fmt.Printf("\t%s\t%s %s %s (%s)\n", presep, sep, emoji.GreenCircle, parser, changeStr)
|
||||
if details {
|
||||
if opts.Details {
|
||||
fmt.Print(detailsDisplay)
|
||||
}
|
||||
} else {
|
||||
|
@ -451,5 +461,4 @@ func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, details
|
|||
}
|
||||
fmt.Println()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue