Forum Discussion

Ron_130795's avatar
Ron_130795
Icon for Nimbostratus rankNimbostratus
May 07, 2014

iRule to catch 4xx and 5xx errors for specific server in a pool

How do I configure an iRule to catch/log 400 and 500 errors on a specific server in a specific pool. Also, where do I go to look at these logs when they are generated?

 

example server ip - 10.20.10.100

 

pool - test123

 

Thanks for any help

 

2 Replies

  • There are quite a few options:

    1. First, there's no specific reporting, per VIP, for server errors, for that you'd probably want to use an iRule attached to the VIP (in which case you've already narrowed it down to a specific VIP and pool)

    2. You could log the response status codes locally.

    3. You could log the response status codes remotely.

    4. You could increment a local "statistics" counter for a given set of status codes.

      when CLIENT_ACCEPTED {
          set hsl [HSL::open -proto UDP -pool syslog-pool]
          set clientip [IP::client_addr]
          set default_pool [LB::server pool]
      }
      when HTTP_RESPONSE {
          switch -glob [HTTP::status] {
              "40*" -
              "50*" {
                   local log: /var/log/ltm
                  log local0. "Client: \[$clientip\] received status code: \[[HTTP::status]\] from pool: \[$default_pool\]"
      
                   high speed remote log
                  HSL::send $hsl "<134>Client: \[$clientip\] received status code: \[[HTTP::status]\] from pool: \[$default_pool\]"
      
                   stats profile (update counter)
                  switch [HTTP::status] {
                      "401" { STATS::incr status_check 401 }
                      "404" { STATS::incr status_check 404 }
                      "500" { STATS::incr status_check 500 }
                  }
              }
          }
      }
      

    The local logs show up in /var/log/ltm in the shell or the LTM log in the GUI. Remote logs will get sent to a syslog server in your environment. The stats can be found under Local Traffic - Profiles - Other - Statistics, and then under the Statistics tab of a given stats profile.

  • OK, so, something like this;

     

    when HTTP_RESPONSE { 
     if { [HTTP::status] >= 400 } { 
     log local0. "[LB::server addr] in Pool:[LB::server pool] returned HTTP status: [HTTP::status]" }
    } 
    

     

    Alternatively, if you meant only log this for a specific server;

     

    when HTTP_RESPONSE { 
     if { ([LB::server addr] equals 10.20.10.100) && ([HTTP::status] >= 400) } { 
     log local0. “[LB:server addr] in Pool:[LB::server pool] returned HTTP status: [HTTP::status]” }
    }