cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1438
Views
5
Helpful
1
Replies

EEM: cli pattern of multiple lines

smitsialis
Level 1
Level 1

Hi,

I'm trying to create a script that will perform an action when a port is configured with specific VLANs.  I need to know which interface was configured in order to be able to take action.  Problem is only the 2nd line shows up in the $_cli_msg.

 

event manager applet testapp1

 description "when port configured for vlans 825 command issued to enable poe"

 event tag 1 cli pattern "interface GigabitEthernet" sync no occur 1 skip no

 event tag 2 cli pattern "switchport access vlan 825" sync no occur 1 skip no

 trigger

 correlate even 1 or event 2

 exit

 action 1.0 set intf ""

 action 1.2 set interf ""

 action 2.0  regexp "GigabitEthernet[0-9/]+" $_cli_msg intf

 action 2.2  if $_regexp_result ne 1

 action 2.4      set interf $intf

 action 2.5      syslog msg "in the if section, $intf, $interf"

 action 2.6 end

 action 4.0 syslog msg  "Message: $_cli_msg, INTERFACE $intf"

 

The script runs twice, once per line so I dont get the interface the 2nd time it runs.  How can I do this differently to make it work?

Thanks,
Spiro

1 Reply 1

Joe Clarke
Cisco Employee
Cisco Employee

This is actually extremely complex to do.  What you have here will absolutely not work as you've already seen.  What you can do is enable config archive so it will record the CLI history:

 

archive
 log config
  logging enable

 

Then run the "show archive log config user $_cli_username 0" command and parse the output to find the interface.  The last line should be the interface.  Plus you can compare the VTY on that line to $_cli_tty to make sure the user didn't have multiple sessions.  See, not easy :-).  But it can be done.