Forum Discussion

Mario's avatar
Mario
Icon for Nimbostratus rankNimbostratus
Oct 26, 2020

verify the length of a value in the header

Currently I need an iRule that verifies the amount of characters that a field has in the header, if a cell phone number arrives (10 digits) it is redirected to a VS, but if a land line number arrives (7 digits) it is redirected to another VS, is it possible to make an irule for this?

 

Header:

<name>operatorUserId</name> 

<singleValue>+573xxxxxxxxx</singleValue> 

</values> 

<values> 

<name>providerUserId</name> 

<singleValue>+573xxxxxxxxx</singleValue> 

</values>

3 Replies

  • I'm unsure if you're talking about HTTP header values or not or some other protocol considering your example shows XML content I'm assuming not HTTP?

     

  • Mario's avatar
    Mario
    Icon for Nimbostratus rankNimbostratus

    I have made this irule, but I do not know how verify the amount of characters

     

     when HTTP_REQUEST_DATA {

    set operatorUserId [findstr [HTTP::payload] "<operatorUserId"]

    if { [ string tolower $operatorUserId ] contains "10 characters" } {

    #log local0. "$operatorUserId "

    virtual VS_10_characters

    #log local0. "\[HTTP::payload\]: [HTTP::payload]"

    }

    if { [ string tolower $operatorUserId ] contains "7 characters" } {

    #log local0. "$operatorUserId "

    virtual VS_7_characters

    #log local0. "\[HTTP::payload\]: [HTTP::payload]"

    }

  • Here's what you can do, I've tested it, able to capture it fine.

        set digits [findstr [HTTP::payload] "<singleValue>" 13 "<"]
        log local0. "$digits & legth is [string length $digits]"

    Payload:

    <values>
    <name>operatorUserId</name> 
    <singleValue>1234567809</singleValue> 
    </values> 

    Output:

    <HTTP_REQUEST>: 1234567809 & legth is 10

    Payload:

    <values>
    <name>operatorUserId</name> 
    <singleValue>1234567</singleValue> 
    </values> 

    Output:

    <HTTP_REQUEST>: 1234567 & legth is 7

    Now with the length value, you can either set it on a variable and do a if condition and send to respective virtual. Hope it helps.