Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-value regex parser feature addition #66

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mmellin
Copy link

@mmellin mmellin commented Jul 13, 2016

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:

  • /data/junos-parsers/show-system-processes-extensive.parser.yaml (new syntax)
  • /open-nti/open-nti.py

YAML syntax update

Added:

  • type: multi-value
  • match_count: integer
  • key_index: integer

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

mmellin added 8 commits July 12, 2016 19:25
Adding my version with changes of open-nti.py
Adding my version with support for multi-value regex
added this file to the wrong folder... deleting it
Taking out some commented out debug print statements.
Adding newer version of "show system processes extensive" multi-value yaml
Adding in all my current junos-parser yaml files.
@dgarros
Copy link
Contributor

dgarros commented Aug 6, 2016

Hi @mmellin,
Please, Could you pull the latest update from the branch master,
It should help to pass the tests

@3fr61n,
Did you got a change to look at it ?
I could use that as well :)

thks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants