For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Yann-Arzel_9990's avatar
Yann-Arzel_9990
Icon for Nimbostratus rankNimbostratus
Nov 26, 2013

Variable issue with iRule generated by IAPP

Hello,

 

I try to use an IAPP for setting up an iRule but I did not managed it when a variable is set on the iRule

 

Code :

 

proc create_iRule { irule_name } { set irule_buffer [string trim "{ when HTTP_REQUEST { set var 0 if { [string tolower [HTTP::path]] contains \"test" } { set var 1 } } when HTTP_RESPONSE { if { \$var == 1 } { HTTP::header insert \"Connection\" \"Close\" } unset var } }"]

 

tmsh_create "/ ltm rule" "$irule_name $irule_buffer" }

 

Indeed, I always get this error message (when I try to deploy a new Application Services) : script did not successfully complete: (can't read "var": no such variable

 

Do you know how to use iRule variable into an IAPP with 'string trim' method ? I try to 'escape' the $ character it without any success.

 

Thanks & Regards,

 

4 Replies

  • have you tried changing the delimiter type to single quotes? eg proc create_iRule { irule_name } { set irule_buffer [string trim '{ when HTTP_REQUEST { set var 0 if { [string tolower [HTTP::path]] contains "test" } { set var 1 } } when HTTP_RESPONSE { if { $var == 1 } { HTTP::header insert "Connection" "Close" } unset var } }'] If not, it may be because you haven't escaped the marks at the end of test : contains \"test" }
  • I think you need to escape the '$' before var - make it '\$'

     

    In my iApps, when I create an iRule, I have to escape the following characters:

     

    $ " [ ] \

     

    So, you may actually need to escape all of those.

     

    Also, check that you have matching {} and []. Your text ends with ']', but likely should be ending with '}'. But, I didn't look too in-depth. Just noticed that right as I was finishing with this post.

     

  • Hello Pete, thanks for your answer but I get an error when I try to save the IAPP when I try to change the delimiter type to single quotes! And yes, I miss one \ before test : \"test\" but it happens only when I copy/paste my code.
  • With a little digging through the existing templates this is the answer I found. You have to do a string replacement on a variable then it will take it:

    set APP_NAME $tmsh::app_name
    set ST_RULE {
        when HTTP_REQUEST {
         if { ([active_members -smoketest-pool] >= 1) and
           ([HTTP::header "smokeTestMode"] contains "enabled") }{
        pool -smoketest-pool
      }
      }
    }
    tmsh::create ltm rule ${RULE_NAME} \
      [string map " $APP_NAME" $ST_RULE]