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.

6 comments:

Nikolay said...

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

Nikolay said...

Looks like "The default number of 5 averaged measurements"

Nikolay said...

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.

Anonymous said...

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 ?

Ivan Pepelnjak said...

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.

Andrey Yuspin said...

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"

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.