Forum Discussion

jkirankumar1993's avatar
jkirankumar1993
Icon for Nimbostratus rankNimbostratus
Feb 06, 2018

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
}

}

  }
}
  • 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][}]

     

  • Surgeon's avatar
    Surgeon
    Ret. 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

     

  • 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][}]

  • 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
    }
    
    }
    
      }
    }
  • 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

    } }

  • Surgeon's avatar
    Surgeon
    Ret. 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
        }
    

    }