Printing the actual test result of failed tests - when a flag is raised

fix #110
pull/282/head
Yoav Hizkiahou 5 years ago
parent c152088254
commit 3aa28c4c32

@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/aquasecurity/kube-bench/check"
"github.com/golang/glog"
@ -142,6 +143,10 @@ func prettyPrint(r *check.Controls, summary check.Summary) {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text))
for _, c := range g.Checks {
colorPrint(c.State, fmt.Sprintf("%s %s\n", c.ID, c.Text))
if includeTestOutput && c.State == check.FAIL && len(c.ActualValue) > 0 {
printRawOutput(c.ActualValue)
}
}
}
@ -240,3 +245,9 @@ func isMaster() bool {
}
return true
}
func printRawOutput(output string) {
for _, row := range strings.Split(output, "\n") {
fmt.Println(fmt.Sprintf("\t %s", row))
}
}

@ -47,6 +47,7 @@ var (
noSummary bool
noRemediations bool
filterOpts FilterOpts
includeTestOutput bool
)
// RootCmd represents the base command when called without any subcommands
@ -87,6 +88,7 @@ func init() {
RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL")
RootCmd.PersistentFlags().BoolVar(&filterOpts.Scored, "scored", true, "Run the scored CIS checks")
RootCmd.PersistentFlags().BoolVar(&filterOpts.Unscored, "unscored", true, "Run the unscored CIS checks")
RootCmd.PersistentFlags().BoolVar(&includeTestOutput, "include-test-output", false, "Prints the actual result when test fails")
RootCmd.PersistentFlags().StringVarP(
&filterOpts.CheckList,

Loading…
Cancel
Save