How to parse out an IP address in a varbind string in a Smarts SAM trap using ASL
There are many ways to parse a varbind string. The following sections of this Fix statement present two possible methods using ASL.
Example assumptions for each parsing method
The example in each method assumes that the IP address will always be within parentheses, and that the V1 string to be parsed is the following:
"EMC-WHITEPLAINS-NY-N6531 (10.9.1.1)::Serial0/0"
Method 1 - Parsing based on parentheses
Parse_IP.asl sample code for parsing based on parentheses is as follows:
START { .. eol }
do {
V1 = "EMC-WHITEPLAINS-NY-N6531 (10.9.1.1)::Serial0/0";
print("ip: ". PARSE_IP(V1));
}
//method 1
PARSE_IP(str) {
input = str;
{ .. "(" }
ip : { .. ")" }
.. eol
do {
return substring(ip,0, sizeof(ip)-1);
}
}
Method 2 - Using the ASL delim functionality
Parse_IP.asl sample code for parsing using the ASL delim functionality is as follows:
//method 2
/*PARSE_IP(str) {
input = str;
delim = "()";
word ip : word
.. eol
do {
return ip;
}
}*/