Supported Built-in Functions in Network Intent
Network Intent supports built-in functions to define compound variables, compound tables, or Formula Columns to convert predefined variables in terms of variable types, units, values, etc.
The following table lists the built-in functions that will provide you the overview of the functions.
|
Note: For the functions Sum, Average, Min, and Max, their return values are in the type of float. So they must be assigned to float variables; otherwise, the assignment will fail. |
|
Function Spec
|
Description | Sample Function Call | ||
| Average (table table, string column_name) |
Returns the average (arithmetic mean) of a set of values.
Note: Returning “-1” if the input is not a valid number array. |
Average($bgp,"bgp_routes")
Return: 10 |
||
| ByteConverter (string input) |
Convert storage units (such as KB, MB, GB, etc.) to byte.
|
ByteConverter("35MB")
(35x1024x1024) |
||
| CalcTrafficBps(number traffic_byte, number sys_time) |
Calculate interface traffic (bit) based on given traffic (byte) data and system uptime information.
|
CalcTrafficBit(191941437745628, 3282115859)
Return: 1000 |
||
| CalcTrafficInfoRaw(string traffic_in_byte_variable, string sys_uptime_variable , string bandwidth_variable) |
Return formalized interface traffic and traffic utilization string based on given traffic (byte), system uptime, and bandwidth information.
|
CalcTrafficInfoRaw($traffic_byte, $sys_uptime, $bandwidth)
Return: "%.1f Kbps, <0.1%" |
||
| CalcTrafficUtilization(number traffic_bit, number bandwidth) |
Calculate interface utilization based on given traffic (bit) and bandwidth information.
Note: The format of bandwidth is GAUGE32. |
CalcTrafficUtilization($traffic_in_bit, 10000000000)
Return: 100 |
||
| CompareDate(string target_date) |
Compare target date with the current time.
Note: Returning “0” if the target date is earlier than the current time; otherwise returns "1". |
CompareDate("$end_of_sale_date")
Return: 0 or 1 |
||
| ConvertToBool(var) |
Convert the input variable to boolean.
Examples: ConvertToBool("false") → False ConvertToBool("abc") → True ConvertToBool("") → False ConvertToBool(1) → True ConvertToBool(0) → False |
ConvertToBool("abc")
Return: True |
||
| Float ConvertToFloat(var) |
Convert the input variable to float.
Examples: ConvertToFloat("2.1") → 2.1 ConvertToFloat("abc") → 0 |
ConvertToFloat("2.1")
Return: 2.1 |
||
| ConvertToInt(var) |
Convert the input variable to integer.
Examples: ConvertToInt("2") → 2 ConvertToInt("2.4") → 2 ConvertToInt("2.5") → 3 ConvertToInt("abc") → 0 |
ConvertToInt("2.5")
Return: 3 |
||
| ConvertToString(var) |
Convert the input variable to string.
Examples: ConvertToString(3.1415) → "3.1415" ConvertToString(true) → "True" ConvertToString(false) → "False" |
ConvertToString(3.1415)
Return: "3.1415" |
||
| Delta (variable_name) |
Get the delta between the variable's current and last values.
Note: Only applies to variables of type number. Returning “-1” if the calculation failed. |
Delta ($intf_traffic)
Return: 0 |
||
| Device(string Hostname) |
Create a device object with an existing device for further operation.
Note: IP address can also be passed in as hostname variable. |
Device("BJ*POP")
Return: device |
||
|
DoesDeviceExist(string Hostname)
|
Check whether a device still exists in the current domain. Note: IP address can also be passed in as hostname variable. |
DoesDeviceExist(“BJ*POP”) Return: True/False |
||
| DeviceGroup (string FullPath) | Create a device group object with an existing device group for further operation. | DeviceGroup("Shared DeviceGroups/BGP/BGP Devices") Return: devicegroup |
||
| DeleteMap(string FullPath) |
Delete an existing normal map with specified full path of the map file.
Note: Function maps not supported here. |
DeleteMap("Public\\OpenTopo") Return: N/A |
||
| DoesInterfaceExist(string Hostname, string InterfaceName) | Check whether an interface still exists in the current domain. |
DoesInterfaceExist("BJ*POP", "ethernet0/0")
Return: True/False |
||
| Find (string str, string substr) |
Find one or more characters in a given string.
Note: Returning “-1” if nothing is found. |
Find("router ospf 100", "ospf")
Return: 1(True) or 0(False) |
||
| File (string FullPath, string Type="Text") | Create a file object with an existing file for further operation. | File("Public/filename”) Return: file |
||
| FormatMAC (string mac_address) |
Get formatted MAC address using NetBrain-specific standard (period-separated hexadecimal notation).
Note: Returning original MAC address if the format fails. |
FormatMAC("D8-67-D9-86-59-40")
Return: "d867.d986.5940" |
||
| FormalizeIntfStatus(string intf_status) | Return formalized interface status information based on the given interface status. |
FormalizeIntfStatus("up")
Return: "UP" |
||
| FormalizeTrafficInfo(number traffic_bit, number traffic_utilization) | Return formalized interface traffic and traffic utilization string based on given traffic (bit) and utilization information. |
FormalizeTrafficInfo($traffic_in_bit, $traffic_utilization)
Return: "%.1f Kbps, <0.1%" |
||
| GetGoldenConfigCheckResult(string FullPath_Of_Golden_Rule, string DeviceName, bool OnlyInstanceWithAlert=True) |
This function calls the Golden Config service to validate the config file of a specified device against the specified golden config rule. |
For more information, see Built-in Functions for Follow-up Remediation. |
||
| GetSiteOverviewMap() | Get the overview map of all sites. |
GetSiteOverviewMap()
Return: map |
||
| GetListElementCount(List) | Get the element count of a specified list. |
GetListElementCount(List)
Return: 6 |
||
| GetTableRowCount (string tableName) |
Obtain the number of rows by using a given table name.
|
GetTableRowCount("ospf_nbrs")
Return: 32 |
||
| GetTimeString(number offset, number timeunit) |
Get a certain time before the current time and return it as a string.
If offset is "0", returns the current time. Timeunit: The value of timeunit could be set as 0/1/2/3/4, respectively representing min/hour/day/week/month. |
GetTimeString(1, 1)
Return: "08/09/2023 11:34:00" |
||
| Interface(string Hostname, string InterfaceName, string InterfaceType="Interface") |
Create a device interface object with an existing interface for further operation.
Types: Interface=1, IPv4=2, IPv6=3, IPsec VPN=4, GRE VPN=5 |
Interface("BJ*POP", "ethernet0/0", 1)
Return: interface |
||
| InterfaceByIP(string IPAddress) |
Create a device interface object by existing interface IP.
If duplicated IPs, first match is used. Supports IPv4 and IPv6. |
InterfaceByIP("10.8.1.30")
Return: interface |
||
| InterfaceShortToFull(string hostname, string shortname) |
Obtain an interface fullname by using a given interface short name.
Note: Returns NULL ("") if the input is not valid. |
InterfaceShortToFull("R1", "Ether2/1")
Return: "Ethernet2/1" |
||
| IPNumberToString (number ip) |
Convert an IP address from integer format to string format.
Note: Returning NULL (“”) represents error. |
IPNumberToString(3232258817)
Return: "192.168.91.1" |
||
| IPStringToNumber (string ip) |
Convert an IP address from string format to an integer. Masked IP address is allowed, e.g., "192.168.91.1/28".
Note: Returning “-1” if the input is not a valid IP address. |
IPStringToNumber("192.168.91.1")
Return: 3232258817 |
||
| IPToHostname (string ip) |
Convert an IP address to the hostname. The input can be an IP or a masked IP, e.g., "192.168.91.1/28".
|
IPToHostname("192.168.91.1")
Return: "R1" |
||
| IPToInterfaceName (string ipaddr) |
Obtain a device interface full name by using a given IP address. Masked IP is allowed.
|
IPToInterfaceName("192.168.91.1")
Return: "FastEthernet1/1" |
||
| IPToSubnet(ip) |
Return the subnet of an IP address. Masked or full address with subnet mask is allowed.
|
IPToSubnet("192.168.100.15/28")
Return: 192.168.100.0/28 |
||
| MACToVendor(string mac_address) |
Return the vendor information for a device by MAC address.
Note: Returns NULL if the MAC is invalid. |
MACToVendor("AAAA.1111.2222.4444")
Return: Cisco |
||
| Map(string FullPath) |
Create a map object with an existing map for further operation.
Note: Only supports normal maps, not function maps. |
Map("Public\\OpenTopo") Return: map |
||
| Max (table table, string column_name) |
Returns the largest value in a set of values.
Note: Returns “-1” if the input is not valid. |
Max($intfs, "traffic")
Return: 12 |
||
| Min (table table, string column_name) |
Returns the minimum value in a set of values.
Note: Returns “-1” if the input is not valid. |
Min($intfs, "traffic")
Return: 13 |
||
| NewFile (string FileName, string Folder, string Type="Text") |
Create a new text file in NetBrain files.
|
NewFile("OpenTopo", "Public", "Text")
Return: file |
||
| NewDeviceGroup (string Name, string Folder) | Create a new device group. |
NewDeviceGroup("BGPDevices", "BGP")
Return: devicegroup |
||
| NewMap (string FullPath) |
Create a new map object using the specified full path of the target map file.
Note: Function maps are not supported. |
NewMap("Public\\DeviceNeighbor") Return: map |
||
| NewSite (string Name, string FullPathOfParent, bool IsLeafSite) |
Create a new site.
Name: Name of the new site FullPathOfParent: full path of the parent site IsLeafSite: True = leaf, False = container |
NewSite("Netbrain-MultiSource", "MyNetwork\\Traditional-DC", True)
Return: site
|
||
| NumberToString (number input) |
Convert a number to string format.
Note: Returning NULL (“”) if the input is not a valid number. |
NumberToString(5)
Return: "5" |
||
| Path(string ApplicationName, string PathName) |
Create a path object with an existing path defined in the domain.
Note: Creating new paths is not supported. |
Path("EmailService", "ClienttoDNS")
Return: path |
||
| PercentageToNumber (string percent) |
Convert a percentage as text to a float number.
Note: Returning “-1” if the input is not a valid percentage. |
PercentageToNumber("50%")
Return: 50 |
||
| ReadAsTable(string columnMappings) |
Read data from a CSV file and map it to the intent table variable based on the defined relationship.
How Column Mappings Work: Define the mapping columns from the CSV, separating them with commas (,). The position numbers of the columns will correspond to those of the table variable columns. If you don't want to map certain columns in the table, leave their positions as null. |
ReadAsTable("Column 1, , CSVcolumn3, ,CSVcolumn2,CSVcolumn4")
Return: table data for intent table variable |
||
| Replace (string original, string old, string new) |
Replace one character with another in a given string and return the replaced string.
Note: Returning the original input string if the replacement fails. |
Replace("2020-8-23", "-", "/")
Return: "2020/8/23" |
||
| ReplacebyRegex | Replace the characters matched by the pattern with the string defined in the replacement. Based on the input, match the characters to be replaced according to the defined pattern, and then replace these characters with the string defined in the replacement. 0: Specifies that no options are set. 1: Specifies case-insensitive matching. 2: For multiline mode, change the meaning of ^ and $ so they can match each line's beginning and end, not just the beginning and the end of the entire string. | RegexReplace(”{$enablepwd}”,"^!enable password ([^!]+)\n!","!enable password {$pwd}"),0) Return: "!enable password {$pwd}" | ||
| Round(number number) |
Return number rounded to two digits precision after the decimal point.
Note: Returning “-1” if the input is not a valid number. |
Round(36.8732994298449)
Return: 36.87 |
||
Site(string Name, string FullPathOfParent) | Create a site object with an existing site for further operation. | Site("Cisco-WLC-Lab", "MyNetwork\\Traditional-DC") Return: site | ||
| SNToDevice(string serial_number) |
Return a device object by its serial number.
Note: Returning NULL if the input is not a valid serial number. |
SNToDevice("SNX1992")
Return: BJ*POP |
||
| SplitString(string input, string SeparatorChars) | Split the input into multiple strings based on one or more given separator chars. |
SplitString("device1 device2 device3", " ")
Return: {device1,device2,device3} |
||
| SplitToLines | Split a string by specified separators, each separator can be unique character. The items spitted will form new string with each item as separate line. | SplitToLines($IPs, "\ ") Return: "10.10.10.1 10.10.10.2" | ||
| SplitByChars | Split a string by specified separators, each separator can be unique character. And further you specify which item to be used as return value, the first item is represented by 0. | SplitByChars($site, "/| ", 1) Return: NA | ||
| StringToNumber (string input) |
Convert a string-type number to a number-type.
Note: Returning "-1" if the input string is not a valid number. |
StringToNumber("19")
Return: 19 |
||
| Sum (table table, string column_name) |
Returns the sum in a set of values.
Note: Returning “-1” if the input is not a valid number array. |
Sum($bgp, "bgp_routes")
Return: 11 |
||
| Trim(string original, string trimchars) |
Trim characters before/after specified characters.
If “trimchars” is "", null characters are removed. If specified, only that character is trimmed. |
Trim($str, "")
Return: (cleaned string) |
||
| TrimLeft (string original, string trimChars) |
Trim one or more characters on the left side of a given string.
Note: Returning original input string if the trim fails. |
TrimLeft("-4.03", "-")
Return: "4.03" |
||
| TrimRight (string original, string trimChars) |
Trim one or more characters on the right side of a given string.
Note: Returning original input string if the trim fails. |
TrimRight("4.03,", ",")
Return: "4.03" |
||
| VerifyGoldenConfig(string FullPath_Of_Golden_Rule, string DeviceName, bool RefreshConfigFile=true) | This function is used to get the result of the latest golden config check result (against golden config rule) of the specified golden config rule for the specified device. |
For more information, see Built-in Functions for Follow-up Remediation. | ||
Get_FHRP_Interfaces(string Virtual_IP)
| Get the corresponding interfaces list with the specific virtual IP as input. | Get_FHRP_Interfaces("10.10.10.1", ) Note: The return is a List of Interface object. | ||
| bool IsInRange (int number, string range) | Check if the number is within the range string. | For example, check if the given input vlan $vlan is present in the vlan allowed list $vlan_range (1-5,7,9-12,13,28,128). If $vlan = 10, the expression IsInRange ($vlan, $vlan_range) will return True. If $vlan = 6, the expression will return False. | ||
| list <string> SubnetToIPs(string subnet) | Get the list of IP addresses within a subnet. | SubnetToIPs(“10.10.10.0/24”) Return: [ “10.10.10.1”, “10.10.10.8”, “10.10.10.34” ] | ||
| String GetGoldenParameterValues(string DeviceName, String ParameterPath) | Get the corresponding golden parameter value with the specific device name and parameter path as input. | GetGoldenParameterValues("GW2LAB", "folder1/ipHelperAddress") Return: “ip helper-address 172.16.131.2 ip helper-address 172.16.141.2 ip helper-address 172.16.151.2 “ |