EEM Matching a string within CLI output

When using EEM Cisco Embedded Event Manager, it can be useful to determine if a particular string exists within specific CLI output. For example, you may want to apply a configuration to all interfaces belonging to a particular VLAN. Matching the VLAN ID you're looking for in CLI output will allow you to identify those interfaces.

To do so, you can use the string match command. For example, the following commands search for the string "Description: my_port" within the output of the show interface gigabitethernet 1/0/1 command.

action 3.2 cli command "show interface gigabitethernet 1/0/1"
action 3.3 string match "*Description: my_port*" "$_cli_result"
action 3.4 puts "$_string_result

If that string is found somewhere within the output of the CLI, the value of the string_result variable will be 1. If not, it will be 0. The above will simply print out the value of the result, but this result can then be used to take further action.

Links:

https://networklessons.com/cisco/ccie-routing-switching/cisco-ios-embedded-event-manager/

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/eem/command/eem-cr-book/eem-cr-a2.html#wp2508208016

https://forum.networklessons.com/t/cisco-ios-embedded-event-manager-eem/1106/37?u=lagapides