Two types of functions (LineByKeyword and LineByVariable) can be added by inserting the original line texts. To launch this function, click + Add More > Parse Lines from the Output area.
Engineers can get the original line texts by three methods.
Parse the Line of Variable
Parse the lines containing the selected one or more variables (Pattern Sample: LineByVariable[$confg]: $var1, LineByVariable[$confg]: $var1, $var2).
- This method can be applied in single pattern, paragraph pattern and collector pattern.
- The scope of selectable variables is all the variables defined in the current pattern.
The following two examples illustrate how to create line pattern with function containing one parsed variable or more than one parsed variables.
Example 1: Parse the lines containing a single variable, e.g., parse acl config per line.
- Create a parser and name it "Access List ".
- Define the settings for collecting configuration file data. In this example, select Configuration as the retrieved data and select the device US-BOS-R1.
- Double-click "1" in line 440 to parse the variable “access_list” first in the Auto Parser mode.
- Click +Parse Lines, then define the Parse Lines Settings in the pop-up dialog:
- Set the name to acl_config, The default name is Lines1.
- Keep the default option The line of variable, then select $access_list by checking the checkbox.
- You can preview the pattern command to be created in the pattern field.
- Click Apply to close the Parse Lines dialog. After this step, you will notice that a var line containing the variable selected in step 4 is created.
- Then check the output to view the new added data column in the Output pane.
- Click Apply at the upper-right corner to confirm all the settings.
Example 2: Parse two variables in different lines. In this example, we will parse lines including interface variable and MTU variables.
- Create a parser and name it Interface and MTU Data.
- Define the settings for collecting CLI Command data. In this example, select CLI Command of show interface as the retrieved command data and select the device US-BOS-R1 to retrieve data on it.
- Double-click Ethernet0/0 in line 2, then continue to double-click 1500 in line 5 to parse the variables $intf and $MTU in the Auto Parser mode.
The original parsed variable can be modified. For example, click "&var1" in the output pane, then change the name to a more suitable one (Interface). - Click +Parse Lines in the Output area, then define Parse Lines settings in the pop-up dialog:
- Set the variable name to intf_mtu,
- select “The line of variable”, then select $intf and $MTU.
- You can preview the pattern command to be created in the pattern field.
- Click Apply to close the Parse Lines dialog. After this step, you will notice that a var line containing the two variables selected in step 4 is created.
- Check the parsed lines including variables $intf and $MTU for each interface in the output.
- Click Apply at the upper-right corner to confirm all the settings.
Parse the Lines Between Variables
Parse the lines in a range defined by two variables, or from a variable to the end of the paragraph (Pattern Sample: LineByVariable[$confg]: $var1-$var2, LineByVariable[$confg]: $var1-).
- This method can be applied in single pattern, paragraph pattern and collector pattern.
- The scope of selectable variables is all the variables defined in the current pattern.
Example 1: In this example, parse the lines between two variables, e.g., parse the basic metric of OSPF interface
- Create a new parser and name it OSPF_Interface.
- Define the settings for collecting CLI Command data. In this example, select CLI Command of show ip ospf interface as the retrieved data and select the device US-BOS-R1 to retrieve data on it.
- Double-click Loopback0 in line 2 to parse the variables $intf, then continue to double-click 1 in line 4 to continue to parser variable $ospf_id in Auto Parser mode.
The system will automatically assign the variable name "var1" and "ID" for the two parsed variables, respectively. In this example, you can change the variable names to more meaningful ones in the Output area.- Click the variable name "$var1", then change it to "$intf" in the pull-down window.
- Click the variable name "$ID", then change it to "$OSPF_ID" and change the variable type to int.
- Click +Parse Lines, then define Parse Lines settings in the pop-up dialog: Set the name to ospf_metric. Select The line between option, then select $intf and $ospf_id to define the scope of the matched original lines. Check the parsed lines between the two selected variables for each interface in the output.
- Set the name to ospf_metric.
- Select The line between, then select $interface and $ospf_id to define the scope of the matched original lines. Check the parsed lines between the two selected variables for each interface in the output.
- Click Apply to save the Parse Lines settings, then you will notice that Var Line 2 is created.
- Check the parsed lines between the two selected variables for each interface value in the output.
- Click Apply at the upper-right corner to confirm all the settings.
Example 2: You can select a variable and End to define the scope of the original text. In this example, we will parse the lines from a variable to the end, e.g., parse OSPF config.
- Create new parser and collect command show run data from the device NY_POPP.
- Double-click 10 in line 97 to parse the variable $ospf (int).
- Click the column header $ospf (int) in the output table, then change the variable column name to ospf_id.
- Click + Parse Lines, then defined the Parse Line Settings in the Parse Lines window:
- Set name as ospf_config.
- Select The line between, then select “$ospf_id” and End.
- Click Apply to close this window, then the line pattern will be added.
- Select Add End Line from the pattern menu, then input ip nat to match the last line of the parsing scope. In this example, the last parsed line is line 105.
Note: To correct the parsed results, the End Line needs to be included.
- Check the output for ospf_config.
Parse the Lines of Keyword
Parse the lines containing the specified keywords or variable template (Pattern Sample: LineByKeyword[$confg]: access-list, LineByKeyword[$confg]: standby <%$standby_id%>).
- The method can be applied to single pattern, paragraph pattern and collector pattern.
- The scope of selectable variables is all the variables defined in the current pattern. Variable is inserted as a variable template to reference a pre-defined variable.
Example 1: Parse the lines containing one keyword, e.g., parse all access-list to one variable.
- Create a new parser, then select CLI Command and retrieve the command show run data on device NY_POPP.
- Click the down arrow beside + New Pattern, then select Single Variable to create a new single-variable pattern.
- Click + Add More > Parse Lines, then define Parse Line Settings.
- Name: Set the name to acl_config.
- Select the The line contains keyword option, then input “^access-list”.
- Click Apply.
- Check the output and click the
icon to save the parser.
Example 2: Parse the lines containing keywords (insert a variable template). In this example, we will parse acl_config for each access-list id.
- Create a new parser, then select CLI Command and retrieve the command show run data on device NY_POPP.
- Click + New Pattern > Advanced > Collector to create a new collector pattern.
- Double-click 3 in line 148 to parse the variable access_list in a collector pattern, then manually change the ID Line to ^access-list $int:access_list.
- Click +Add More > Parse Lines to define Parse Line Settings.
- Set the new variable name to acl_config,
- Select The line contains keyword option, then input ^access-list. Click to select $access-list, then continue to input $_dummy. after these settings, a var line LinesByKeyword[$ospf_config]:^access-list <% $access_list %> $_dummy is added.
- Click Apply.
- Check the output table.
- Click the
icon at the upper-right corner to save the parser.