Forum Discussion

EtienneMT_32950's avatar
EtienneMT_32950
Icon for Nimbostratus rankNimbostratus
Oct 04, 2017

APM irule event to check device serial number against and api.

Hi,

 

Is it possible to create and irule event to check "session.client.serial_number" against an API dump which must be downloaded on the fly from and url, and check "session.client.serial_number" against the value of a "serialnumber"

 

Any ideas on how to get about it please?

 

Regards, Etienne

 

1 Reply

  • Hi,

     

    You can create a HTTP auth to request API.

     

    if you have to manage in irule the response, you can create an virtual server to convert request / response from API to be managed in APM AAA HTTP Auth server.

     

    Access Policy --> HTTP auth --> virtual server with irule --> API server as pool

    the irule will insert in cookie / header information you can retrieve in variables.

     

    I wrote this irule applied to a virtual server API converter for air watch.

     

    when HTTP_REQUEST {
        set AWuser [URI::decode [URI::query [HTTP::uri] AWuser]]
        set AWpwd [URI::decode [URI::query [HTTP::uri] AWpwd]]
        set AwTenantCode [URI::decode [URI::query [HTTP::uri] AwTenantCode]]
        set b64auth [b64encode "$AWuser:$AWpwd"]
        HTTP::uri [HTTP::path][URI::query [HTTP::uri] uid]
        HTTP::header insert "aw-tenant-code" $AwTenantCode
        HTTP::header insert "Content-Type" "application/json"
        HTTP::header insert "Authorization" "Basic $b64auth"
        unset AWuser
        unset AWpwd
        unset b64auth
        unset AwTenantCode 
    }
    
    when HTTP_RESPONSE {
    
       Trigger collection for up to 1MB of data
      if {[HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] <= 1048576}{
        set content_length [HTTP::header "Content-Length"]
      } else {
          set content_length 1048576
      }
       Check if $content_length is not set to 0
      if { ([HTTP::status] == 200) && ($content_length > 0)} {
        HTTP::collect $content_length
      }
    }
    
    when HTTP_RESPONSE_DATA {
         do stuff with the payload
        set payload [HTTP::payload]
        foreach str {UserName Platform} {
            set strlengh [string length $str ]
            set fieldstart [expr {[string first "\"$str\":\"" $payload] +$strlengh +4}]
            set fieldEnd [expr {[string first "\"," $payload $fieldstart] -1}]
            set field [string range $payload $fieldstart $fieldEnd]
            HTTP::header insert $str $field
            HTTP::cookie insert name $str value $field
        }
    }