cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2513
Views
0
Helpful
4
Replies

EEM - Add cli data to different variables

fsebera
Level 4
Level 4

Hello, I'm hoping to get some help with my EEM script - I tried everything except what works.

 

My EEM script:

action A cli command "enable"

action B cli command "show crypto session | i port"

action C foreach BBBB "$_cli_result" "\n\n\s"

action D end

action E puts nonewline "BBBB=\n\n$BBBB"

action Z exit

 

 

Results:

BBBB=

 

 

Peer: 10.0.3.1 port 500

Peer: 10.0.2.1 port 500

Peer: 20.0.3.1 port 500

Peer: 20.0.2.1 port 500

 

What I am trying to accomplish is to get each of the 4 line IP addresses assigned to different variables. ANY help would be appreciated. 

 

Thank you

Frank

4 Replies 4

fsebera
Level 4
Level 4

...


UPDATE!!!!

 

I found if I use a different EEM feature I get closer to my goal but sadly still not 100%


Please note, I am attempting to make this script dynamic as possible by not nailing down the IP addresses as I support a test lab and I will not know the IP address in use up front.

Still hoping for help!!!

 

My NEW EEM script:

action A cli command "enable"

action B cli command "show crypto session | i port"

action C regexp "([1]+)([0-9.]+)([0-9.]+)([0-9]+)" "$_cli_result" IPADDR1

action D regexp "([2]+)([0-9.]+)([0-9.]+)([0-9]+)" "$_cli_result" IPADDR2

action E puts "IPADDR1 = $IPADDR1"

action F puts "IPADDR2 = $IPADDR2"

action Z exit

 

 

NEW Results:

IPADDR1 = 10.0.3.1

IPADDR2 = 20.0.3.1

 

 

ORIGINAL RESULTS:

Peer: 10.0.3.1 port 500

Peer: 10.0.2.1 port 500

Peer: 20.0.3.1 port 500

Peer: 20.0.2.1 port 500

 

So I now have about 50% but hoping for 100%!! I'll keep hacking away.

Thanks

Frank

Dan Frey
Cisco Employee
Cisco Employee

It would be easiest take actions as your iterating over the IP addresses in the foreach loop of the EEM applet.  Variable values are not persistent between scripts runs unless contexts are used.   EEM applets can not have a variable name that is itself a variable and you will need EEM TCL to do this.   Here is an example of an EEM TCL file that uses an array data structure to store and call the key value pairs and an example of storing the ip addresses to different variable names.

 

::cisco::eem::event_register_none

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

# Open the CLI

if [catch {cli_open} result] {

   error $result $errorInfo

} else {

    array set cli1 $result

}

# Go into enable mode

if [catch {cli_exec $cli1(fd) "en"} result] {

    error $result $errorInfo

}

if [catch {cli_exec $cli1(fd) "show ip int brief | inc 10" } result ] {

        error $result $errorInfo

}

# stuff into array

set lines [split $result "\n"]

array set intfIps [list]

set counter 1

foreach line $lines {

    if  [regexp {(\d+.\d+.\d+.\d+).*} $line -> intfIp] {

        append intfIps(var$counter) $intfIp

        #create variables (var1, var2, etc..)

        set var$counter $intfIp

        incr counter

    }

}

# Get Array key value pairs

foreach {key value} [array get intfIps] {

    puts "key: $key value: $value"

}

catch {cli_close $cli1(fd) $cli1(tty_id)}

###########end

C1111#event manager run ipaddress2variable.tcl

key: var3 value: 10.249.249.1

key: var4 value: 10.128.128.1

key: var5 value: 10.129.129.1

key: var1 value: 10.253.254.1

key: var6 value: 10.130.130.253

key: var2 value: 10.129.130.1

Hi Daniel,

 

We are out of office every other week (Covid-19), thus delayed reply.

Thank you for your reply. I am considering looking into the "context" option first. If you have any helpful hints, I'd welcome them!!!!

 

Thank you

Frank

Review Cisco Networking for a $25 gift card