Forum Discussion

Robberhines_120's avatar
Robberhines_120
Icon for Nimbostratus rankNimbostratus
Oct 14, 2013

Passing a variable through an iRule

We have the following maintenance test page, it's based off the standard maintenance page. What we are trying to do is create a dynamic maintenance page for each site(pool) so all we would have to do is just upload two ifiles and the irule wouldn't have to be adjusted. so lets say someones tries to go to www.abc.com, hits the F5, goes to the www.abc.com pool, however all of it's memebers are down. we have iFiles called www.abc.com.html and www.abc.com.jpg, the irule would find the files for www.abc.com and then display their own maintenance page. Later on we would add files for www.xyz.com and if www.xyz.com is down, their custom page would be displayed.

when CLIENT_ACCEPTED {
                    set default_pool [LB::server pool]
    }
    when HTTP_REQUEST { 
        set htmlfile
        set imagefile
        if { [active_members $default_pool] < 1 }{
            $htmlfile = lsearch -exact $default_pool.html
            $imagefile = lsearch -exact $default_pool.jpg
            log local0. $imagefile
                if{!($htmlfile equals $default_pool)} {
                    if { [HTTP::uri] contains $imagefile } { 
                    HTTP::respond 200 content [ifile get $imagefile] noserver "Cache-Control" no-cache "Server" 
                    } else {                
                    log local0. "[HTTP::host] for client [client_addr]"
                    HTTP::respond 200 content [ifile get $htmlfile] noserver "Cache-Control" no-cache "Server" 
                    }

            }
        }
    }  

with the above I get the following message when I tail the LTM log

err tmm[8134]: 01220001:3: TCL error: /Common/Maint_test - can't read "htmlfile": no such variable while executing "set htmlfile"

2 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Ah... You're a C programmer? Java perhaps? (I sympathise. I prefer C or perl myself. Hate Java). But I digress... This is TCL... The syntax for setting your variables is incorrect. You SET a variable to assign it a value. Not to declare it. So the

    set htmlfile
    

    doesn't need to be there (Unless you want toset it to some default value like

    set htmlfile ""
    

    Which gets rid of your first (And only reported so far) error. But the syntax where you set it to explicit values is also wrong for TCL. It should be something like

     set htmlfile [lsearch -exact $default_pool.html]
    

    But I'm unsure what you're trying to do there. leasrch searches a list... But $default_pool.html isn't a list... Reading the rest of the logic perhaps you just meant something like

    set htmlfile "$default_pool.html"

    Perhaps? As $htmlfile is supposed to be the name of a file to return the contents of?

    H

  • Hamish,

     

    the reason we are doing the lsearch is because the pool name may not always be www.abc.com, it might just be in as contoso.com with no www. So the lsearch is in there to locate the proper html and jpg in the LTM's ifiles location for the pool/site that is trying to be called. in our case we may have many different files for the number of domains we host.

     

    so you are correct in assuming what we are trying to do with $htmlfile (and $imagefile) is to get the corresponding file back from the list of ifiles we would have. again say the client accepted pool is just call abc.com but the file search comes back with www.abc.com.html, we would then want to display that html and jpg file