Reload a router when ping fails

One of my readers has asked an interesting question: can you reload a router when pinging a specific IP address from it fails? While there are other ways of dealing with stuck interfaces or routing processes, sometimes such a drastic measure is the only workaround, so here's how you do it:

  • Configure an IP SLA measurement (you'll find the necessary commands in the Not-so-Very-Static Routes section of my IP Corner article Small Site Multihoming). You might want to use the after parameter in the ip sla schedule command to ensure the router does not get reloaded immediately after the startup due to IP routing table not being populated.
  • Configure a tracked object based on the IP SLA measurement with the track object-id rtr sla-id reachability command
  • Configure an EEM applet that will reload the router if the tracked object enters the down state
Use configuration similar to the one below for the EEM applet:
event manager applet PingHasFailed
event track 100 state down
action 1.0 syslog msg "Ping has failed, reloading the router"
action 2.0 reload
Note: this article is part of You've asked for it series.

8 comments:

  1. What about thresholds? I mean if just one ping failed my router will restarted.
    That's probably ip sla threshold-type consecutive but I'm unsure about this no tried yet

    ReplyDelete
  2. Looks like "The default number of 5 averaged measurements"

    ReplyDelete
  3. Now I figure out you how it works. Fisrt of all you SHOULD use IP SLA schedulde start-time NOW - not after.(If IP SLA not run track rtr generate down event)
    And after you enter command
    track object-id rtr sla-id reachability
    don't forget configure delay down 60 otherwise you got infinitive rebooting router, there no such thing like threshold in this.

    ReplyDelete
  4. event manager applet PingHasFailed
    event track 100 state down
    action 1.0 syslog msg "Ping has failed, reloading the router"
    action 2.0 reload

    I don't know why my 2811 router, IOS 12.4(13r) doesn't have command for event track ...
    When I type event ?, then I see the set of command as follow :(application,cli,counter,interface,ioswdsysmon,none,oir,snmp,syslog,timer)

    Is that event track command is lacking in this IOS, or it's replaced by other ?

    ReplyDelete
  5. Cisco documentation (http://www.cisco.com/en/US/docs/ios/12_4t/12_4t2/ht_eem.html#wp1080886) tells you that the event track command exists only in 12.4T images.

    ReplyDelete
  6. I don't want to use T images - so I do it this way
    event manager applet PingHasFailed
    event syslog pattern "\%TRACKING-5-STATE: 100 rtr 100 reachability Up->Down"

    ReplyDelete
  7. Ivan,

    I have done similar EEM scripts in my role. But I don't reload the router, I only reload the 3G-HWIC instead and I do it after I miss 8x IP SLA consecutive pings at 1min intervals and default ping timeout of 5s.

    I can share my config if you wish, let me know.

    Cheers,
    Joe.

    ReplyDelete
  8. Joe,

    do you still have that config?
    Can you pls share it?

    That would be really nice.

    Kind regards,
    Stefan

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.