Forum Discussion

Ken_McEwen_5009's avatar
Ken_McEwen_5009
Icon for Nimbostratus rankNimbostratus
Jan 18, 2006

Translating 4.5 i-rules to Ver 9

Help,

 

 

I have a some units on 4.5 that load balance by rules. I have to issues when I translate this to version 9.2

 

 

The first is as follows: -

 

 

elseif { [HTTP::payload length] < 20 } {

 

log "accumulating..."

 

Accumulate

 

}

 

 

the problem is that during programing this is accepted but when running the unit throws up an error saying does not reconise command accumulate. Does any one have any idea what this should be with the new syntax.

 

 

The second is to do with the regular expression syntax. The old syntax translates as follows (in theroy).

 

 

else {

 

if { [HTTP::header "X-WSB-msisdn"] matches_regex "[01234]$" } {

 

use pool mmsny1_pool

 

log "mms: 01234: NY"

 

}

 

elseif { [HTTP::header "X-WSB-msisdn"] matches_regex "[56789]$" } {

 

use pool mmsbe1_pool

 

log "mms: 56789: BE1"

 

}

 

else {

 

use pool mmsbe1_pool

 

log "mms: missed msisdn"

 

}

 

}

 

Problem is with the regular expression in the square brackets as per 4.5 the UIE rejects the script as it thinks this is a function. Removal of the square brackets prevents the script from compareing the regular expression. Any ideas on what replaces the square brackets.
  • For the accumulate question, you'll need to use the HTTP::collect method (if you are in an HTTP event which it looks like you are. For a HTTP request, here's is something that you could use to collect the payload:

    when HTTP_REQUEST {
       if { [HTTP::header exists "Content-Length"] } {
          set content_length [HTTP::header "Content-Length"]
       } else {
          set content_length 4294967295
       }
       if { $content_length > 0 } {
          HTTP::collect $content_length
       }
    }
    when HTTP_REQUEST_DATA {
       HTTP::payload will now contain the content
    }

    As for the matches_regex, you'll need to surround your regular expression with curly-braces.

    else {
      if { [HTTP::header "X-WSB-msisdn"] matches_regex {[01234]$} } {
        use pool mmsny1_pool
        log "mms: 01234: NY"
      } elseif { [HTTP::header "X-WSB-msisdn"] matches_regex {[56789]$} } {
        use pool mmsbe1_pool
        log "mms: 56789: BE1"
      } else {
        use pool mmsbe1_pool
        log "mms: missed msisdn"
      }
    }

    Another option would be to use the builtin TCL regexp command. That usage would be the following:

    else {
      if { [regexp {[01234]$} [HTTP::header "X-WSB-msisdn"]] } {
        use pool mmsny1_pool
        log "mms: 01234: NY"
      } elseif { [regexp {[56789]$} [HTTP::header "X-WSB-msisdn"] ] } {
        use pool mmsbe1_pool
        log "mms: 56789: BE1"
      } else {
        use pool mmsbe1_pool
        log "mms: missed msisdn"
      }
    }

    The TCL Reference for regexp gives an example of enclosing the variable in braces.

    http://tmml.sourceforge.net/doc/tcl/regexp.html

    Click here

    But, Regular expressions are very expensive resource-wise. If you are just looking for the last character to see if it's a number in your ranges, you could also do something like one of the following:

    else {
       extract last character in header
      set last [string last [HTTP::header "X-WSB-msisdn" end]
      if { ($last >= 0) && ($last <= 4) } {
          use pool mmsny1_pool
          log "mms: 01234: NY"
      } elseif { ($last >= 5) && ($last <= 9) } {
          use pool mmsbe1_pool
          log "mms: 56789: BE1"
      } else {
          use pool mmsbe1_pool
          log "mms: missed msisdn"
      }
    }

    -or-

    else {
       extract last character in header
      set last [string last [HTTP::header "X-WSB-msisdn" end]
      switch $last {
        0 - 1 - 2 - 3 - 4 {
          use pool mmsny1_pool
          log "mms: 01234: NY"
        }
        5 - 6 - 7 - 8 - 9 {
          use pool mmsbe1_pool
          log "mms: 56789: BE1"
        }
        default {
          use pool mmsbe1_pool
          log "mms: missed msisdn"
        }
      }
    }

    It's probably a toss up which one has lower overhead.

    -Joe