cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1586
Views
0
Helpful
3
Replies

context_save and context_retrieve

Alex Steer
Level 1
Level 1

(attached tcl script at the bottom with some descriptions)

Hello,

I'm wondering if someone may be able to help me understand the context_retrieve and context_save commands please?

I'm trying to create a .tcl script that uses a counter to decide if something has happened a certain number of times.  As I understand it, normal variables are deleted after a script has finished running so it's not possible to use a typical variable to count if someone has happened between each run.  Joseph Clarke provided a great response to someone's similar question on this with regards to the context_save and context_retrieve commands that as I understand, allows the script to save a variable as 'something' external to the script itself.

I've been having trouble getting the most basic form of this command to work.  My attempts to experiment with either command shows me errors that suggests the router hasn't got a clue what I'm trying to do.  I thought perhaps that the syntax was wrong but I've been reading this document and haven't been able to see anything wrong.

http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/eem/configuration/12-4t/eem-12-4t-book/eem-context-tcl.html#GUID-BB5C5537-B72F-437E-8595-BD9A1B63A53C

I've also tried Joseph's example of the commands letter for letter (nested in if/else and catch statements in that example) and that doesn't appear to work either.  Could some help me with the following 4 questions please?

1.     Does anyway have any idea why my router is complaining about this command? (see below)

2.     I also have a question about the variable "counter" (in my example).  Does a script not need a "set counter" statement before the "context_retrieve" statement in a script to put the value of "MYCTXT" into it?

3.     What actually is a CTXT and where does it live/get stored?

4.     Does a CTXT need to be defined anywhere?

Many thanks in advance for any assistance,

Alex

(router output)

router(tcl)#context_retrieve MYCTXT counter

invalid command name "context_retrieve"

% Invalid input detected at '^' marker.

router(tcl)#set counter 15

15

router(tcl)#context_save MYCTXT counter

invalid command name "context_save"

% Invalid input detected at '^' marker.

router(tcl)#context_save MYCTXT $counter

invalid command name "context_save"

% Invalid input detected at '^' marker.

router#show event manager version

Embedded Event Manager Version 3.00

Component Versions:

eem: (v300_throttle)2.2.19

eem-gold: (v300_throttle)1.0.15

eem-call-home: (v300_throttle)2.0.4

Event Detectors:

Name                Version   Node        Type

appl                01.00     node0/0     RP

syslog              01.00     node0/0     RP

rf                  01.00     node0/0     RP

resource            01.00     node0/0     RP

routing             01.00     node0/0     RP

track               01.00     node0/0     RP

cli                 01.00     node0/0     RP

counter             01.00     node0/0     RP

gold                01.00     node0/0     RP

interface           01.00     node0/0     RP

ioswdsysmon         01.00     node0/0     RP

ipsla               01.00     node0/0     RP

none                01.00     node0/0     RP

nf                  01.00     node0/0     RP

oir                 01.00     node0/0     RP

snmp                01.00     node0/0     RP

snmp-notification   01.00     node0/0     RP

timer               01.00     node0/0     RP

test                01.00     node0/0     RP

config              01.00     node0/0     RP

env                 01.00     node0/0     RP

rpc                 01.00     node0/0     RP

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

The context_save and context_retrieve commands are not available in tclsh.  They are only available in EEM Tcl.  Your policy will work if you remove the tclsh constructs you have in it.  Plus, just by declaring something as a "main method" doesn't make it so.  Best not to use a function in your case.

View solution in original post

3 Replies 3

Joe Clarke
Cisco Employee
Cisco Employee

The context_save and context_retrieve commands are not available in tclsh.  They are only available in EEM Tcl.  Your policy will work if you remove the tclsh constructs you have in it.  Plus, just by declaring something as a "main method" doesn't make it so.  Best not to use a function in your case.

Joe,

As with the last time I asked you a question (about 12 months ago) what a fantastic response.

I was going down a bit of a rabbit hole trying to understand how to swap the tcl syntax with the IOS tcl/eem syntax. (forgive the terminology)

I've attached my working script with some descriptions in case anyone else wants to rob it.  I've also attached my poor attempt at trying to do what you'd described above without looking at your script (trying to figure it out myself).

Out of interest, any idea why this particular line was returning the entire "show ip interface $dialer" output in the logs during each run?

if { [ string first $noipaddress [ $commandOutput] ] >= 0 } {

    action_syslog priority warning msg \

        "$dialer has no ip address"

Again, many thanks for your help!

Started reading some of the presentations you put together for Ciscoline and bought another book too!

Alex

You don't want to include the $commandOutput in square braces.  What you want is:

if { [string first $noipaddress $commandOutput] >= 0 } {