cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2819
Views
20
Helpful
11
Replies

how can i add the value of a string to another string in eem?

Hi,

i am trying to find out if it is possible to add a string value like "cisco" to another string like "test" to finally form |"ciscotest" using an eem applet/script or maybe in terminal shell ?

i am looking to do this:

i want to skim the sh log for instances of threshold violation on interfaces and using a regexp to retrieve the interfaces impacted from that output , this far i already got

I would like to add the matching results from this regex (foreach line in the log matching )  to a string

is there any way this can be done in eem?

Note, i am talking strings here, not integer values of a variable

 

 

 

 

2 Accepted Solutions

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

Take a look at the append feature in EEM applet to concatenate strings.

event manager applet test
 event none
 action 010 set var1 "cisco"
 action 020 set var2 "Rocks"
 action 030 append var1 "$var2"
 action 040 puts "$var1"
!
end

lab-csr2#event manager run test
ciscoRocks

View solution in original post

Attached is an EEM/TCL policy that should do most of what you need.   Presumably the syntax of the syslog message is:

%SFF8472-5-THRESHOLD_VIOLATION: Te1/9: Rx power low warning; Operating value: -13.8 dBm, Threshold value:  -9.9 dBm.

The policy is written to parse out the interface where Te1/9 is located.   The event triggers are to run manually or after reboot. Manual method is good for testing and change the reboot line to another event trigger if needed.  Instructions to load the policy are commented inside the .tcl file

::cisco::eem::event_register_timer tag tag1 cron cron_entry "@reboot" maxrun 30
::cisco::eem::event_register_none tag tag2

::cisco::eem::trigger {
    ::cisco::eem::correlate event tag1 or event tag2
}

View solution in original post

11 Replies 11

Hello,

 

what output exactly are you trying to get ? Concatenation of two strings is easy ("cisco" + "test" would result in "ciscotest").

 

Post the EEM script you have, and indicate what result you need.

 

 

Dan Frey
Cisco Employee
Cisco Employee

Take a look at the append feature in EEM applet to concatenate strings.

event manager applet test
 event none
 action 010 set var1 "cisco"
 action 020 set var2 "Rocks"
 action 030 append var1 "$var2"
 action 040 puts "$var1"
!
end

lab-csr2#event manager run test
ciscoRocks

Thanks Daniel,

 

i didn’t kniw it was that simple !

last question, is there a way to only get unique values from a given string?

lets say string containst he following:

 

one two four four four one five

desired output: one two four five

 

so basically ,what i want is to remove the duplicates ,and put the result in a new string.

is this possible too?

 

 

 

Easiest way to remove duplicates is to use the lsort  with the -unique flag  in TCL and this feature is not available in applet.  So you would need to write this in EEM/TCL in order to use lsort.    What are you trying to accomplish with the EEM policy?

 

lab-csr1#tclsh
lab-csr1(tcl)#set result [list one two four four four one five]
one two four four four one five
lab-csr1(tcl)#lsort -unique $result
five four one two
lab-csr1(tcl)#

 

 

 

 

Hi Daniel,

 

thanks yes i was aware that it was possible in tcl scripting but i got stuck with that approach since running an exec requires another VTY line to be active, so i was back to looking for a way to do it in eem..

 

Maybe it can be done using what is called "back referenced regex "it may be possible, but i am not so good at regex

 

Here's  what i am trying to do is this:

 

 show log | i TRHESHOLD_VIOLATION and get all the duplicates interface-names out for fiber links that are receiving high RX input (fiber uplinks)

the log contains multiple duplicates for several interfaces, and i want to keep a list of unique interfaces that are facing this problem. Then i want to iterate over that list of interfaces to get the sfp type with "sh inv $int" and get the neighbor device with "show cdp nei $int" to see what the other end has for an sfp

 

Attached is an EEM/TCL policy that should do most of what you need.   Presumably the syntax of the syslog message is:

%SFF8472-5-THRESHOLD_VIOLATION: Te1/9: Rx power low warning; Operating value: -13.8 dBm, Threshold value:  -9.9 dBm.

The policy is written to parse out the interface where Te1/9 is located.   The event triggers are to run manually or after reboot. Manual method is good for testing and change the reboot line to another event trigger if needed.  Instructions to load the policy are commented inside the .tcl file

::cisco::eem::event_register_timer tag tag1 cron cron_entry "@reboot" maxrun 30
::cisco::eem::event_register_none tag tag2

::cisco::eem::trigger {
    ::cisco::eem::correlate event tag1 or event tag2
}

thanks so much for your Help on this Daniel ,

i will need some time to process this one as my tcl skills are not at that level yet!

Awesome stuff im sure to learn a lot from this one!!

 

Hi Dan, 

I have run this applet on cisco 1121-4PLTEP to do LTE survey but my append cli command doesn't seem to work

 

conf t
event manager applet RSSI
event syslog pattern "SMS sender 1XXXXXXXXXX"
action 1.0 cli command "enable"
action 2.0 cli command "show cellular 0/2/0 radio | include Current RSSI "
action 2.5 set A $_cli_result
action 3.0 cli command "show cellular 0/2/0 radio | include Current RSRP "
action 3.5 set B $_cli_result
action 3.6 cli command "show cellular 0/2/0 radio | include Current RSRQ "
action 3.7 set C $_cli_result
action 3.8 cli command "show cellular 0/2/0 radio | include Current SNR "
action 3.9 set D $_cli_result
action 4.0 append A $B
action 5.0 puts $A
action 5.1 cli command "cell 0/2/0 lte sms send 1xxxxxxxxxx $A"
action 5.4 cli command " cell 0/2/0 lte sms delete all " pattern confirm
action 5.5 cli command " y "
!
end

 

Thanks

What is the output of each of the 4 CLI commands when you run them manually? What is the output of puts $A when EEM runs?

A shorter way to get the data would be this policy.

event manager applet RSSI1
 event none
 action 1.0 cli command "enable"
 action 2.0 cli command "show cellular 0/2/0 radio | include Current RSSI|Current RSRP|Current RSRQ|Current SNR"
 action 2.1 puts "$_cli_result"


C1111#event manager run RSSI1
Current RSSI = -88 dBm
Current RSRP = -118 dBm
Current RSRQ = -11 dB
Current SNR = 6.6  dB

this works for action puts

but doesn't work for  this command action 2.0 cli command "cell 0/2/0 lte sms send 1xxxxxxxxxx $_cli_result"

 

how can I combine 4 lines into one line string such that _cli_result holds value like this Current RSSI = -88 dBm, Current RSRP = -118 dBm, Current RSRQ = -11 dB, Current SNR = 6.6 dB? 

Current RSSI = -88 dBm
Current RSRP = -118 dBm
Current RSRQ = -11 dB
Current SNR = 6.6  dB

 

Review Cisco Networking for a $25 gift card