cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
9952
Views
0
Helpful
16
Replies

EEM Ping Applet

Hello Community,

Can someone please show me how to add to the following EEM applet so as to add more ip addresses. I would like to add 172.7.7.1, 192.168.0.1, 10.1.1.1

event manager applet pingall

action 1.1 cli command "enable"

action 1.2 cli command "ping 141.231.45.133"

Cheers

Carlton

16 Replies 16

Community,

Ultimately, I would like to have the results of the ping appear in the cli.

Regards

Carlton

Depends on your version of code.  With EEM 3.0 you can do:

event manager environment hosts 141.231.45.133 10.1.1.1 11.1.1.1

event manager applet pingall

event none

action 1.0 cli command "enable"

action 2.0 foreach host $hosts

action 3.0  cli command "ping $host"

action 4.0  append results $_cli_result

action 5.0 end

action 6.0 puts $results

Joseph,

Thanks for that mate. I'm going to test it out now.

In the meantime, can you tell me what level of code the applet won't work with?

Also, can you tell me what codes won't show event manager version output?

Cheers

Carlton

This applet requires EEM 3.0 or higher.  To figure out exactly what version your device supports, see:

https://supportforums.cisco.com/docs/DOC-8799

That article covers all of the tips and tricks to figure out the version even if the "show event manager version" is not supported.  That said, if "show event manager version" is not supported, then you don't have EEM 3.0.

Joseph,

I converted the EEM Applet to Tcl using conversion tool here.

::cisco::eem::event_register_none

#
# This EEM tcl policy was generated by the EEM applet conversion
# utility at http://www.marcuscom.com/convert_applet/
# using the following applet:
#
# event manager environment hosts 10.36.36.225 10.36.36.227 10.50.131.34
# event manager applet pingall
# event none
# action 1.0 cli command "enable"
# action 2.0 foreach host $hosts
# action 3.0  cli command "ping $host"
# action 4.0  append results $_cli_result
# action 5.0 end
# action 6.0 puts $results
#

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

foreach host "host" {
    if [catch {cli_exec $cli1(fd) "ping $host"} _cli_result] {
        error $_cli_result $errorInfo
    }

    append results $_cli_result
}
puts $results

# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

However, when I issue the command:

'event manager run pingall',  I get the message

Translating "host"...domain server (255.255.255.255)

% Unrecognized host or address, or protocol not running.

Any ideas?

Hi Carlton,

The issue with the foreach loop.  The "host" list is a string but needs to be a variable, probably something like this should take care of it:

foreach host $hosts {
    if [catch {cli_exec $cli1(fd) "ping $host"} _cli_result] {
        error $_cli_result $errorInfo
    }

    append results $_cli_result
}

Disclaimer:  Not tested.

Mike

Mike

Going to try it now...

Hi Mike,

The script doesn't work. :-(

What error do you get?  You need to make sure you've done:

event manager environment hosts HOST_LIST

Where HOST_LIST is a space-separated list of IP addresses to ping.

Mike I amended the script as follows:

::cisco::eem::event_register_none

#
# This EEM tcl policy was generated by the EEM applet conversion
# utility at http://www.marcuscom.com/convert_applet/
# using the following applet:
#
# event manager environment hosts 10.36.36.225 10.36.36.227 10.50.131.34
# event manager applet pingall
# event none
# action 1.0 cli command "enable"
# action 2.0 foreach host $hosts
# action 3.0  cli command "ping $host"
# action 4.0  append results $_cli_result
# action 5.0 end
# action 6.0 puts $results
#

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

foreach host $hosts {
    if [catch {cli_exec $cli1(fd) "ping $host"} _cli_result] {
        error $_cli_result $errorInfo
    }

    append results $_cli_result
}

puts $results

# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

That first line of my sample needs to be configured under config t mode:

event manager environment hosts 10.36.36.225 10.36.36.227 10.50.131.34

That defines the hosts to ping.

Hi Joseph sorry it's taken so long to respond,

Anyway are you saying that the following would work

event manager applet pingall
event none
action 0.5 conf t "event manager environment hosts 10.36.36.225. 10.36.36.227"
action 1.0 cli command "enable"
action 2.0 foreach host $hosts
action 3.0 cli command "ping $host"
action 4.0 append results $_cli_result
action 5.0 end
action 6.0 puts $results

Cheers


Sent from Cisco Technical Support iPad App

Hi Carlton,

No, Joe is saying the following would work with EEM 3.0 or later:

event manager environment hosts 10.36.36.225. 10.36.36.227

event manager applet pingall

event none

action 1.0 cli command "enable"

action 2.0 foreach host $hosts

action 3.0 cli command "ping $host"

action 4.0 append results $_cli_result

action 5.0 end

action 6.0 puts $results

Or the following would work with any version of EEM that supports Tcl:

event manager environment hosts 10.36.36.225. 10.36.36.227

event manager directory user policy

event manager policy

For the applet, the foreach command was introduced in EEM 3.0, so that requires EEM 3.0 or later.  In both cases, you have to define the environment variable "hosts" so that the policy can use it.

Mike

Mike, apologies for late response - I'm in England.

Anyway, that appears to be working, however the script will only ping the last addres 10.36.36.227. Is there any reason why it won't ping 10.36.36.225?

Cheers

Review Cisco Networking for a $25 gift card