cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
184
Views
1
Helpful
2
Replies

Regex on EEM applet not working to shut/no shut an interface

Cedric Metzger
Level 1
Level 1

I want to shut/no shut 60 seconds after boot the uplink. The uplink has the port description "PNP STARTUP VLAN". There is only one port per switch with this description.

I came up with following applet:

event manager applet SHUT_NO_SHUT_UPLINK
event timer countdown time 60 name sixtyseconds
action 1 syslog msg "started after 60s"
action 2 cli command "enable"
action 3 cli command "configure terminal"
action 4 cli command "do show interfaces description | include PNP STARTUP VLAN"
action 5 regexp "^[^\s]+" $_cli_result match interface
action 6 syslog msg "$interface brought up by EEM script"
action 7 cli command "interface $interface"
action 8 cli command "shutdown"
action 9 wait 10
action 10 syslog msg "waited 10s"
action 11 cli command "no shutdown"
action 12 cli command "end"
action 13 cli command "write memory"

I tested the regex on regex101.com the regex seems to be correct. No matter what I try, the variable $interface remains empty which I verified with the syslog messages

*May 16 19:44:58.296: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: started after 60s
*May 16 19:44:58.296: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: waited 10s
*May 16 19:44:58.666: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: brought up by EEM script

Has anybody an idead why the variable remains empty?

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

The action number in EEM is lexicographical so you need all action numbers to have the same number of digits in order for the action sequence to remain as provisioned.  The regexp you have is valid but does not contain the correct syntax to parse out data as its missing the ()parens.

updated Policy

event manager applet SHUT_NO_SHUT_UPLINK
 event none
 action 010 syslog msg "started after 60s"
 action 020 cli command "enable"
 action 030 cli command "configure terminal"
 action 040 cli command "do show interfaces description | include LTE network"
 action 050 regexp "^([A-Za-z0-9\/]+)" "$_cli_result" match interface
 action 060 syslog msg "$interface brought up by EEM script"
 action 070 cli command "interface $interface"
 action 080 cli command "shutdown"
 action 090 wait 10
 action 100 syslog msg "waited 10s"
 action 110 cli command "no shutdown"
 action 120 cli command "end"

test

INTERNET#event manager run SHUT_NO_SHUT_UPLINK

*May 16 20:54:17.499: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: started after 60s
*May 16 20:54:18.638: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: Gi3 brought up by EEM script
*May 16 20:54:21.164: %LINK-5-CHANGED: Interface GigabitEthernet3, changed state to administratively down
*May 16 20:54:22.164: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet3, changed state to down
INTERNET#
*May 16 20:54:29.261: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: waited 10s
INTERNET#
*May 16 20:54:29.778: %SYS-5-CONFIG_I: Configured from console by notAuser on vty0 (EEM:SHUT_NO_SHUT_UPLINK)
INTERNET#
*May 16 20:54:36.311: %LINK-3-UPDOWN: Interface GigabitEthernet3, changed state to up
INTERNET#
*May 16 20:54:37.312: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet3, changed state to up
INTERNET#

 

View solution in original post

2 Replies 2

Dan Frey
Cisco Employee
Cisco Employee

The action number in EEM is lexicographical so you need all action numbers to have the same number of digits in order for the action sequence to remain as provisioned.  The regexp you have is valid but does not contain the correct syntax to parse out data as its missing the ()parens.

updated Policy

event manager applet SHUT_NO_SHUT_UPLINK
 event none
 action 010 syslog msg "started after 60s"
 action 020 cli command "enable"
 action 030 cli command "configure terminal"
 action 040 cli command "do show interfaces description | include LTE network"
 action 050 regexp "^([A-Za-z0-9\/]+)" "$_cli_result" match interface
 action 060 syslog msg "$interface brought up by EEM script"
 action 070 cli command "interface $interface"
 action 080 cli command "shutdown"
 action 090 wait 10
 action 100 syslog msg "waited 10s"
 action 110 cli command "no shutdown"
 action 120 cli command "end"

test

INTERNET#event manager run SHUT_NO_SHUT_UPLINK

*May 16 20:54:17.499: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: started after 60s
*May 16 20:54:18.638: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: Gi3 brought up by EEM script
*May 16 20:54:21.164: %LINK-5-CHANGED: Interface GigabitEthernet3, changed state to administratively down
*May 16 20:54:22.164: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet3, changed state to down
INTERNET#
*May 16 20:54:29.261: %HA_EM-6-LOG: SHUT_NO_SHUT_UPLINK: waited 10s
INTERNET#
*May 16 20:54:29.778: %SYS-5-CONFIG_I: Configured from console by notAuser on vty0 (EEM:SHUT_NO_SHUT_UPLINK)
INTERNET#
*May 16 20:54:36.311: %LINK-3-UPDOWN: Interface GigabitEthernet3, changed state to up
INTERNET#
*May 16 20:54:37.312: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet3, changed state to up
INTERNET#

 

Thank you @Dan Frey, the script is now working.