===== Command parsing on Cisco IOS finding interfaces and ports ===== The goal of this example is to find interfaces that belong to specific vlans. Create a new Command Job and save it using a desired name. ==== Command Job ==== The job is "empty". It still requires something though, so it's filled with a '!'. ! ==== Parsing template parsevlan ==== The command that is used is //show vlan | i user|data//. This parse template will match specifically on the word "active". For those lines it will set the vlannumber and vlandescr variables. active |*| ==== Parsing template intfnumber ==== The command //show int switchport | i Name:|Access Mode VLAN// is used to find the combination of information of interface and (data) vlan. In this parsing template and ''%'' sign is used to create a hash to store the other variables in relation to it. This allows to retrieve the variable using the following inside a loop in the scenario: ''%%<<%%interface>.accessvlan%intf>'' Name: <%interface> Access Mode VLAN: Make sure to read the [[menu:operate:scenarios:syntax#hash_variables|hash article]] on how is different than <%variable>. ==== Job scenario ==== Description Parsing vlan and interfaces on task := scn_parse_vlan_intf ==== Scenario scn_parse_vlan_intf ==== # Test whether node is live and reachable reachable -n if LogAction -n -a Parse_job -m " is not reachable" stop endif LogAction -n -a Parse_job -m " is reachable" <%cmd> := parse_cmd -n -t parsevlan -r "show vlan" := keys <%cmd> foreach in log -m "vlan: " <%intf> := parse_cmd -n -t intfnumber -r "show int switchport \\| i Name:\\|Access Mode VLAN" := keys <%intf> foreach in log -m "interface: " log -m "vlan: <.accessvlan%intf>" if "<.accessvlan%intf> == " log -m "Interface found, generating and/or appending configuration" config_create -n -t user_interface -f _user_intf.cmd -x if Logaction -n -m "Failed to create the template for " Stop endif endeach endeach log -m "Pushing new configuration" config_exec -n -f _user_intf.cmd if Logaction -n -m "Failed to configure commands" Stop endif end Some things to note: \\ * '' := keys <%intf>'', this is required to be able to loop over the created hash/dictionary. * Config is being generated for every interface in addition and once completely done, it will be pushed to the device. * ''|'' (pipes) need to be escaped (double). This is because the can also be used as conditionals.