10.1.15.12-06212024

Declare Variables

Variable is the most fundamental element of Visual Parser, the value of which is Visual Parser aiming to parse.

The following table introduces the available data types of Parser variables and their formats. The general format is $variable_type:variable_name (exception: Enumeration).

Table 1 - Types of Variables
Variable Type
Description
Variable Format
StringMatch any single word.
Information Note: Space characters cannot be applied to a string-type variable.

$string:var1 or
$var1
Multi-string

Match one or multiple words.

Information Note: A multi-string variable cannot be followed by another multi-string variable.
$mstring:var2
IntegerMatch any whole number.$int:var3
FloatMatch any double-precision IEEE 64-bit (8-byte) floating-point number.$float:var4
BooleanA variable with possible value options “true”, “false”, "1" or "0".
Information Note: Both "true" and "false" are case-insensitive.

$bool:var5
Enumeration

Match one of the listed options of a variable.

Information Note: Only the listed values can be successfully parsed. 
$var6(value1|value2)
DummyA placeholder for an uninterested variable that will not be parsed.$type:_dummy

Information Note: A variable name can only contain letters, numbers, and underlines, and can only start with a letter or underline.
Information Note: The variable types (Multi-string and Enumeration) are variants of string-type variables and will be treated as a string in further automation.
Information Tip: NetBrain provides built-in functions to support the definition of compound variables. 

Enumeration Variable

Enumeration is a user-defined data type where you can specify a set of values for a variable, and the variable can only take one out of the set of possible values. When there are no constant keywords before or after a target variable, but the values of the variable are predictably controlled, you can use Enumeration to define the variable. All the possible values must be included in a pair of parentheses after the variable name, and a vertical line (|) can be used to separate two possible values, e.g., $var1(value1|value2|value3). Note that even if there is only one possible value, the vertical line (|) must be added, e.g., $var1(value1|).

You can use Enumeration to parse all variable types, such as:

  • $var1(value1|value2) indicates to parse the value of a string-type variable.
    Information NoteSpace is allowed in the value of a string, e.g., $duplex(Full Duplex|Auto Duplex).
  • $int:var1(value1|value2) indicates to parse the value of an integer-type variable.
  • $float:var1(value1|value2) indicates to parse the value of a float-type variable.

For example, to parse enumeration-type variables like $duplex , you can use $duplex(Full-duplex|Half-duplex|Auto-duplex)” in the variable line pattern. Following the steps below to complete the settings in this example.

  1. In the Sample text area, double-click "FastEthernet0/1" in line 29 to create an ID line, double-click 1500 in line 33 to create Var Line 1, then select "Full-duplex" and "100kb/s" in line 37 to create Var Line 2. 
  2. Define Enumeration for Var Line 2: 
    1. Manually edit the var line by changing the command line to "$Duplex(Full-duplex|Auto-duplex), $Spped, $_dummy". 

    2. In the output area, click "$var2", then change the name to "Duplex" and define the Enumeration to "Full-duplex|Auto-duplex". 

      Click Apply to close the window and apply the settings.
Information Note: Only the values listed in the line pattern can be successfully extracted.
Information Note: Possible values cannot contain special characters | and right bracket ).

Dummy Variable

A Dummy variable is a virtual variable in the shape of $type:_dummy in a line pattern and will not be extracted as a Parser variable.

You can use a dummy variable to skip a specific type of variable you are not interested in, like a placeholder. For example:

  • $mstring:_dummy indicates skipping multiple lines of string.
  • $string:_dummy($_dummy) indicates to skip a string.
  • $int:_dummy indicates to skip an integer.
  • $float:_dummy indicates to skip a float.

Take the BGP router as an example: If you want to parse its ip address, the string "local AS" you are not insterested in can be skipped.

Variable Template <% $var %>

Variable template <% $var %> can be inserted in a line pattern to reference a pre-defined variable. Variable template is primarily developed for using the key variables formed by certain variable values to match the lines containing variables to be parsed in Var line.

Variable Template comes handy for collector parser and we also extend the scope of using variable templates to other types of parsers. 

The following lists the line patterns supporting variable templates.
  • Var Line (support variable template in paragraph/collector pattern
  • ID line (support variable template in paragraph/collector pattern)
  • Start Line (support variable template in paragraph/collector/ Json table Pattern)
  • End Line (support variable template in paragraph/collector/ Json table Pattern)
  • End of Paragraph (support variable template in paragraph pattern)
  • Parser line UI (support variable template in LineByKeyword syntax)
Information Note: Variable template is not supported in Auto Parser Mode.

Add Variables

During parsing variables, line patterns will be automatically generated by parsing the variable and finding anchors (which will be used as the keywords for filtering variables from the parser input).
  • When one word is selected from one line as a variable (double-click the word in the parser input area), a typical line pattern is generated in the form “anchor + variable + anchor”. For example, in the sample data below, if "10.10.10.10" is selected as variable, the line pattern “identifier $identifier, local” will be generated.

  • If you select words several times for parsing variables and the selected words are in one line, the variables will be merged into one line pattern. For example, in the sample data below, if “10.10.10.10” and “65001” in the same line are selected as variables, the line pattern “identifier $identifier1, local $mstring:_dummy number $int:number” will be generated.

  • If a new selected variable is not in the same line with the existing variables, a new line pattern will be generated for the new variable. For example, in the sample data below, double-click “Ethernet0/0” to add line pattern “^$var1 is” first, then double-click “1500”, a new line pattern “^ MTU $int:MTU bytes,” will be generated.

    Information Note: If a number is selected as variable, the system will automatically generate a variable of “$int” type, like $int:mtu.
  • If several words are selected as a variable, the variable type will be automatically set to “$mstring”. For example, in the sample data below, if “1728 bytes” are selected as a variable, which are two distinct words, the line pattern “using $mstring: using of memory” will be generated. 

Automatically Assign Variable Name

After variable is parsed, the system will automatically assign variable name for the variables parsed in line pattern.

  • The first anchor is primarily defined as variable name.

  • The anchor after the variable will be used as the variable name if the first anchor does not exist.

  • If the anchor is one of “isarewerewasonofwithatunderforinbyoverbetween, through, tofromduring”, these words cannot be used as variable name, and the system will automatically assign variable names “$var1$var2$varN…”.

  • If an entire line is selected and no anchor can be qualified as variable name, the system will add the selected variables to the line pattern as enumerations.
  • If the matched word contains “/”, the generated variable will be replaced by “_”.

Rules for Generating Anchor

If words are selected as variable, anchor will be automatically generated by following the rules below:

  • The words beside selected variable will be considered as anchor if they are “String” or “String + Special Character” type. For example, if the word “75/36” is selected as variable, the word “activity” at the left side is in string format, and word “prefixes” at the right side is in "string + special characters" format, so these two words can be set as anchor to identify the selected variable.

    Information Note: the specifical character, including “.”, “?”, “!”, “,”, “;”, “:”, “"”, “'” by default (which are configurable in database). 
  • If you select word as variable, and the selected word starts or ends with special character, the special character will not be recognized as variable. For example, if “10.10.10.10” is selected, “,” after it will not be used as variable, and line pattern “identifier $identifier, local” will be generated.  

  • If no word before the selected word can be used as anchor, "^" will be added as anchor. For example, if “39” is selected, and there is no suitable anchor before it, “^” is added as the anchor. Line pattern “^$int:path path” is generated.

  • If a generated variable is before/after the currently selected word, the variable that is generated before will be used as anchor. For example, if “10.10.10.10” is already selected to generate variable “$var1”, and we continue to select “255.255.255.255”, $var1 will be the anchor before this selected word.

  • If the word before or after the selected word is of the types (“Number”, “String + Number”, “Number + Special Character”, or “String + Number + Character”), the system will skip this type of word (“$_dummy” will be used to replace these words) and continue to find anchor. For example, if “6.7.8.9” is selected, the line pattern “^$var2 $_dummy $_dummy $_dummy $_dummy $_dummy $_dummy $_dummy never” is generated.

Using Special Character for Exact Match and Avoiding Mismatch

When there is no keyword before and after a target variable in one line of raw text, that is, the variable is the only string in that line, you can use the character ^ to represent the start of a line and use the character $ to represent the end of a line when defining the line pattern.

Take the following Paragraph Parser as an example: the parent line pattern only contains a variable of interface name (note that there is space before and after the variable).

  • To define the parent line pattern, you can use “^ $int: minute”, which means the variable starts with a space.
  • You can use $Timeout$ in the line pattern, where the second "$" means the end of this line pattern.