Forum Discussion

Srinivasa_Chala's avatar
Srinivasa_Chala
Icon for Nimbostratus rankNimbostratus
Sep 17, 2018

Please assist me in creating irule

Hi All,

 

I need help in creating irule as i am new to F5. Please find the requirement details below.

 

Solution requirement : WebApplication running Hassle Free return application will make HTTPS API call to the F5 provided printer URL where : 1) F5 will provide HTTPs based DNS URL which will be mapped to multiple IP based printers located at corp. 2) Once received the request, F5 will terminate the HTTP connection at F5 and generate a HTTP call the printer hostnames ( or IP's). 3) F5 will use path based routing from request HTTPS URL to determine which specific printer this request need to be routed. 4) For a given URL like https://corpprinter.lsapps.net/{corpcode}/{printername}/ where {corpcode} and {printername} are dynamic elements, respective request will be routed to http://corpcode-printername.lsapps.net URL on F5.

 

Thanks!

 

4 Replies

  • what do you mean by "respective request will be routed to"? Do you mean the requested will be redirected or that it will push it to a different virtual server or it will send it to a specific node in the pool?

     

  • Hi Pete,

     

    Thanks for your reply!

     

    Answer: It has to send it to a specific node.

     

    Thanks!

     

  • Hi,

    here is a good base to start. Once we reach our goal we can optimize the IRULE.

    So first of create a pool "pool-printer" with all your printer, suppose your printer listen on port 80:

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/corpcode1/printername1/" {
            HTTP::uri http://corpcode1-printername1.lsapps.net
            pool pool-printer member 10.10.10.1 80
        }
        "/corpcode2/printername2/" {
            HTTP::uri http://corpcode2-printername2.lsapps.net
            pool pool-printer member 10.10.10.2 80  
        }
        "/corpcode3/printername3/" {
            HTTP::uri http://corpcode3-printername3.lsapps.net
            pool pool-printer member 10.10.10.3 80  
        }
        default { 
             nothing 
        }
      }
    }
    

    that's what I understood from your request if you see some things inconsistent, keep me update.

    regards,

  • Hi,

     

    you can use following code (not tested)

     

    It retrieve printer name, resolve printer address with DNS servers in pool p_dns, then define as

     

    when HTTP_REQUEST {
        if {[scan [HTTP::uri] {/%[^/]/%[^/]/} corpcode printername] == 2} {
            set printer "${corpcode}-${printername}.lsapps.net"
                HTTP::path [string map "/${corpcode}/${printername}/ /" [HTTP::path]]
                foreach dns [active_members -list p_dns] {   
                 Check if the first list element was empty
                if {[set dest [lindex [RESOLV::lookup @[lindex $dns 0] -a $printer] 0]] ne ""} {
                     Set Node IP based on DNS resolution
                    node $dest 80
                    break
                }
            }
        }
    }