Using a regular expression to analyze arbitrary data
The regex analyzer is used to run arbitrary regular expressions against text data collected into a bundle. You can use the regex analyzer with any text data collector, such as the
regexGroups must be set, but not both.
regex: (Optional) A regex pattern to test.
If the pattern matches the file, the outcome that has set
"true" is executed.
when expression is specified, the
pass outcome defaults to
regexGroups: (Optional) A regex pattern to match.
Matches from named capturing groups are available to
when expressions in outcomes.
fileName (Required) Path to the file in support bundle to analyze.
This can be an exact name, a prefix, or a file path pattern as defined by Go's
ignoreIfNoFiles (Optional) If no file matches, this analyzer produces a warn outcome by default. This flag can be set to
true to suppress the warning.
apiVersion: troubleshoot.sh/v1beta2 kind: SupportBundle metadata: name: example spec: hostCollectors: - run: collectorName: "localhost-ips" command: "sh" args: ["-c", "host localhost"] hostAnalyzers: - textAnalyze: checkName: Check if localhost resolves to 127.0.0.1 fileName: host-collectors/run-host/localhost-ips.txt regex: 'localhost has address 127.0.0.1' outcomes: - fail: when: "false" message: "'localhost' does not resolve to 127.0.0.1 ip address" - pass: when: "true" message: "'localhost' resolves to 127.0.0.1 ip address"
apiVersion: troubleshoot.sh/v1beta2 kind: SupportBundle metadata: name: ping spec: hostCollectors: - run: collectorName: "ping-google" command: "ping" args: ["-c", "5", "google.com"] hostAnalyzers: - textAnalyze: checkName: "run-ping" fileName: host-collectors/run-host/ping-google.txt regexGroups: '(?P<Transmitted>\d+) packets? transmitted, (?P<Received>\d+) packets? received, (?P<Loss>\d+)(\.\d+)?% packet loss' outcomes: - pass: when: "Loss < 5" message: Solid connection to google.com - fail: message: High packet loss