Forum Discussion

gdoyle's avatar
gdoyle
Icon for Cirrostratus rankCirrostratus
Oct 31, 2018

Return active pool members from log local0. in an irule?

Is it possible to list the active pool members for a specific pool using the log local0. logging command in an irule?

 

I'm using a maintenance page that checks to see if certain pools are up based on the URI. If there are no active members up then it redirects the user to the maintenance page, but if there are some members active then the user is sent to that pool.

 

It doesn't appear to be working quite right (they claim to be getting the maintenance page all the time when the irule is applied regardless of pool member status). I'd like to insert some logging into the irule so I can see at which points, if any, it is hitting and working improperly.

 

Thanks.

 

  • Is it possible to list the active pool members for a specific pool using the log local0. logging command in an irule?

    Yes.

    Start with looking at: Pool Member Status HTML5 Page

    Instead of creating HTML content, just log to local0.

    e.g.

    when HTTP_REQUEST {
        set thispool "my_http_pool"
        foreach { pmem } [members -list $thispool] {
          log local0. "$thispool - [getfield $pmem " " 1] [LB::status pool $thispool member [getfield $pmem " " 1] [getfield $pmem " " 2]]"
        }
    }
    

    I hope this helps.

  • gdoyle's avatar
    gdoyle
    Icon for Cirrostratus rankCirrostratus

    So this is how my irule now looks. I have added in the above and am hoping I did it correctly. I was hoping someone could look it over and point out any issues they see (if any)? I'm not 100% certain I inserted the above logging statement for the pool members accurately. My irule is based on one Kevin Stewart helped me here: https://devcentral.f5.com/questions?pid=61854.

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
          "/place/portal" -
          "/place/portal/" -
          "/" { 
            HTTP::respond 301 "Location" "https://www.my-website.com/portal/my-website-com" 
           }
          "/redirect.nsf*" { 
    
     This section prints the active members in the SuperServers_pool to the logs
     if this section of the irule is invoked.
    
          set thispool "SuperServers_pool"
          foreach { pmem } [members -list $thispool] {
            log local0. "$thispool - [getfield $pmem " " 1] [LB::status pool $thispool member [getfield $pmem " " 1] [getfield $pmem " " 2]]"
           }
     
     This next section states that if there are more than 0 pool members are active in the SuperServers_pool 
     then the user is redirected there, else they are presented a Maintenance Page.
    
              if { [active_members SuperServers_pool] > 0 } {
              log local0. "Sending to the SuperServers_pool."
                  pool SuperServers_pool 
              } else {
              log local0. "Sending to MX Page for the SuperServers_pool."
                  HTTP::respond 503 content [ifile get "/external/my-website_MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
                  return
              }
          }
          "*/hrp/*" { 
    
     This section prints the active members in the PDFServers_Pool to the logs
     if this section of the irule is invoked.
    
          set thispool "PDFServers_Pool"
          foreach { pmem } [members -list $thispool] {
            log local0. "$thispool - [getfield $pmem " " 1] [LB::status pool $thispool member [getfield $pmem " " 1] [getfield $pmem " " 2]]"
           }
     
     This next section states that if there are more than 0 pool members are active in the PDFServers_Pool 
     then the user is redirected there, else they are presented a Maintenance Page.
    
              if { [active_members PDFServers_Pool] > 0 } {
              log local0. "Sending to the PDFServers_Pool."
                  pool PDFServers_Pool 
              } else {
              log local0. "Sending to MX Page for the PDFServers_Pool."
                  HTTP::respond 503 content [ifile get "/external/my-website_MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
                  return
              }
           }
          default { 
    
     This section prints the active members in the my-website.com_pool to the logs
     if this section of the irule is invoked.
    
          set thispool "my-website.com_pool"
          foreach { pmem } [members -list $thispool] {
            log local0. "$thispool - [getfield $pmem " " 1] [LB::status pool $thispool member [getfield $pmem " " 1] [getfield $pmem " " 2]]"
           }
     
     This next section states that if there are more than 0 pool members are active in the my-website.com_pool 
     then the user is redirected there, else they are presented a Maintenance Page.
    
              if { [active_members my-website.com_pool] > 0 } {
              log local0. "Sending to the my-website.com_pool."
                  pool my-website.com_pool 
              } else {
              log local0. "Sending to MX Page for the my-website.com_pool."
                  HTTP::respond 503 content [ifile get "/external/my-website_MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
                  return
              }
          }
        }
    
      log local0. "Inserting HttpsIndicatorHeader Value"
        HTTP::header insert HttpsIndicatorHeader True
    }