Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Webcast-Catalyst9k
New Member

Using EEM & tcl script to talk to a remote http server

I would like to use the eem and a tcl script to check for any new files to download from a remote http server. The eem would be used as a scheduler to invoke the tcl script - which would access the http server and download any new files (what will be ip phone config files) to the flash on the router.

Can anyone provide me with an example config for this?

thanks,

John.

19 REPLIES
Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

First, you should not be using EEM to execute a tclsh script. Instead, you should do everything in an EEM Tcl policy. Second, on what version of IOS will this policy run? If you already have the tclsh script to do the HTTP operations, please post that.

Blue

Re: Using EEM & tcl script to talk to a remote http server

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

There is already HTTP code built-in to EEM. that is why I asked about IOS version and whether or not he had existing code to do his HTTP operations.

Blue

Re: Using EEM & tcl script to talk to a remote http server

Could you list the minimum version of EEM/IOS required to get built-in http get support?

New Member

Re: Using EEM & tcl script to talk to a remote http server

I am running IOS version 12.4(15)T9 on an IAD 2431 router. I have not written the http get code yet.

thanks,

John.

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

This should do what you want. It requires three environment variables to be set (examples below):

event manager environment http_check_time 86400

event manager environment http_check_url http://host.company.com/file.txt

event manager environment http_check_fs flash:

The above will run the script every 24 hours, download file.txt from the given host, and save the file to flash:/file.txt.

New Member

Re: Using EEM & tcl script to talk to a remote http server

Thanks. I added the following to my config:

event manager environment http_check_url http://10.10.10.10/conf/test-tcl/file1.txt

event manager environment http_check_fs flash:

event manager environment http_check_time 60

event manager directory user policy "flash:/"

event manager policy tm_http_check.tcl

but saw the following in the debug:

%HA_EM-6-LOG: tm_http_check.tcl: "open flash: /file1.txt w"

%HA_EM-6-LOG: tm_http_check.tcl: Tcl policy execute failed: expected integer but got "w"

Any idea what might be wrong? (I set it to check every 60 secs just for testing)

thanks,

John.

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

Did you modify my script any? It looks like something might have been changed.

New Member

Re: Using EEM & tcl script to talk to a remote http server

I didn't modify it... I see there was a "w" at the end of this line:

set fd [open "${http_check_fs}/${fname}" "w"]

So i removed that... now when i run it i get what looks like a permissions error:

002067: .Aug 4 16:23:47.590: %HA_EM-6-LOG: tm_http_check.tcl: invalid access mode "/file1.txt": must be RDONLY, WRONLY, RDWR, APPEND, CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

The line should read:

set fd [open "${http_check_fs}/${fname}" "w"]

It could be that the file name is being found with an embedded space. Can you post an attachment of the device config and output (copied from the terminal), so I can check?

New Member

Re: Using EEM & tcl script to talk to a remote http server

Config and debug attached.

thanks,

John.

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

Try this version.

New Member

Re: Using EEM & tcl script to talk to a remote http server

Thanks - the new script seems to be working. What was different? I diff'd the files - but didn't see anything.

Your script requires that you must enter a filename for the http_check_url variable. How much harder would it be to have it download all the contents of a directory? Or just the files that have changed since the last download?

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

The new script trims whitespace from the environment variables.

Loading all files in a directory over HTTP is non-trivial since you can't do a directory listing over HTTP. The way indexing works is that the web server generates an HTML page which lists the directory contents. Therefore, the client would need to parse the HTML data returns for the directory, and then make new HTTP requests for each file. This is doable, but as I said, it's not as trivial as doing this with a regular directory.

An alternative would be to tar up all of the files you want to download, then have the client download the tar file. IOS can easily work with tar files. You can then call the IOS archive command to extract the file. The new config files can be copied from a temp location to the final destination.

Clearly the latter method is the easiest.

New Member

Re: Using EEM & tcl script to talk to a remote http server

So could i accomplish what i am looking for just using the EEM? Something like this:

event manager applet LoadConfigFiles

event timer cron name "load_timer" cron-entry "0 23 * * *"

action 1.0 cli command "configure terminal"

action 1.1 cli command "file prompt quiet"

action 1.2 cli command "exit"

action 2.0 cli command "copy http://10.10.10.10/test-tar/files.tar flash:files.tar"

action 3.0 cli command "archive tar /xtract flash:files.tar flash:/"

Or is it better to use a policy tcl script?

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

Yes, this would work provided you add:

action 0.5 cli command "enable"

But you could further simplify this. Change action 2.0 to:

action 2.0 cli command "archive tar /xtract http://10.10.10.10/test-tar/files.tar flash:/"

Then remove action 3.0. The advantage of Tcl is that you could extract the tar file to a temp directory, then scan the files to see if any of them need to be installed. This may not be necessary given your end goal, though.

New Member

Re: Using EEM & tcl script to talk to a remote http server

If i were to use the above command - the applet would be simplified to the one action line, correct? This sounds good to me!

The tar file itself will include only files that have changed or are new in the remote directory - so yeah, having a temp dir on the router should not be necessary.

thanks again,

John.

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

At the very least you'd need two actions:

action 1.0 cli command "enable"

action 2.0 cli command "archive tar /xtract ..."

Cisco Employee

Re: Using EEM & tcl script to talk to a remote http server

Any device which supports EEM 2.1 should have the http library. This means IOS 12.3(14)T and higher, 12.2(18)SXF5 and higher, etc.

812
Views
5
Helpful
19
Replies
CreatePlease to create content