Skip to content

Commit 73201c0

Browse files
authored
feat: Add regex host analyser (#1267)
* feat: Add regular expressions host anaylser This anaylser is the same as the in-cluster text anaylser. You pass in search expressions to find values in files collected in a bundle * additional test assertion to check analyser warn
1 parent 531edf4 commit 73201c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+612
-93
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ BUILDFLAGS = -tags "netgo containers_image_ostree_stub exclude_graphdriver_devic
3838
BUILDPATHS = ./pkg/... ./cmd/... ./internal/...
3939
TESTFLAGS ?= -v -coverprofile cover.out
4040

41-
all: test support-bundle preflight collect analyze
41+
.DEFAULT: all
42+
all: test build
4243

4344
.PHONY: ffi
4445
ffi: fmt vet

config/crds/troubleshoot.sh_analyzers.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,67 @@ spec:
24552455
required:
24562456
- outcomes
24572457
type: object
2458+
textAnalyze:
2459+
properties:
2460+
annotations:
2461+
additionalProperties:
2462+
type: string
2463+
type: object
2464+
checkName:
2465+
type: string
2466+
collectorName:
2467+
type: string
2468+
exclude:
2469+
type: BoolString
2470+
excludeFiles:
2471+
items:
2472+
type: string
2473+
type: array
2474+
fileName:
2475+
type: string
2476+
ignoreIfNoFiles:
2477+
type: boolean
2478+
outcomes:
2479+
items:
2480+
properties:
2481+
fail:
2482+
properties:
2483+
message:
2484+
type: string
2485+
uri:
2486+
type: string
2487+
when:
2488+
type: string
2489+
type: object
2490+
pass:
2491+
properties:
2492+
message:
2493+
type: string
2494+
uri:
2495+
type: string
2496+
when:
2497+
type: string
2498+
type: object
2499+
warn:
2500+
properties:
2501+
message:
2502+
type: string
2503+
uri:
2504+
type: string
2505+
when:
2506+
type: string
2507+
type: object
2508+
type: object
2509+
type: array
2510+
regex:
2511+
type: string
2512+
regexGroups:
2513+
type: string
2514+
strict:
2515+
type: BoolString
2516+
required:
2517+
- outcomes
2518+
type: object
24582519
time:
24592520
properties:
24602521
annotations:

config/crds/troubleshoot.sh_hostcollectors.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,67 @@ spec:
927927
required:
928928
- outcomes
929929
type: object
930+
textAnalyze:
931+
properties:
932+
annotations:
933+
additionalProperties:
934+
type: string
935+
type: object
936+
checkName:
937+
type: string
938+
collectorName:
939+
type: string
940+
exclude:
941+
type: BoolString
942+
excludeFiles:
943+
items:
944+
type: string
945+
type: array
946+
fileName:
947+
type: string
948+
ignoreIfNoFiles:
949+
type: boolean
950+
outcomes:
951+
items:
952+
properties:
953+
fail:
954+
properties:
955+
message:
956+
type: string
957+
uri:
958+
type: string
959+
when:
960+
type: string
961+
type: object
962+
pass:
963+
properties:
964+
message:
965+
type: string
966+
uri:
967+
type: string
968+
when:
969+
type: string
970+
type: object
971+
warn:
972+
properties:
973+
message:
974+
type: string
975+
uri:
976+
type: string
977+
when:
978+
type: string
979+
type: object
980+
type: object
981+
type: array
982+
regex:
983+
type: string
984+
regexGroups:
985+
type: string
986+
strict:
987+
type: BoolString
988+
required:
989+
- outcomes
990+
type: object
930991
time:
931992
properties:
932993
annotations:

config/crds/troubleshoot.sh_hostpreflights.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,67 @@ spec:
927927
required:
928928
- outcomes
929929
type: object
930+
textAnalyze:
931+
properties:
932+
annotations:
933+
additionalProperties:
934+
type: string
935+
type: object
936+
checkName:
937+
type: string
938+
collectorName:
939+
type: string
940+
exclude:
941+
type: BoolString
942+
excludeFiles:
943+
items:
944+
type: string
945+
type: array
946+
fileName:
947+
type: string
948+
ignoreIfNoFiles:
949+
type: boolean
950+
outcomes:
951+
items:
952+
properties:
953+
fail:
954+
properties:
955+
message:
956+
type: string
957+
uri:
958+
type: string
959+
when:
960+
type: string
961+
type: object
962+
pass:
963+
properties:
964+
message:
965+
type: string
966+
uri:
967+
type: string
968+
when:
969+
type: string
970+
type: object
971+
warn:
972+
properties:
973+
message:
974+
type: string
975+
uri:
976+
type: string
977+
when:
978+
type: string
979+
type: object
980+
type: object
981+
type: array
982+
regex:
983+
type: string
984+
regexGroups:
985+
type: string
986+
strict:
987+
type: BoolString
988+
required:
989+
- outcomes
990+
type: object
930991
time:
931992
properties:
932993
annotations:

config/crds/troubleshoot.sh_supportbundles.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11187,6 +11187,67 @@ spec:
1118711187
required:
1118811188
- outcomes
1118911189
type: object
11190+
textAnalyze:
11191+
properties:
11192+
annotations:
11193+
additionalProperties:
11194+
type: string
11195+
type: object
11196+
checkName:
11197+
type: string
11198+
collectorName:
11199+
type: string
11200+
exclude:
11201+
type: BoolString
11202+
excludeFiles:
11203+
items:
11204+
type: string
11205+
type: array
11206+
fileName:
11207+
type: string
11208+
ignoreIfNoFiles:
11209+
type: boolean
11210+
outcomes:
11211+
items:
11212+
properties:
11213+
fail:
11214+
properties:
11215+
message:
11216+
type: string
11217+
uri:
11218+
type: string
11219+
when:
11220+
type: string
11221+
type: object
11222+
pass:
11223+
properties:
11224+
message:
11225+
type: string
11226+
uri:
11227+
type: string
11228+
when:
11229+
type: string
11230+
type: object
11231+
warn:
11232+
properties:
11233+
message:
11234+
type: string
11235+
uri:
11236+
type: string
11237+
when:
11238+
type: string
11239+
type: object
11240+
type: object
11241+
type: array
11242+
regex:
11243+
type: string
11244+
regexGroups:
11245+
type: string
11246+
strict:
11247+
type: BoolString
11248+
required:
11249+
- outcomes
11250+
type: object
1119011251
time:
1119111252
properties:
1119211253
annotations:

pkg/analyze/analyzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func HostAnalyze(
7979
return nil
8080
}
8181

82-
result, err := analyzer.Analyze(getFile)
82+
result, err := analyzer.Analyze(getFile, findFiles)
8383
if err != nil {
8484
return NewAnalyzeResultError(analyzer, errors.Wrap(err, "analyze"))
8585
}

pkg/analyze/host_analyzer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubl
55
type HostAnalyzer interface {
66
Title() string
77
IsExcluded() (bool, error)
8-
Analyze(getFile func(string) ([]byte, error)) ([]*AnalyzeResult, error)
8+
Analyze(getFile func(string) ([]byte, error), findFiles getChildCollectedFileContents) ([]*AnalyzeResult, error)
99
}
1010

1111
func GetHostAnalyzer(analyzer *troubleshootv1beta2.HostAnalyze) (HostAnalyzer, bool) {
@@ -50,6 +50,8 @@ func GetHostAnalyzer(analyzer *troubleshootv1beta2.HostAnalyze) (HostAnalyzer, b
5050
return &AnalyzeHostServices{analyzer.HostServices}, true
5151
case analyzer.HostOS != nil:
5252
return &AnalyzeHostOS{analyzer.HostOS}, true
53+
case analyzer.TextAnalyze != nil:
54+
return &AnalyzeHostTextAnalyze{analyzer.TextAnalyze}, true
5355
default:
5456
return nil, false
5557
}

pkg/analyze/host_block_devices.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func (a *AnalyzeHostBlockDevices) IsExcluded() (bool, error) {
2424
return isExcluded(a.hostAnalyzer.Exclude)
2525
}
2626

27-
func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
27+
func (a *AnalyzeHostBlockDevices) Analyze(
28+
getCollectedFileContents func(string) ([]byte, error), findFiles getChildCollectedFileContents,
29+
) ([]*AnalyzeResult, error) {
2830
hostAnalyzer := a.hostAnalyzer
2931

3032
contents, err := getCollectedFileContents(collect.HostBlockDevicesPath)

pkg/analyze/host_block_devices_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestAnalyzeBlockDevices(t *testing.T) {
265265
return b, nil
266266
}
267267

268-
result, err := (&AnalyzeHostBlockDevices{test.hostAnalyzer}).Analyze(getCollectedFileContents)
268+
result, err := (&AnalyzeHostBlockDevices{test.hostAnalyzer}).Analyze(getCollectedFileContents, nil)
269269
if test.expectErr {
270270
req.Error(err)
271271
} else {

pkg/analyze/host_certificate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func (a *AnalyzeHostCertificate) IsExcluded() (bool, error) {
2020
return isExcluded(a.hostAnalyzer.Exclude)
2121
}
2222

23-
func (a *AnalyzeHostCertificate) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
23+
func (a *AnalyzeHostCertificate) Analyze(
24+
getCollectedFileContents func(string) ([]byte, error), findFiles getChildCollectedFileContents,
25+
) ([]*AnalyzeResult, error) {
2426
hostAnalyzer := a.hostAnalyzer
2527

2628
collectorName := hostAnalyzer.CollectorName

0 commit comments

Comments
 (0)