Forum Discussion

AN_168028's avatar
AN_168028
Icon for Nimbostratus rankNimbostratus
May 31, 2018

iRULE to extract domain info from HORIZON VDI BROKER XML

I am surprised.. no one came across with this.. I am trying to read xml broker for Horizon VDI.. and get domain info out of it and redirect based on domain... Following iRULE I have

 

Code

        when HTTP_REQUEST {
        if { ( [HTTP::uri] contains "/broker/xml") and ( [HTTP::method] eq "POST")and ([HTTP::header Content-Length] == 395)}
        {
        HTTP::collect [HTTP::header Content-Length]
        }
    }

    when HTTP_REQUEST_DATA {
     Parse XML Data
    set xmlusername [findstr [HTTP::payload] "username" 22 ""]
    set xmldomain [findstr [HTTP::payload] "domain" 22 ""]
    log local0. "xmlusername check" $xmlusername

if {($xmlusername contains "user1")} 
    {
HTTP::redirect https://vdi1.abc.com
    }

}

above iRULE is not working I see hit count for HTTP_REQUEST but no HIT count for HTTP_REQUEST_DATA

 

1 Reply

  • Try adding some logging to the iRule to see if the URI, METHOD and Content-Length matches. I tested your iRule and in my lab it triggers the HTTP_REQUEST_DATA event.

    when HTTP_REQUEST {
        log local0. "uri: [HTTP::uri]"
        log local0. "method: [HTTP::method]"
        log local0. "content-length: [HTTP::header Content-Length]"
        if { ( [HTTP::uri] contains "/broker/xml") and ( [HTTP::method] eq "POST")and ([HTTP::header Content-Length] == 395)} {
            HTTP::collect [HTTP::header Content-Length]
        }
    }
    
    when HTTP_REQUEST_DATA {
        log local0. "HTTP_REQUEST_DATA triggered"
         Parse XML Data
        set xmlusername [findstr [HTTP::payload] "username" 22 ""]
        set xmldomain [findstr [HTTP::payload] "domain" 22 ""]
        log local0. "xmlusername check" $xmlusername
    
        if {($xmlusername contains "user1")} {
            HTTP::redirect https://vdi1.abc.com
        }
    }
    

    Output:

    Jun  1 14:28:54 nielsvs-bigip info tmm[13519]: Rule /Common/IRULE_XML : uri: /broker/xml
    Jun  1 14:28:54 nielsvs-bigip info tmm[13519]: Rule /Common/IRULE_XML : method: POST
    Jun  1 14:28:54 nielsvs-bigip info tmm[13519]: Rule /Common/IRULE_XML : content-length: 395
    Jun  1 14:28:54 nielsvs-bigip info tmm[13519]: Rule /Common/IRULE_XML : HTTP_REQUEST_DATA triggered