R12.1-2025July30

Declare Variables

A variable is the basic element of the Visual Parser. It represents the value that the Visual Parser aims to extract.

The following table introduces the available data types of Parser variables and their corresponding 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: Another multi-string variable cannot follow a 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 contain only letters, numbers, and underscores, and must begin with a letter or an underscore.

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 that allows you to define a variable with a fixed set of possible values. The variable can take only one of the specified values at a time.

You can use Enumeration when there are no constant keywords before or after a target variable, but the values of the variable are controlled and predictable. To define an Enumeration, enclose all possible values in parentheses after the variable name and separate each value with a vertical bar (|). For example: $var1(value1|value2|value3)

Information Note: Even if there is only one possible value, the vertical bar (|) is still required. For example: $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. Follow 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 100Mb/s in line 37 to create Var Line 2. 
     
  2. Define Enumeration for Var Line 2:

    1. In the Output area, click the variable column name $var2. In the pop-up window, change the variable name to $duplex and define the Enumeration to Full-duplex|Auto-duplex
    2. 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 the 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, you can skip the string local AS if it is not relevant.

Variable Template <% $var %>

You can insert the Variable template <% $ var% %> in a line pattern to reference a pre-defined variable. The variable template is primarily developed to use key variables formed by specific variable values to match lines containing variables to be parsed in the Var line.

Variable templates are useful for collector parsers, and their usage has been extended to other types of parsers as well.

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 variable parsing, line patterns are automatically generated by identifying variables and locating anchors, which serve as 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 the 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 as 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 a 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” is selected as a variable, which is two distinct words, the line pattern “using $mstring: using of memory” will be generated. 

Automatically Assign Variable Name

After a variable is parsed, the system automatically assigns a variable name to the parsed variable in the line pattern.

  • The first anchor is primarily defined as the 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 a 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 variables, anchors are automatically generated according to the following rules:

  • The words beside the selected variable will be considered as the 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 special characters include “.”, “?”, “!”, “,”, “;”, “:”, “"”, “'” by default (which are configurable in the database). 
  • If you select a word as a variable, and the selected word starts or ends with a special character, the special character will not be recognized as a variable. For example, if 10.10.10.10 is selected, “,” after it will not be used as a variable, and the line pattern identifier $identifier, local will be generated.  

  • If no word before the selected word can be used as an anchor, will be added as an 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.

  • Suppose a generated variable is before/after the currently selected word, the variable that is generated before will be used as the 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 Characters for Exact Match and Avoiding Mismatch

If a target variable is the only string in a line of raw text (i.e., it has no keywords before or after it), use the caret symbol (^) to indicate the start of the line and the dollar sign ($) to indicate the end of the line when defining the line pattern.

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

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

Add Two Underscores Before Parser Variable

If two underscores are added before a parser variable, the variable becomes hidden from other features where parser variables are typically available, such as Network Intent and Data View. However, users can still view the variable in the Parser Preview within the Parser Library.