Multi-value regex parser feature addition #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've updated a few of the junos-parser yaml files, and added new ones (not necessarily relevant to this feature, just fyi).
Required files for the new feature are:
YAML syntax update
Added:
type
If the code sees a yaml file matching a regex method and a "type" equal to multi-value it knows to treat it as such. Required for feature.
match_count
This is the maximum number of times (Top N) you want to regex to match. Currently (probably) doesn't support output that contains fewer potential matches than this count. Example: You have an output where each line is similar (think TOP command output) and you want to grab the top 10 items, but only 9 line items total are in the output. This probably will return nothing because there are not matches. I haven't tried this yet.
key_index
This is the index number of the capture group that will serve as the key and name of the measurement. 1 is the lowest supported value. Take the following regex for example:
\s+(\w+)\s+(\w+)\s+(\w+)
There are 3 groups in this regex with the last group to the right being key_index = 3
Corresponding input we are looking through:
Hello World bar
Goodbye World foo
Output we would end up with after code parsing:
[ ('Hello', 'World'):{'key':'bar'}, ('Goodbye','World'):{'key':'foo'} ]
The key value is used for the name of the measurement and replaces the '$key' value in the yaml file.
Example yaml
parser:
regex-command: show\s+system\s+processes\s+extensive
matches:
-
type: multi-value
match_count: 5
method: regex
regex: \s_[0-9]+\s+\w+\s+\S+\s+\S+\s+\S+\s+(\d+[K|M|G]?)\s+(\d+[K|M|G]?)\s+\S+\s_[\d+]?\s+\S+\s+(\S+)%\s+([\w\d-]+)$
key_index: 4
variables:
-
variable-name: $host.re.memory.$key-SIZE
variable-type: integer
-
variable-name: $host.re.memory.$key-RES
variable-type: integer
-
variable-name: $host.re.memory.$key-CPU
variable-type: integer