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

HTTP action?

Jeremy Impson
Level 1
Level 1

Has there been any discussion of an applet action for HTTP POSTs and GETs? My environment is embedded & mobile, and other systems in it already use RESTful services for status, so I don't want to add an SNMP or SYSLOG server. I think I can do this in TCL, but didn't want to add knowledge of TCL to my dev team's required skill set until I'm certain that's the best way to go.

I'm an EEM newbie, and I know I'm likely to rehash a lot of stuff that's been put to bed, but I couldn't find a discussion so I thought I'd ask. I saw a DynDNS TCL script at https://supportforums.cisco.com/message/3953822#3953822 which will definitely work for my needs.

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

No.  Adding HTTP actions to applets i not something on our roadmap.  We do have that API in Tcl, though (HTTP 1.0 is built in to IOS).  Any kind of socket operations other than email, syslog, and SNMP will require Tcl.

View solution in original post

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

No.  Adding HTTP actions to applets i not something on our roadmap.  We do have that API in Tcl, though (HTTP 1.0 is built in to IOS).  Any kind of socket operations other than email, syslog, and SNMP will require Tcl.

I realize that a TCL policy is the right solution to my problem, but I obstinantly continued to try to find an applet solution. I'm glad I did, because I learned a few things. Below is a simple applet-based HTTP GET client using the copy CLI command with an http://  path as the source. The titchy part is that special work needs to be done to handle the "?" character (needed in HTTP to actually pass any information from the router to the web server via HTTP)

The idea is to use this kind of IOS CLI command:

Router#copy http://10.10.10.10/log?ifname=Vi2.11&name=mechanic&addr=10.10.69.23 flash:log

...as a way to push information to a web app (called "log" in this case).

Thanks to https://supportforums.cisco.com/thread/140658? for knowing about "Control-V" is an escape character to enter a "?" in to IOS command line.

But I found that I couldn't just pick up this command and put it in an EEM action cli command statement. When I did, the question mark was being stripped off before the HTTP request got to the web server. I fixed it by first embedding a Control-V (by doing Control-V Control-V) before embedding the ? (by doing Control-V ?). Apparantly there are two levels of interpolation by the IOS shell in this situation. So I created a variable called q for the ?, and another called cv for a Control-V. (Thanks to hint from https://supportforums.cisco.com/message/3681133.)

So here's the applet, but be wary that action lines 001 and 002 have to be hand typed because I'm sure the copy&paste from my terminal emulator into this web site, and the same from the web site to your terminal emulator, has stripped off the control characters.

event manager applet HTTPTEST

event none

action 001 set q ?            ! This must be Control-V then ?

action 002 set cv ^V         ! This must be Control-V then Control-V

action 010 cli command "enable"

action 020 cli command "configure terminal"

action 030 cli command "file prompt quiet"

action 040 cli command "end"

action 050 set url "http://10.10.50.13/log"

action 051 append url "$cv"

action 052 append url "$q"

action 060 append url "ifname=Vi2.11&name=mechanic&addr=10.10.69.23"

action 070 puts "$url"

action 080 cli command "copy $url flash:log"

action 090 cli command "enable"

action 091 cli command "configure terminal"

action 092 cli command "no file prompt quiet"

action 093 cli command "end"

To use, change action 050 to set the correct URL for your web server and web app, and action 060 to the information you want to send to the web server.

Does IOS have an equivalent to Unix /dev/null that I can use as the target of the CLI copy command?

Another note: The IOS copy command can also use an http:// path as the target of a copy ("copy flash: http:"). It appears to the the PUT command, which makes sense given its purpose. There doesn't appear to be a way to do POST (other than using TCL, which is what I'll do in the long run).

Glad you found a workaround.  The interesting thing about this is that this is a way to do https as well (whereas that won't work in Tcl).  But as you point out, this type of approach is limited to GET and PUT operations with very little overall control.  Tcl gives you POST as well as more robust session and user agent control.  But if this works, awesome!

Hello Jeremy,

 

Quick question, you're able to test it on your environment? I'm trying to do the exact same sequence to pasate the ? symbol into an http request but I can't figure it out why is it failing, here' some info:

 

Feb 22 16:18:05.992 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN  : Switch>enable
Feb 22 16:18:06.003 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : Switch#
Feb 22 16:18:06.008 ET:
Switch#%HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN  : Switch#more http://$user:$pass@dynupdate.no-ip.com/nic/update?hostname=$fqdn
Feb 22 16:18:06.029 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT :   http://$user:$pass@dynupdate.no-ip.com/nic/update A URL beginning with this prefix
Feb 22 16:18:06.029 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT :
Feb 22 16:18:06.029 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : Switch#
Feb 22 16:18:06.029 ET: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : CTL : cli_close called.

 

My Script is quite simple:

event manager applet ddns authorization bypass
 event none
 action 001 set q "?"
 action 005 set cv "^V"
 action 010 set noip "http://user:pass@dynupdate.no-ip.com/nic/update"
 action 015 append noip "$cv"
 action 020 append noip "$q"
 action 025 append noip "hostname=fqdn"
 action 030 puts "$noip"
 action 035 cli command "enable"
 action 040 cli command "more $noip"

 

Thanks

Review Cisco Networking for a $25 gift card