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

carrying variables in applets

tblack
Level 1
Level 1

I am writing an applet that puts a record in the log when any output drops are seen in a 30 second window. I would like to have the log say something like - ouput drops have increased from X to Y, but I am having problems carrying the var from one applet instance to the next. Here is what I am playing with, any suggestions on how to either set a global or carry a variable from one instance to the next?

event manager environment _application_data1

event manager applet OutputPacketsDropped

event interface name GigabitEthernet0/1 parameter output_packets_dropped entry-op ge entry-val 1 entry-type increment poll-interval 30

action 2.0 syslog msg "value $_interface_name $_interface_parameter increased from $_application_data1 to $_interface_value"

action 3.0 set _application_data1 "$_interface_value"

action 5.0 set _exit_status "1"

Thanks

1 Accepted Solution

Accepted Solutions
4 Replies 4

mtimm
Cisco Employee
Cisco Employee

Thanks Mike,

It turned into this:

event manager applet OutputPacketsDropped

event interface name GigabitEthernet0/1 parameter output_packets_dropped entry-op ge entry-val 1 entry-type increment poll-interval 10

action 10.00 context retrieve key prev_drop variable "prev_drop"

action 20.00 syslog msg "value $_interface_name $_interface_parameter increased from $prev_drop to $_interface_value"

action 30.00 set prev_drop "$_interface_value"

action 40.00 context save key prev_drop

action 50.00 set _exit_status "1"

One thing you may want to add is

action 9.0 handle-error type ignore

In case the context was not yet created, you would hit a run time error which would terminate the script.

The above command should fix that.

Just for future references, I would like to add another way to maintain global counters

http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-a1.html#wp2528836556

The counters can be also used as events for other applets:

http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-e1.html#wp7592791630