cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

199
Views
0
Helpful
4
Replies
Highlighted
Beginner

EEM or TCL Ping with Variable

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:

 

  • Grep the first three octects of a specific interface or the entire address and parse so that only the first three octects remain.
  • Construct an array containing those prefixes and a pre-determined block of IPs (say .7 to .11).
  • Execute a continuous ping to those devices, or a ping every 60 seconds if that's possible.
  • Save the configuration and have the script run at all times, starting whenever the device boots or whenever the service fails.

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

 

 

4 REPLIES 4
VIP Advisor

Re: EEM or TCL Ping with Variable

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.

Everyone's tags (1)
Beginner

Re: EEM or TCL Ping with Variable

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

VIP Advisor

Re: EEM or TCL Ping with Variable

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.

 

 

 

Beginner

Re: EEM or TCL Ping with Variable

Hi Seb,

Thanks allot. We test this .

Br,
Jean
CreatePlease to create content
Content for Community-Ad
FusionCharts will render here