Adding Conditions to an EEM Script

Answered Question
May 19th, 2010
User Badges:

Hello


I have a script that reboots router if a ping (IP SLA) ha failed and the only issue with this is that if the site that I am pinging goes down, or the service provider goes down, the router will get cought in "reboot loop". Is there a way to add a condition saying that if the router has been up for X number if hours do not reboot or process the script.

Here is my script below.


Many thanks in advance


Jeff




ip sla 100

icmp-echo 192.168.1.25 source-interface Loopback0

timeout 500

frequency 10

ip sla schedule 100 life forever start-time now

!

event manager applet PingHasFailed

event track 100 state down

action 1.0 syslog msg "Ping has failed, reloading the router"

action 2.0 reload

Correct Answer by Joe Clarke about 7 years 5 days ago

Sure, you can add such a condition, but I'm not sure how checking for hours of uptime will prevent the loop.  That is, if the router reloads (for any reason), and when it comes back, the host in question is not reachable, then the router will still continue to reload.  What you might want instead is this to use nesting.  For example:


event manager environment quote "

!

event manager applet track-up

event track 100 state up

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "event manager applet track-down"

action 4.0 cli command "event track 100 state down"

action 5.0 cli command "action 1.0 syslog msg $quote Ping has failed, reloading the router$quote"

action 6.0 cli command "action 2.0 reload"

action 7.0 cli command "end"

!

event manager applet remove-track-down

event syslog pattern "SYS-5-RESTART"

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet track-down"

action 4.0 cli command "end"


Using these policies, you will only see the reload if the track had been up.  On a reload, the track-down applet (if it still exists) will be removed.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (1 ratings)
Loading.
Joe Clarke Wed, 05/19/2010 - 15:57
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

What version of IOS are you running?

Correct Answer
Joe Clarke Wed, 05/19/2010 - 16:10
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Sure, you can add such a condition, but I'm not sure how checking for hours of uptime will prevent the loop.  That is, if the router reloads (for any reason), and when it comes back, the host in question is not reachable, then the router will still continue to reload.  What you might want instead is this to use nesting.  For example:


event manager environment quote "

!

event manager applet track-up

event track 100 state up

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "event manager applet track-down"

action 4.0 cli command "event track 100 state down"

action 5.0 cli command "action 1.0 syslog msg $quote Ping has failed, reloading the router$quote"

action 6.0 cli command "action 2.0 reload"

action 7.0 cli command "end"

!

event manager applet remove-track-down

event syslog pattern "SYS-5-RESTART"

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet track-down"

action 4.0 cli command "end"


Using these policies, you will only see the reload if the track had been up.  On a reload, the track-down applet (if it still exists) will be removed.

Actions

This Discussion