Maintanance Irule two issues

Hi there,

We’ve build a cool maintanance Irule (With your help much appreciated)

when HTTP_REQUEST {
    switch [HTTP::uri] {
        "/index.css" {
            HTTP::respond 200 content [ifile get index.css] "Content-Type" "text/css"
        } 
        "/logo.gif" {
            HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
        }
        default {
            HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
                            return 0
        }
    }
}

This seems to work fine but there are several issues though. The first issue, and that’s why I’ve put the “return 0” in, is the combinantion with multiple Irules. Allthough I’ve put the return 0 in, I still see (In the logging) the next Irule is being hit and therefore the maintanance doesn’t show. So I have to remove all irules from the VS and just put the maintanance Irule on Why?

The second issue is for example I put the maintanance on a VS which listens to www.x.com So when I type www.x.com the maintanance page shows up. But for example when I type in www.x.com/something , the maintance text shows up but the images aren’t shown. I would like to see the images when I type www.x.com/something. Is there a way to optimize this Irule to achieve this?

heskez,

Just a comment about your first point and the other iRules firing. It’s my understanding that the connection won’t see individual iRules, as they all get compiled. As iRules are event based then all similar events across the iRules will be grouped together i.e. all HTTP_REQUESTS before any HTTP_RESPONSE events. The order of the iRule can order which commands fire first within similar events, or you can use the Priority Command on an event.

Hope I explained this sufficiently and gives you a bit of an insight.

Rgds N

Thanks for explaining nathan. I ordered the irules on the vs so the first one is the maintanance page irule. But if I understand you correctly, if the second irule contains a HTTP_REQUEST it will be hit?

Yes. You could set Priority of a event to order them. see: Priority

Thanks Nathan for explaining. And how about the second issue we get? :slight_smile:

Regarding the second issue, I’d suggest initially removing the ‘return 0’ from your rule. After that, if there’s no difference your best bet would be to do a packet capture client side and take a closer look at the request/response sequence.

Does your error.html have relative pathnames ? A browser developer tool will probably help you here (or HTTPWatch - that’s my fav tool apart from Wireshark).

Thanks, I’m trying HTTPWatch right now, very cool tool!

When I investigate with Element inspect from Google the location of the Ifile seems allright. I try to investigate further but I’m afraid that I’m stuck here.

The first issue, and that’s why I’ve put the “return 0” in, is the combinantion with multiple Irules. Allthough I’ve put the return 0 in, I still see (In the logging) the next Irule is being hit and therefore the maintanance doesn’t show. So I have to remove all irules from the VS and just put the maintanance Irule on Why?

you need event disable command.

event wiki

iRules: Disabling Event Processing by Deb Allen

The second issue is for example I put the maintanance on a VS which listens to www.x.com So when I type www.x.com the maintanance page shows up. But for example when I type in something (@something) / X , the maintance text shows up but the images aren’t shown. I would like to see the images when I type something (@something) / X. Is there a way to optimize this Irule to achieve this?

the image is not shown because the image request also contains /something (e.g. /something/logo.gif). the /something is included because you do not change url at client.

for workaround, you may adjust switch pattern (e.g. using glob-style matching) but you have to make sure it won’t conflict with server’s url.

hope this helps.

Thanks Nitass, so when I use something like this in mu irule it should show the images? set RequestedPath [string tolower [HTTP::path]] switch $RequestedPath { “/” { HTTP::respond 200 content [ifile get error.html] “Content-Type” “text/html” } }

Thanks Nitass, I’ve put an “event disable” in front of every section and now I can clearly see the maintanance page comes up with the images shown, it works great! So the first issue is resolved.

Concerning the second issue, most people have some favorite in their browser, so when they click there’s something like www.x.com/application/eninge the images of the maintanance page doesn’t show up. When I type www.x.com/application the images do show up! So, we’re almost there. So I’d like in the Irule something like redirect /application/engine to root path www.x.com. That would probably solve it. Is this the correct syntax?

set RequestedPath [string tolower [HTTP::path]] switch $RequestedPath { "/" { HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html" } }

Or what I actually want to do is

when HTTP_REQUEST {
if { [HTTP:uri] starts_with "/" }

"Call the script

Else

"Do something else"

Is that possible?

So I’d like in the Irule something like redirect /application/engine to root path www.x.com.

you can do but shouldn’t it be easier to use switch glob-style matching similar to this?

when HTTP_REQUEST {
  switch -glob [HTTP::path] {
    "*/index.css" {
      HTTP::respond 200 content [ifile get index.css] "Content-Type" "text/css"
    } 
    "*/logo.gif" {
      HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
    }
    default {
      HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
    }
  }
}

@Nitass: Thanks, I’ll give it a try!

I tried it but the problem is when an address is type like: http://www.x.com/something/somemoreinput The images aren’t shown. Also when typed something (@something) / X (notice the / at the end)

So the best thing to do I guess is call another script part or another irule from this irule with

when HTTP_REQUEST {
if { [HTTP:uri] starts_with "/" }

“Call the script”

I don’t see how i’m going to get this running with the global switch parameter.

I tried it but the problem is when an address is type like: http://www.x.com/something/somemoreinput The images aren’t shown. Also when typed something (@something) / X (notice the / at the end)

can you post the irule here?

Sure.

when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "/index.css" {
            HTTP::respond 200 content [ifile get index.css] "Content-Type" "text/css"
            event disable
        } 
        "/logo.gif" {
            HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
            event disable
        }
        "/corners2-grid1-half.png" {
            HTTP::respond 200 content [ifile get corners2-grid1-half.png] "Content-Type" "image/gif"
            event disable
        }
        "/body2-grid1-half.gif" {
            HTTP::respond 200 content [ifile get body2-grid1-half.gif] "Content-Type" "image/gif"
            event disable
        }
        "/canvas-bottom.png" {
            HTTP::respond 200 content [ifile get canvas-bottom.png] "Content-Type" "image/gif"
            event disable
        }
    "/default.jpg" {
            HTTP::respond 200 content [ifile get default.jpg] "Content-Type" "image/gif"
            event disable
        }
        default {
            HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
            event disable
        }
    }
}

did you forget to add asterisk (*) in switch pattern?

Where should i put the asterisk?