05-01-2013 08:27 AM
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
Solved! Go to Solution.
05-01-2013 10:20 AM
Normally this would be done using contexts:
action context save:
http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-a1.html#wp1349683890
action context retrieve:
http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-a1.html#wp2399063000
Mike
05-01-2013 10:20 AM
Normally this would be done using contexts:
action context save:
http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-a1.html#wp1349683890
action context retrieve:
http://www.cisco.com/en/US/docs/ios-xml/ios/eem/command/eem-cr-a1.html#wp2399063000
Mike
05-01-2013 12:47 PM
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"
05-01-2013 12:50 PM
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.
05-01-2013 12:54 PM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide