Special Built-In Functions
Wildmask Conversion for Cisco
Use function called wildcardtocidr
Sample
print "converting $(ip) wild mask $(wildmask) => $(converted)"
The result could be:
Convert ISIS system ID to IPv4
Sample:
toipv4(1921.6800.0001) will return 192.168.0.1
Match string value
Use function called getmatch
Sample:
set $(number) getmatch(interface.name, “[0-9.]+”)
print “$(number)”
The result of the print out is “1”
Get physical interface from sub interface
Use function called getphysical
Sample:
set $(physical) getphysical(logical)
print “$(physical)
The result of the print out is “ge-0/0/1”.
Arithmetic Function
Arithmetic functions supported are add, subtract, multiply, and divide
Sample:
set $(b) "2"
set $(add_result) add(a,b)
print "$(add_result)"
The result of the print out is “7”
print "$(substract_result)"
The result of the print out is “3”
print "$(multiply_result)"
The result of the print out is “10”
print "$(divide_result)"
The result of the print out is “2.5”
String Extraction Function
String extraction functions returns the character of properties of a string. The first character in a string starts at index 1. String functions includes len, right, left, mid, and find.
len(string) # returns the length of the string
right(string, num_char) # returns the number of characters from the right
left(string, num_char), # returns the number of characters from the left
mid(string, start_index, num_char) # returns the number of characters from the specified start index
find(txt_to_find, string, [start_index]) # find the index of the character in the string, the start_index is optional
Sample:
set $(country) mid(host_name,1,2)
print "country is $(country)"
set $(role) mid(host_name,4,5)
print "role is $(role)"
set $(intf) "port-1/8/5:10G"
set $(colon) ":"
set $(res) right(intf, len(intf)- find(colon,intf,1))
print "test case 1: $(intf) => $(res)"
The result of the print out is "port-1/8/5:10G => 10G"
set $(res2) left(intf2, find(".",intf2,1)-1)
print "test case 2: $(intf2) => $(res2)"
The result of the print out is "GigabitEthernet0/7/0/36.1778 => GigabitEthernet0/7/0/36"
set $(len) len(s)
print "test case 3 (a): length = $(len)"
The result of the print out is “test case 3 (a): length = 10"
Array Extraction Function
To extract an array from a string, the string syntax must have the array elements enclosed by bracket [,] and delimited by comma or white space. Then use the toarray function on the string to extract the array elements.
Sample:
set $(array) toarray(string)
print "test case 3: $(array)" # prints [bgp, direct, static]
Data Structure Objects
Data structure objects allows the user to create an object that can have multiple attributes assigned to it.
Sample:
create $(interface_obj)
set $(interface_obj.name) "ge-0/0/0"
set $(interface_obj.isis) "yes"
set $(interface_obj.disable) "no"
add $(interface_obj_list) $(interface_obj)
print "interface $(interface_obj)"
create $(interface_obj)
set $(interface_obj.name) "ge-0/0/1"
set $(interface_obj.isis) "no"
set $(interface_obj.disable) "no"
add $(interface_obj_list) $(interface_obj)
foreach $(interface_obj_list) do
print "$(element)"
end
set $(interface_obj) getobject(interface_obj_list, "name", "ge-0/0/0")
print "$(interface_obj)"