Forum Discussion
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
- PeteWhite
Employee
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" } - Richard_Jones
Nimbostratus
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.
- Yann-Arzel_9990
Nimbostratus
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. - wuench_99164
Altocumulus
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]
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com