Simple IRule apparently not working

Greegings all.

We have the IRule below and when we install it and attempt to execute our web app, we see not messages in the log. We do not see any syntax errors messages either. Any ideas why we would be getting no output at all?

Thanks in advance for any and all help!

Earnie!

when RULE_INIT {
    log local0. "Earnies rule is being initialized"
  }
  when HTTP_REQUEST {
 Look of each entry in badurl in the URI
    set uri [HTTP::uri]
    log local0. "Checking uri: $uri"
    set badurl [list "http://ww1:80" "https://ww1:80"]
    foreach x $badurl {
      if {$uri starts_with $x} {
        set len [string length $x]
 Get all of the URI after the port number
        set resource [substr $uri $len]
        set outlocation "https://ww1$resource"
        log local0. "Changing request for $uri to $outlocation"
        HTTP::uri $outlocation
        break;
      }
    }
    
  }
  when HTTP_RESPONSE {
 If this is not a browser redirect, igonore it
    if {[HTTP::status] starts_with "3"} {
      set location [HTTP::header "Location"]
      if {$location == ""} {
        return
      }
    } else {
      return
    }
  
    log local0. "Checking location: $location"
 Look of each entry in badurl in the redirect location
    set badurl [list "http://ww1:80" "https://ww1:80"]
    foreach x $badurl {
      if {$location starts_with $x} {
        set len [string length $x]
 Get all of the URI after the port number
        set resource [substr $location $len]
        set outlocation "https://ww1$resource"
        log local0. "Rewriting $location to $outlocation"
        HTTP::header replace "Location" $outlocation
        break;
      }
    }
  }

There should definitely be some information sent to your log file with that rule in place, assuming you’re hitting the VIP it’s assigned to.

Which log file are you checking? /var/log/ltm?

-Colin

Do you have a oneConnect profile enabled?

I had a simple rule:

when HTTP_RESPONSE {

HTTP::header replace “Test” “test”

}

And the Test header was only added to about 10% of the responses. Without oneConnect it works.

In this case, a ONECONNECT profile shouldn’t make any difference over whether or not ANY log entries show up.

If you take a look at the beginning of the rule:

when RULE_INIT {
    log local0. "Earnies rule is being initialized"
  }

This event occurs when the rule is initialized (loaded into memory or modified), so it should occur at least once, no matter what.

So like I said, there shoudl be at least something in the log…

-Colin

Colin - Yes its the ltm log file im looking at, when we use the following code i get entries int he log file:

when RULE_INIT {

log local0. “Earnies rule is being initialized”

}

when HTTP_RESPONSE {

If this is not a browser redirect, igonore it

if {[HTTP::status] starts_with “3”} {

set location [HTTP::header “Location”]

if {$location == “”} {

return

}

} else {

return

}

log local0. “Checking location: $location”

Look of each entry in retidrect_rewrite in the redirect location

set badurl [list “http://ww1:80” “https://ww1:80”]

foreach x $badurl {

if {$location starts_with $x} {

set len [string length $x]

Get all of the URI after the port number

set resource [substr $location $len]

set outlocation “https://ww1$resource”

log local0. “Rewriting $location to $outlocation”

HTTP::header replace “Location” $outlocation

break;

}

}

}

But soon as we add additional items to this code like what Earnie posted above it then sends nothing to the logs (ltm).

And NO, one connect profile is not enabled , it is set to NONE.

thanks

To test this, I copied and pasted Earnie’s rule, the one listed in the initial post, into my bigip.conf file. I then reloaded the configuration, and I did indeed see the log entry sent to the log file, as you can see below:

b load

Reading configuration from /config/bigip_base.conf.

Reading configuration from /usr/bin/monitors/builtins/base_monitors.conf.

Reading configuration from /config/profile_base.conf.

Reading configuration from /config/daemon.conf.

Reading configuration from /config/bigip.conf.

Reading configuration from /config/bigip_local.conf.

Loading the configuration …

tail /var/log/ltm

Feb 16 08:21:10 bigip130 b: 010a0043:5: The configuration was successfully loaded.

Feb 16 08:21:10 tmm tmm[1012]: Rule : Earnies rule is being initialized

Are you not seeing even this entry?

-Colin

what log file are you seeing this? I add the irule through the gui interface on f5 under Local traffic, irulelist. then the Irule is added to the virtual server it belongs to. I then check the ltm log file and the log file under the gui and see not entries at all on either the gui log or right in the ltm log file itself.

The first version of his log file, the one in my post worked great and showed up in the logs, but not the new one which he posted.

maybe you have modified your syslog configuration?

it’s the file /etc/syslog-ng/syslog-ng.conf

I do see stuff in he ltm log now, didnt before but see some items now> when i did the b load from command line it seems to have worked. When i do the irule and click update from the gui it doesnt seem to work

Ah, you may be seeing CR54041 which can manifest itself as that an iRule doesn’t appear to change when being modified via the GUI. You can check your hotfixes to see if that is included in your current version.

FYI - I’ve seen this happen lots and didn’t know about the hotfix for it. A consistent workaround for me has been going back to the virtual server to which the iRule is attached and hitting “Update” there (even though there are no changes to the virtual server settings).

-Bill

i will probably have to call support on that, even though i see log entries now in the ltm log file, still not log entries show up under the logging on the gui under locak traffic and is should show up there also. thanks for everyones help, Earnie has figured it out and the rules are working, now just have to get the logging fixed. But thank you again!