Forum Discussion

Bas_van_Velzen_'s avatar
Bas_van_Velzen_
Icon for Nimbostratus rankNimbostratus
Mar 09, 2016

A if statement in a Set statement?

Hello,

 

Im new to this, what I'm trying to do is:

 

I have got an vip that load balances traffic from several applications which create's a massive irule, im trying to make the irule a bit shorter by using variables. only certain pools are configured on different ports which can be identified with certain applications names.

 

so for example "abc" uses port 81 and "def" uses port 83.

 

I figured out the first part to check which Application it is about. set APP [lindex [split [HTTP::uri] "/"] 1]

 

Now I want to set the port to the correct one, and my thought was using a data-class the statement below does not work because frankly i'm not very good at these. set PORT [ if {${APP} equals class-test} {81} else {83} ]

 

can anybody help me find the correct syntax for this?

 

1 Reply

  • Hi Bas,

    to recycle the return value of

    [if]
    in such a way, it would be required to
    [set]
    the value within the
    {script
    } section...

    set PORT [if {${APP} equals class-test} then { set x 81} else {set x 83}]
    

    ... but this doesn't make any sense at all. It would be better to use just...

    if {${APP} equals class-test} then {
        set PORT 81
    } else {
        set PORT 83
    }
    

    Note: I didn't get the point of "data-class"? Do you want to use LTM datagroups to resolve the APP to PORT information?

    Cheers, Kai