1

I'm wondering if it's possible to build an EEM script that will shutdown, wait, and then enable a router interface based on a syslog message. I know I can get this to work if I specify the interface in the log message and in the action, but I want to know if its possible to use one script for multiple interfaces. He's an example of the script I planned to implement:

event manager applet interface_Shutdown
 event syslog pattern "(Tunnel2) is down: retry limit exceeded"
 action 1.0 cli command "enable"
 action 1.5 cli command "config t"
 action 2.0 cli command "interface Tunnel2
 action 2.5 cli command "shutdown"
 action 3.0 wait 360
 action 3.5 cli command "no shutdown"
 action 4.0 cli command "end"

Is there a variable I can use for the tunnel interface number that will allow me to run this one script that will work for all my tunnel interfaces? Or do would have to create a script for each one?

1
  • If my/any answer resolved your problem, please consider marking it as the accepted answer. Alternatively, you can post your own answer and mark that. Either will keep this from popping up as unresolved.
    – Jesse P.
    Commented Apr 24, 2022 at 15:33

2 Answers 2

3

For automating the shutdown and no shutdown of multiple interfaces in a sequential range, you would be best not to use entirely EEM but rather a combination of EEM and TCL scripting (EEM to monitor the event and trigger the launching of a TCL script).

First, you need to create your TCL script and store it on the flash or bootflash partition of the device. An example of a single script (without a pause) for what you want to do could be something like:

for {set i 0} {$i <= 9} {incr i} {
set var Tunnel
append var $i
exec "interface $var"
exec "shutdown"
exec "no shutdown"}

Then you can create your EEM applet as you need to, with the first action line being your "enable" command and the next being a call to launch the TCL script you just created. For example:

event syslog pattern "(Tunnel[0-9]) is down: retry limit exceeded"
action 1.0 “enable”
action 1.5 cli command "tclsh flash:shut_no-shut_tunnels.tcl"

If you want to have a pause for 360 seconds between the shutdown and no shutdown commands, you could easily just break apart the script into 2 scripts (one to shutdown and the other to no shutdown). For example:

Shutdown:

for {set i 0} {$i <= 9} {incr i} {
set var Tunnel
append var $i
exec "interface $var"
exec "shutdown"}

No Shutdown:

for {set i 0} {$i <= 9} {incr i} {
set var Tunnel
append var $i
exec "interface $var"
exec "no shutdown"}

Just name the files accordingly and reference them in separate actions in your EEM applet as needed, such as:

action 1.5 cli command "tclsh flash:shut_tunnels.tcl"
action 2.0 wait 360
action 2.5 cli command "tclsh flash:no-shut_tunnels.tcl"

If you insist on using solely EEM, there are some variables you can use to extract the information you seek. Using the command show event manager detector syslog detailed will show you a list of available variables in both TCL and EEM applet format/syntax.

So, you could use a combination of Regular Expression and these variables to handle this task.

An example of such an EEM applet to do this could be:

event manager applet interface_Shutdown
 event syslog pattern "(Tunnel[0-9]) is down: retry limit exceeded"
 action 1.0 regexp "(Tunnel[0-9]) is down: retry limit exceeded" "$_syslog_msg" match intf
 action 1.5 cli command "enable"
 action 2.0 cli command "configure terminal"
 action 2.5 cli command "interface $intf"
 action 3.0 cli command "shutdown"
 action 3.5 wait 360
 action 4.0 cli command "no shutdown"
 action 4.5 cli command "end"

Note: I have not tested that EEM applet to see if it works correctly. This is just an example.

1

Thanks for your input Jesse! After some trial and error, this is what I ended up using. Works like a charm!

event manager applet TUNNEL-FIX authorization bypass
event syslog pattern ".Tunnel([0-9]+). is down: retry limit exceeded" maxrun 400
action 1.0 regexp "Tunnel([0-9]+)" "$_syslog_msg" ifname
action 1.3 cli command "enable"
action 1.5 cli command "config t"
action 2.0 cli command "interface $ifname"
action 2.5 cli command "shutdown"
action 3.0 wait 310
action 3.5 cli command "no shutdown"
action 4.0 cli command "end"
action 4.5 syslog msg "$ifname brought up by EEM script"
1
  • Very nice. Happy to help.
    – Jesse P.
    Commented May 1, 2022 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.