Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

BIG IP F5 IRule with data group to check if date has passed

talsa
Nimbostratus
Nimbostratus

Hello,

I have a datagroup of kind string/external file, which has hosts on the first field, and dates with format YYYY-MM-DD on the second field. I want to create an irule that will do something when the date on the same row of the host has passed, or do something else if it doesn't.

Example:

"www.google.com" := "2020-04-16"

In this case I want to do something, and if the date was 2024-11-25 I would want to do something else.

Right now, it's not working for me, as I've tried with my Irule for a number of times. I am not even getting anything in the log.

My irule:

when HTTP_REQUEST priority 100 { if { not (
( [IP::addr [IP::client_addr] equals 1.1.0.0%2/15]) or
( [IP::addr [IP::client_addr] equals 2.2.4.0%2/24]) or
( [IP::addr [IP::client_addr] equals 3.3.23.0%2/24]) or
( [IP::addr [IP::client_addr] equals 4.4.41.0%2/24]) or
( [IP::addr [IP::client_addr] equals 5.5.66.0%2/24]) or
( [IP::addr [IP::client_addr] equals 6.6.236.65%2/24]) or
( [IP::addr [IP::client_addr] equals 7.7.151.0%2/24]) or
( [IP::addr [IP::client_addr] equals 8.8.6.0%2/23]) or
( [IP::addr [IP::client_addr] equals 9.9.8.0%2/21]) or
( [HTTP::host] ends_with "co.il") or
( [HTTP::host] ends_with "sites.example.com")
) } {

if { [string tolower [class match -name "[HTTP::host]" equals /Common/webrules_tal]] ne "" } {
set expire_date [clock scan { class match -value equals /Common/webrules_tal }]
log local0. "Got host address: [HTTP::host]"
if { [clock seconds] < [clock scan { "$expire_date" }] } {
HTTP::redirect "https://www.youtube.com"
}
}

}

}

How can I do something like this in my Irule?

Note: The IP address restriction above is to restrict by IP, these IP addresses are not mine, they're there just for this post.

Thank you!

Tal Sabadia

1 ACCEPTED SOLUTION

CA_Valli
MVP
MVP

So, this code will return the value of the date you've mapped to every host

 

when HTTP_REQUEST {
 set host [string tolower [HTTP::host]] 
 set now [clock seconds] ; log local0. "now is $now"
 set expire_date "1991-01-01"
 if { [class match $host eq test-string] }{ set expire_date [class match -value "$host" equals test-string] } else { log local0. "$host does not have a value in datagroup"}
 log local0. "expire date is $expire_date"
 set exp_clock [clock scan $expire_date]; log local0. "exp_clock is $exp_clock"
 
}

 

CA_Valli_0-1671616066682.png

Here's what variables look like

 

Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: now is 1603535987
Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: expire date is 2024-04-16
Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: exp_clock is 1713218400

Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: now is 1603536053
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: www.random.com does not have a value in datagroup
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: expire date is 1991-01-01
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: exp_clock is 662684400

 

View solution in original post

1 REPLY 1

CA_Valli
MVP
MVP

So, this code will return the value of the date you've mapped to every host

 

when HTTP_REQUEST {
 set host [string tolower [HTTP::host]] 
 set now [clock seconds] ; log local0. "now is $now"
 set expire_date "1991-01-01"
 if { [class match $host eq test-string] }{ set expire_date [class match -value "$host" equals test-string] } else { log local0. "$host does not have a value in datagroup"}
 log local0. "expire date is $expire_date"
 set exp_clock [clock scan $expire_date]; log local0. "exp_clock is $exp_clock"
 
}

 

CA_Valli_0-1671616066682.png

Here's what variables look like

 

Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: now is 1603535987
Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: expire date is 2024-04-16
Dec 21 12:39:47 bigip info tmm4[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: exp_clock is 1713218400

Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: now is 1603536053
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: www.random.com does not have a value in datagroup
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: expire date is 1991-01-01
Dec 21 12:40:53 bigip info tmm1[11336]: Rule /Common/iRule_DC <HTTP_REQUEST>: exp_clock is 662684400