Forum Discussion

koen_51858's avatar
koen_51858
Icon for Nimbostratus rankNimbostratus
May 05, 2010

undefined procedure: else

Hi all.

 

 

Trying to create an irule that will allow only users from specific countries to access a specific webpage. Any other webpage from that pool however is free for the entire world to access.

 

 

With no experience whatsoever with irules or big-ip's I managed (with the excellent help of devcentral) to create a rule that would match my purpose. I'm however stuck at the very last detail. Even after checking the TCL references (http://www.tcl.tk/man/tcl8.4/TclCmd/if.htm) for the syntax and double checking brackets using notepad++ I cannot figure out what is wrong with my irule. Namely the"else" part of my if-function doesn't seem to be allowed.

 

 

When I try applying my irules to my big-ip 10.1.0 Virtual Edition I get the following error

 

 

I get the following error while applying it to the big-ip 10.1.0 Virtual Edition though: "01070151:3: Rule [test_rule] error: line 21: [undefined procedure: else] [else { comment not even correct page so direct pool access pool www.pool.be } ] "

 

 

Iis something you guys can help with? What is wrong with that else-statement at the end of my irule? Any assistance would be appreciated.

 

 

 

 

allow only belgium and czech repulic access to specific page, rest of pool is free for all

 

when HTTP_REQUEST {

 

if {

 

[HTTP::uri] equals "/test/test/test.aspx"

 

} then {

 

switch [whereis [IP::client_addr] country] {

 

BE {

 

comment BE

 

pool www.pool.be

 

}

 

CZ {

 

comment CZ

 

pool www.pool.be

 

}

 

default {

 

HTTP::redirect "http://www.test.be/no_auth.html"

 

log local0. "Access to [HTTP::uri] was attempted by [IP::client_addr] from [whereis [IP::client_addr] country]"

 

}

 

}

 

}

 

else {

 

comment not even correct page so direct pool access

 

pool www.pool.be

 

}

 

}

 

end iRule
  • Managed to find my own error. Solution here for reference.

     

    Apparently the else-part of the if-statement cannot be on a new line. It needs to follow on the same line as the closing bracket of the else-part.

     

     

    WRONG

     

     

    if {

     

    a=b

     

    } then {

     

    pool y

     

    }

     

    else {

     

    pool x

     

    }

     

     

     

    CORRECT:

     

    if {

     

    a=b

     

    } then {

     

    pool y

     

    } else {

     

    pool x

     

    }
  • e_candelas_2043's avatar
    e_candelas_2043
    Historic F5 Account

    I can't believe it, a so simple solution, but I guess it shouldn't be like that it should parse the syntax with out taking much attention whether is in a new line or not.

     

  • This was incredibly helpful koen, thank you very much for the solution.

     

    I'm going to have to remove a whole lot of new lines from my codes now XD