diff --git a/pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go b/pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go index 5cc25c80..5f23e8ac 100644 --- a/pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go @@ -1,5 +1,7 @@ package v1beta2 +import "github.com/replicatedhq/troubleshoot/pkg/multitype" + type CPUAnalyze struct { AnalyzeMeta `json:",inline" yaml:",inline"` Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"` @@ -85,17 +87,19 @@ type HostAnalyze struct { TCPPortStatus *TCPPortStatusAnalyze `json:"tcpPortStatus,omitempty" yaml:"tcpPortStatus,omitempty"` - HTTP *HTTPAnalyze `json:"http" yaml:"http"` + HTTP *HTTPAnalyze `json:"http,omitempty" yaml:"http,omitempty"` - Time *TimeAnalyze `json:"time" yaml:"time"` + Time *TimeAnalyze `json:"time,omitempty" yaml:"time,omitempty"` - BlockDevices *BlockDevicesAnalyze `json:"blockDevices" yaml:"blockDevices"` + BlockDevices *BlockDevicesAnalyze `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"` - TCPConnect *TCPConnectAnalyze `json:"tcpConnect" yaml:"tcpConnect"` + TCPConnect *TCPConnectAnalyze `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"` - IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces" yaml:"ipv4Interfaces"` + IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"` - FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance" yaml:"filesystemPerformance"` + FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"` - Certificate *CertificateAnalyze `json:"certificate" yaml:"certificate"` + Certificate *CertificateAnalyze `json:"certificate,omitempty" yaml:"certificate,omitempty"` + + Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"` } diff --git a/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go b/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go index b681b83a..0e20ba53 100644 --- a/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go @@ -101,8 +101,9 @@ type HostCollect struct { Time *HostTime `json:"time,omitempty" yaml:"time,omitempty"` BlockDevices *HostBlockDevices `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"` TCPConnect *TCPConnect `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"` - FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance" yaml:"filesystemPerformance"` - Certificate *Certificate `json:"certificate" yaml:"certificate" yaml:"certificate"` + FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"` + Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"` + Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"` } func (c *HostCollect) GetName() string { diff --git a/pkg/preflight/analyze.go b/pkg/preflight/analyze.go index 1157ab3b..c0d3dbae 100644 --- a/pkg/preflight/analyze.go +++ b/pkg/preflight/analyze.go @@ -3,10 +3,13 @@ package preflight import ( "fmt" "path/filepath" + "strconv" "strings" + "github.com/pkg/errors" analyze "github.com/replicatedhq/troubleshoot/pkg/analyze" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" + "github.com/replicatedhq/troubleshoot/pkg/multitype" ) // Analyze runs the analyze phase of preflight checks @@ -64,6 +67,9 @@ func doAnalyze(allCollectedData map[string][]byte, analyzers []*troubleshootv1be } for _, hostAnalyzer := range hostAnalyzers { + if excluded, _ := isExcluded(hostAnalyzer.Exclude); excluded { + continue + } analyzeResult, err := analyze.HostAnalyze(hostAnalyzer, getCollectedFileContents, getChildCollectedFileContents) if err != nil { analyzeResult = []*analyze.AnalyzeResult{ @@ -81,3 +87,20 @@ func doAnalyze(allCollectedData map[string][]byte, analyzers []*troubleshootv1be } return analyzeResults } + +func isExcluded(excludeVal multitype.BoolOrString) (bool, error) { + if excludeVal.Type == multitype.Bool { + return excludeVal.BoolVal, nil + } + + if excludeVal.StrVal == "" { + return false, nil + } + + parsed, err := strconv.ParseBool(excludeVal.StrVal) + if err != nil { + return false, errors.Wrap(err, "failed to parse bool string") + } + + return parsed, nil +} diff --git a/pkg/preflight/collect.go b/pkg/preflight/collect.go index 13f4bce0..5d7900cf 100644 --- a/pkg/preflight/collect.go +++ b/pkg/preflight/collect.go @@ -67,6 +67,9 @@ func CollectHost(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (Collec } for _, collector := range collectors { + if excluded, _ := isExcluded(collector.Collect.Exclude); excluded { + continue + } result, err := collector.RunCollectorSync() if err != nil { opts.ProgressChan <- errors.Errorf("failed to run collector: %s: %v\n", collector.GetDisplayName(), err)