Compound Variable
Beyond existing built-in variables and parser variables, the system supports compound variables in a data view template definition to organize multiple variables to represent complex network semantics. For example, you can define a compound variable,
$routing = $hasBGP?$as:($hasOSPF?$rid:($hasISIS?$level:”N/A”)) , to present the following semantics:
- If $hasBGP is true, return the value of $as; if not, return the value of ($hasOSPF?$rid:($hasISIS?$level:”N/A”)).
- If $hasOSPF is true, return the value of $rid; if not, return the value of $hasISIS?$level:”N/A”).
- If $hasISIS is true, return the value of $level; if not, return ”N/A”.
Refer to Compound Variable Properties on how to define a compound variable,
Compound Variable Properties
Compound variables can be separately defined at device and interface levels, composed of built-in variables or parser variables, operators and functions.
The following table lists the properties of a compound variable.
Property | Description |
Variable Name | The name of a compound variable. |
Type | The type of compound variable:
|
Definition | Define a compound variable with built-in functions or formulas, including Global Functions. Examples:
|
![]() |
General Notes for Compound Variable Definition: 1) Device-level compound variables can be composed of device variables and input variables; interface-level compound variables can be composed of device variables, interface variables and input variables. 2) Line breaks are not allowed. 3) Nested compound variables are not allowed. |
String Operators
The following table lists the built-in operators used for string-type variables.
Operator | Description | Example |
+ | Merge two string-type variables. | $routing = $bgp_config + $ospf_config |
== | Equals specified string. | $a==$b?1:0 |
!= | Not equals specified string. | $a!=$b?1:0 |
Substring | Only keep a sub string out of source string. Format: $var.Substring(startIndex, length)
| If $a = abcdef, then:
|
MatchPattern() | Support the match of regular expressions. Format: $var.MatchPattern(input, pattern)
|
|
String + Number | Merge a string-type variable and a number-type variable. | $str2 = $str1 + $number1 |
StartsWith | Match a string starting with specified sub string. | $a.StartsWith("abc") |
EndsWith | Match a string ending with specified sub string. | $a.EndsWith("def") |
Contains | Match a string that contains specific characters. | $a.Contains("ab") |
IsEmpty | Judge whether the value of a string or a variable is null. |
|
Number Operators
The following table lists the built-in operators that can be used for number-type variables.
Operator | Description | Example |
+ | Add two number-type variables. | $error = $input_error + $output_error |
- | Subtract two number-type variables. | $error = $input_error - $output_error |
* | Multiply two number-type variables. | $a*$b |
/ | Divide two number-type variables. | $a/$b |
> | Judge whether the value of a number-type variable is greater than that of another one. | $cpu > 90 |
>= | Judge whether the value of a number-type variable is equal to or greater than that of another one. | $a>=$b |
< | Judge whether the value of a number-type variable is less than that of another one. | $a<$b |
<= | Judge whether the value of a number-type variable is equal to or less than that of another one. | $a<=$b |
== | Judge whether the values of two number-type variables equal. | $a==$b |
!= | Judge whether the values of two number-type variables don't equal. | $a!=$b |
Bool Operators
The following table lists the built-in operators that can be used for bool-type variables.
Operator | Description | Example |
&& | Combine two variables, indicating both var1 and var2. | $cpu > 90 && $mem > 80 |
|| | Alternate two variables, indicating either var1 or var2. | $cpu > 90 || $mem > 80 |
! | Get the opposite result of a variable. | !($cpu > 90) |
?: | The ternary operator. | $cpu > 90?1:0 It means if $cpu > 90, return 1; if not, return 0. |
() | Prioritize a formula. | ($a-$b)*$c |
Global Functions
The following table lists the global functions that can be used to define a compound variable.
Function Name | Description | Example |
NB_GetDevice | Obtain a device name by using an IP address. | NB_GetDevice($ip) |
NB_GetMgmtIP | Obtain a management IP address by using a hostname. | NB_GetMgmtIP($hostName) |
GetTableRowCount | Obtain the number of rows for a table-type variable. Format: GetTableRowCount($Table, $vrf, $PeIP) Notes: 1) "$" is not required when referencing a function. 2) Both $vrf and $PeIP are optional, and can be left blank. |
|