cancel
Showing results for 
Search instead for 
Did you mean: 

irule for extracting a string from a URI

DifanZ
Cirrus
Cirrus

Hi experts,

I am new to irule and it doesn't look like I am allowed much time to learn it properly... In short, they want me to redirect to a URL when all the members in the pool are down. The problem is that the redirect URL will need some data from the original URL.

 

Original -> http://ecmqut.network.qut/ecmlivelink/llisapi.dll/open/168812040

Redirect to -> http://csintqut.network.qut:81/fsl/Redirect.aspx?docid=168812040

 

As you can see, the number string is what I need to extract from the original URL. Here is my irule (that's not working)

when HTTP_REQUEST {   if { [active_members livelink_qut_tcp_8100_pool] < 1 } {     set doc_id [regexp \\/open\\/\(\\d+\)\[0-9\] [HTTP::uri] ] #    HTTP::redirect "http://outagemessage-qut.network.qut/"     log local0. “http://csintqut.network.qut:81/fsl/Redirect.aspx?docid=$doc_id” } }

 

As you can see, I am not even redirecting right now. I am just logging it to make sure it comes out right and it doesn't... I am getting error like

http_process_state_prepend - Invalid action:0x109010 Server sends too much data. serverside

 

Please help...

Thanks,

Difan

4 REPLIES 4

Jaspreetgurm
Altocumulus
Altocumulus

is this remain same "168812040" for all client connections ? or every connection gets different ID ?

Hey thanks Jaspreet. yes the number is dynamic. The length is also random...

SanjayP
MVP
MVP

You can try below.

 

when HTTP_REQUEST { if { ([string tolower [HTTP::uri]] starts_with "/ecmlivelink/llisapi.dll/open") and ([active_members livelink_qut_tcp_8100_pool] == 0) } { set doc_id [string range [HTTP::uri] 30 end] HTTP::respond 301 Location "http://csintqut.network.qut:81/fsl/Redirect.aspx?docid=$doc_id" return } }

 

Thanks Sanjay. The length might be dynamic and there could be at least a slash at the end of the link.. I actually opened a case and I am provided with a regular expression code like this

regexp "/open/(\[0-9\]+" $uri something doc_id

This successfully got me the number, regardless of the pending characters. But thanks anyway for your help!