11-04-2019 08:19 AM - edited 11-04-2019 08:20 AM
I'm looking to deploy a script to over a 1,000 routers that can continually ping a range of IP addresses. I would like to do this on the routers as opposed to a central management platform and from what research I've performed, it looks like I can do so through EEM or TCL. The easy part is that the devices needing pinged all share the same block of IPs, but with every subnet being unique, I am looking for a way to push a single script to every router that will:
Can someone look at my EEM code I pieced together from code online and my pseudo code below and help with the last several lines--parsing the first three octets of the IP address, iterating from .7 to .11 and storing those in an array or individual variables and then pinging those IPs simultaneously, followed by a pause of one minute and then repeating line 70 ad infinitum:
event manager applet 100 event none action 10 cli command "en" action 20 cli command "show ip int br | i 0/0.XXX" action 30 foreach line "$_cli_result" action 40 regexp"([0-9]+\.[0-9]+\.[0-9]+\.+)" "$line" ip action 50 stores $ip + .7 in variable full_ip action 60 continues until .11 is reached action 70 pings .7 - .11 repeat five wait one minute action 80 line 70
11-05-2019 12:14 AM
Hi there,
Try the following (untested) EEM script:
action 10 cli command "en" action 20 cli command "show ip int br | i 0/0.XXX" action 30 foreach line "$_cli_result" action 40 regexp"([0-9]+\.[0-9]+\.[0-9]+\.+)" "$line" ip action 51 set foo 0 action 52 while foo le 1
action 53 set var 7 action 54 while $var le 12 action 55 cli command "ping $ip$var repeat 5" action 56 increment var action 57 end action 58 wait 60 action 58 end action 59 end
Note we are using the variable $foo to ensure the first while loop never exits. I'm sure this script will burn in hell because we should really be repeatedly calling it from the EEM manager and not getting it stuck in an infinite loop...but if should work :)
The alternative would look like:
event manager applet 100 event timer cron cron-entry "*/1 * * * *" action 10 cli command "en" action 20 cli command "show ip int br | i 0/0.XXX" action 30 foreach line "$_cli_result" action 40 regexp"([0-9]+\.[0-9]+\.[0-9]+\.+)" "$line" ip action 50 set var 7 action 51 while $var le 12 action 52 cli command "ping $ip$var repeat 5" action 53 increment var action 54 end action 55 end
The only problem I see with these scripts is that you have to wait for the ping command to complete for each IP iteration, therefore you are not sending the pings simultaneously as per your original requirement. Last time I checked EEM doesn't support threads.
cheers,
Seb.
12-03-2019 02:24 AM
Hello,
I want to be able to do a ping from all my interfaces on the router? Meaning can I script the ping to change the source interface on each ping?
Br,
Jean
12-03-2019 02:43 AM
Hi Jean,
Yes, you can add the source interface to the ping command, the result would like something like:
action 52 cli command "ping $ip$var repeat 5 source $intf"
...the challenge you would have is providing the $intf value. If you really want to source a ping from every interface then capturing the output from sh ip int br and then regexing for the IP addresses:
(\d{1,3}.){3}\d{1,3}
...list give you all of the IP addresses assigned to the router interfaces which you can then loop over.
cheers,
Seb.
12-03-2019 02:51 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide