Forum Discussion
LTM displaying notification based on matching muliple DNS alias/hostnames tied to the VIP
Hi All,
I have tired to get this working but it does not seem to be.
Here is what we need to do.
- When users comes in as or (DNS alias) that points to this same VIP, we want the F5 to look at the host header and take action based on that. Otherwise do nothing.
- Action needed/triggered when the come in as host1/host2 is to display the predefined message in this iRule. Under normal condition, this message should not be display to the users if they come in and their host header is other than "host1/host2". Example, they come in as http://mysite.com that dns points to this VIP, the F5 sees this and does not display the message.
Please let me know if this will work below. I am getting errors trying to get the code for the message to take. I think the sytax is incorrect.
Thank you for your help.
when HTTP_REQUEST {
Use the Host header value for the responses if it's set. If not, use the VIP address.
if {[string length [HTTP::host]]}{
set host [HTTP::host]
} else {
set host [IP::local_addr]
}
Check if the URI is /decommission-message
switch [HTTP::uri] {
"/decommission-message" {
Send an HTTP 200 response
HTTP::respond 200 content \
"Link Decommission Notification\
Dear All:
Please note that the site/domain for "Host1" and "Host2" will no longer be used.
We apologize for any inconvenience, please use "NewHostLink" instead.
Thank you.
" "Content-Type" "text/html"
return
}
}
switch [string tolower [HTTP::host]] {
"host1" -
"host2" {
HTTP::redirect "http://$host/decommission-message"
}
}
}8 Replies
- ekaleido
Cirrus
This might be a little simpler...
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "host1.com" || [string tolower [HTTP::host]] equals "host2.com" } { HTTP::respond 200 content \ "Link Decommission Notification\ Dear All: Please note that the site/domain for "Host1" and "Host2" will no longer be used. We apologize for any inconvenience, please use "NewHostLink" instead. Thank you. " "Content-Type" "text/html" } } Hi Tony,
you may try the iRule below as a starting point...
when HTTP_REQUEST { switch -exact -- [string tolower [HTTP::host]] { "host1" - "host2" { switch -exact -- [HTTP::uri] { "/decommission-message" { HTTP::respond 200 content " Link Decommission Notification Dear All: Please note that the site/domain for \"Host1\" and \"Host2\" will no longer be used. We apologize for any inconvenience, please use \"NewHostLink\" instead. Thank you. " "Content-Type" "text/html" } default { HTTP::redirect "/decommission-message" } } } } }Note: The line
contains a
variable that is not defined in this iRule. You have to check that the variable is defined somewhere else, otherwise the HTTP::response will throw an error.*$stimeCheers, Kai
- Tony2020
Nimbostratus
Hi Ekaleido,
I tried to use the code you suggested and got this error message. Do you know what is missing or where the issue is?
01070151:3: Rule [/Common/TEST-Message-V1] error: /Common/TEST-Message-V1:4: error: [undefined procedure: Link Decommission Notification]["Link Decommission Notification" \ Dear All: ] /Common/TEST-Message-V1:6: error: [undefined procedure: Please][Please note that the site/domain for "Host1" and "Host2" will no longer be used. ] /Common/TEST-Message-V1:7: error: [undefined procedure: We][We apologize for any inconvenience, please use "NewHostLink" instead. ] /Common/TEST-Message-V1:8: error: [undefined procedure: Thank][Thank you. ] /Common/TEST-Message-V1:9: error: [undefined procedure: "][" "Content-Type" "text/html" ] when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "host1.com" || [string tolower [HTTP::host]] equals "host2.com" } { HTTP::respond 200 content \ "Link Decommission Notification" \ Dear All: Please note that the site/domain for "Host1" and "Host2" will no longer be used. We apologize for any inconvenience, please use "NewHostLink" instead. Thank you. " "Content-Type" "text/html" } }- ekaleido
Cirrus
Hmm, it doesn't like the way the HTML is formatted in the iRule.
- Tony2020
Nimbostratus
is this because of the LTM code I am running or have they removed this feature? Running 11.5.3 currently. I looked on devc entral and the syntax seems to be correct.
- Tony2020
Nimbostratus
looks like you have to do it in this format now.
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "host1.com" || [string tolower [HTTP::host]] equals "host2.com" } { HTTP::respond 200 content { Link Decommission Notification\ Dear All: Please note that the site/domain for "Host1" and "Host2" will no longer be used. We apologize for any inconvenience, please use "NewHostLink" instead. Thank you. } } }
- Tony2020
Nimbostratus
Hi Kai,
Same thing...Error while trying to save this iRule. For some reason, it does not like the HTML parameters. I have removed the meta value for the refresh from this code as we probably do not need it.
01070151:3: Rule [/Common/TEST-Message-V1] error: /Common/TEST-Message-V1:20: error: [undefined procedure: ][ ] /Common/TEST-Message-V1:22: error: [undefined procedure: We][We apologize for any inconvenience, please use "NewHostLink" instead.] /Common/TEST-Message-V1:25: error: [undefined procedure: Thank][Thank you.] /Common/TEST-Message-V1:27: error: [undefined procedure: ][] /Common/TEST-Message-V1:28: error: [undefined procedure: ][] /Common/TEST-Message-V1:29: error: [undefined procedure: "][" "Content-Type" "text/html"] when HTTP_REQUEST { switch -exact -- [string tolower [HTTP::host]] { "host1" - "host2" { switch -exact -- [HTTP::uri] { "/decommission-message" { HTTP::respond 200 content " Link Decommission Notification Dear All: Please note that the site/domain for "Host1" and "Host2" will no longer be used. We apologize for any inconvenience, please use "NewHostLink" instead. Thank you. " "Content-Type" "text/html" } default { HTTP::redirect "/decommission-message" } } } } }Hi Tony,
sorry my fault. Missed to escape the
chars within the HTML. I've already updated my last post..."Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com