Tcl script convertion

Answered Question
Apr 8th, 2009

This message is for Joe Clark. I got referred to here from a TAC case.

Here is my problem. I am running 12.4(15)T7 on a 800 series router. I am using the event manager to kick off tcl scripts for various tasks. Because of problems in the event manager I had to upgrade my IOS to 12.4(22)T1. My registered policy looks like this:

2 applet user timer cron Off Thu Feb 28 19:01:12 2002 myApplet

cron entry {5,10,15,20,25,30,35,40,45,50,55 * * * *}

maxrun 20.000

action 1.0 cli command "enable"

action 2.0 cli command "tclsh flash:/tcl/myscript.tcl"

action 3.0 set _exit_status "1"

Now the TAC engineer told me that this is not the right way. The tcl script needs to be converted into a policy.

Joe can you give me the run down on this?



I have this problem too.
0 votes
Correct Answer by Joe Clarke about 7 years 6 months ago

Found it. You forgot a '#'.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (1 ratings)
hmaiwald Wed, 04/08/2009 - 09:44

It collects statistics from all configured SLAs, condenses them into a message, encrypts the message with RC4 and sends it via httpget to a pre-defined server

Joe Clarke Wed, 04/08/2009 - 09:51

Please post the script. Some of this can probably be converted to EEM Safe Tcl as-is, but some will probably need modification.

hmaiwald Wed, 04/08/2009 - 09:54

Joe, can you first tell me what is wrong with the way I am currently doing it? What are the drawbacks of running this as an applet?

Joe Clarke Wed, 04/08/2009 - 10:10

The interaction between EEM and tclsh has been known to be buggy. This was never officially tested, nor was EEM designed to spawn tclsh scripts. The reason for this is that EEM includes its own built-in Tcl. The recommended approach is to use an EEM Tcl policy if the applet conventions do not meet your needs.

Joe Clarke Wed, 04/08/2009 - 15:04

Here you go. This is untested as I do not have all of your Tcl libraries. The one thing that cannot be directly ported is the sourcing of these library files. You have two choices here. First, you can copy all of the contents of these files into the tm_oobsla.tcl script. This, of course, is not nice for code reuse.

The second choice is to generate an auto index file for all of these modules (you can leave out http.tcl as we already include this library with EEM). To create an auto index file, put all of these library files into one directory on a host which has tclsh. Then do the following from within the directory which contains the library files:

$ tclsh

% auto_mkindex . *.tcl

That will generate a tclIndex file. Copy this file along with all of the .tcl library files to a directory on the router (e.g. flash:/tcl). Then, configure this directory as the EEM user library directory:

event manager directory user library flash:/tcl

Then, copy the tm_oobsla.tcl script to the router. Put this file into another directory on flash. I recommend flash:/eem_policies. Then, configure this directory to be the user policy directory:

event manager directory user policy flash:/eem_policies

Finally, register the Tcl policy:

event manager policy tm_oobsla.tcl

If everything went right, it should just start working. If you run into problems, post the details

Joe Clarke Wed, 04/08/2009 - 15:15

One other thing. Your IOS version check needs to be updated for your current version of IOS. Right now, the policy will die if the IOS version is not 12.4(15)T7. You will need to change this check to 12.4(22)T1 to match your current version. If you leave it the way it is now, you will see a syslog message indicating that the IOS version is wrong.

hmaiwald Thu, 04/09/2009 - 09:39

Thanks Joe, I managed to convert all the sourced files and modify the script for the new condition. Still I get an error message that does not make sense to me when the policy is trying to run:

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: invalid command name "}"

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: while executing

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: "}"

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: invoked from within

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: "$slave eval $Contents"

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: (procedure "eval_script" line 7)

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: invoked from within

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: "eval_script slave $scriptname"

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: invoked from within

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: "if {$security_level == 1} { #untrusted script

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: interp create -safe slave

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: interp share {} stdin slave

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: interp share {} stdout slave

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: ..."

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)

Apr 9 13:35:01: %HA_EM-6-LOG: tm_oobsla.tcl: Tcl policy execute failed: invalid command name "}"

The error does not seem to come from my scripts. Any idea?

Joe Clarke Thu, 04/09/2009 - 09:50

I don't see how this error could be coming from the script I sent you. Can you post the script you're using along with the libraries? It looks like you have something like:

[ } ]



This Discussion