Forum Discussion
Irule to divert traffic - Not working
Can someone please review my code?
rule jiradivertingtraffic{
when HTTP_REQUEST {
log local0. "Request: [HTTP::host]"
log local0. "Request: [HTTP::uri]"
log local0. "Request: [HTTP::path]"
if { [string tolower [HTTP::host]] equals "jiratest.corp.chartercom.com" } {
if {[string tolower [HTTP::uri]] contains "/rest"} {
pool JIRA-test-pool
}
}
else {
if { [string tolower [HTTP::host]] not equals "jiratest.corp.chartercom.com" } {
if { [string tolower [HTTP::path]] equals "/login.jsp"} {
pool JIRA-test-pool
}
}
else {
pool JIRA-test-external-pool
}
}
}
}
- SurgeonRet. Employee
ok, code was reviewed. what is the question?
- jkirankumar1993Nimbostratus
I am getting few errors when trying to implement this code.
Here's the error that one gives: 01070151:3: Rule [/Common/jira-divertingtraffic] error: /Common/jira-divertingtraffic:1: error: [undefined procedure: rule][rule jira-divertingtraffic{] /Common/jira-divertingtraffic:7: error: [parse error: PARSE syntax 140 {syntax error in expression "class match [HTTP::uri] contains "/rest"": variable references require preceding $}][{class match [HTTP::uri] contains "/rest"}] /Common/jira-divertingtraffic:14: error: [undefined procedure: elseif][elseif {class match [HTTP::host] not equals "jiratest.corp.chartercom.com" } {
if {class match [HTTP::path] equals "/login.jsp"} {
pool JIRA-test-pool }
}] /Common/jira-divertingtraffic:23: error: [undefined procedure: else{][else{] /Common/jira-divertingtraffic:30: error: [command is not valid in the current scope][}]
- SurgeonRet. Employee
are you sure you provided us right irule? the error contains class match command which was not find in the provided irule. The rule name in error is different from the name of the irule in question
- jkirankumar1993Nimbostratus
Ah sorry. This is the irule I implemented before.
rule jira-divertingtraffic{ when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "jiratest.corp.chartercom.com" } { if {class match [HTTP::uri] contains "/rest"} { pool JIRA-test-pool } } elseif {class match [HTTP::host] not equals "jiratest.corp.chartercom.com" } { if {class match [HTTP::path] equals "/login.jsp"} { pool JIRA-test-pool } } else{ pool JIRA-test-external-pool } } } This is the error I got : 01070151:3: Rule [/Common/jira-divertingtraffic] error: /Common/jira-divertingtraffic:1: error: [undefined procedure: rule][rule jira-divertingtraffic{]
/Common/jira-divertingtraffic:7: error: [parse error: PARSE syntax 140 {syntax error in expression "class match [HTTP::uri] contains "/rest"": variable references require preceding $}][{class match [HTTP::uri] contains "/rest"}] /Common/jira-divertingtraffic:14: error: [undefined procedure: elseif][elseif {class match [HTTP::host] not equals "jiratest.corp.chartercom.com" } {
if {class match [HTTP::path] equals "/login.jsp"} {
pool JIRA-test-pool }
}] /Common/jira-divertingtraffic:23: error: [undefined procedure: else{][else{] /Common/jira-divertingtraffic:30: error: [command is not valid in the current scope][}]
- SurgeonRet. Employee
it looks like you did not configure data group to use class match https://clouddocs.f5.com/api/irules/class.html
 
- jkirankumar1993Nimbostratus
So will this code works ??
rule jiradivertingtraffic{ when HTTP_REQUEST { log local0. "Request: [HTTP::host]" log local0. "Request: [HTTP::uri]" log local0. "Request: [HTTP::path]" if { [string tolower [HTTP::host]] equals "jiratest.corp.chartercom.com" } { if {[string tolower [HTTP::uri]] contains "/rest"} { pool JIRA-test-pool } } else { if { [string tolower [HTTP::host]] not equals "jiratest.corp.chartercom.com" } { if { [string tolower [HTTP::path]] equals "/login.jsp"} { pool JIRA-test-pool } } else { pool JIRA-test-external-pool } } } }
- annliuAltostratus
firstly,class match need data group , secondly, not equals can be replaced by else.
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] equals "jiratest.corp.chartercom.com" } {
if { [HTTP::uri] contains "/rest"} {
pool JIRA-test-pool }
} else {
if { [HTTP::path] equals "/login.jsp"} {
pool JIRA-test-pool }
pool JIRA-test-external-pool
} }
- SurgeonRet. Employee
I would suggest.
when HTTP_REQUEST {
log local0. "Request: [HTTP::host]" log local0. "Request: [HTTP::uri]" log local0. "Request: [HTTP::path]" if { [string tolower [HTTP::host]] equals "jiratest.corp.chartercom.com" } { if {[string tolower [HTTP::uri]] contains "/rest"} { pool JIRA-test-pool } } elseif { [string tolower [HTTP::path]] equals "/login.jsp"} { pool JIRA-test-pool } else { pool JIRA-test-external-pool }
}
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