Forum Discussion
crodriguez
Oct 31, 2017Ret. Employee
iApps are fussy with brackets, braces, and quotes, and need a lot of escape characters, especially when creating an iRule. As a result, I like to set a variable to the iRule code string (with all the escape characters) and then refer to the variable on the tmsh::create command, rather than try to do it all on one command. Makes maintenance a bit easier, too:
set MyRule "
when HTTP_REQUEST \{
if \{ \[HTTP::uri\] starts_with \"/portal${app}_pool\" \} \{
pool ${app}_pool
\} else \{
TCP::close
\}
\}"
tmsh::create "/ltm rule ${app}_MyRule $MyRule"
Notice the braces in ${app} are not escaped so that the iApp processor will perform variable substitution when the application service is deployed. But all the braces, brackets, and quotes that need to be present in the finished iRule must be escaped.