Forum Discussion

Nathaneil0227_2's avatar
Nathaneil0227_2
Icon for Nimbostratus rankNimbostratus
Mar 22, 2016

iRule for HSL or logging etc

Hi Devcentrallers,

 

Do you have an iRule that will send logs with timestamp, clientIP, poolmember, vs that also have a condition if fails/success?

 

Any reply would be appreciated.

 

16 Replies

  • If this is for HTTP, I recommend using a Request Logging Profile:

    If that is not suitable, however:

    when LB_SELECTED {
        set hsl [HSL::open -publisher your_publisher]
        
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    

    If you wish to do this for HTTP, it's prudent to do this instead (if you want to log on each HTTP Request message):

    when CLIENT_ACCEPTED {
        set hsl [HSL::open -publisher your_publisher]
    }
    
    when HTTP_REQUEST {
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    
    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Hi Vernon, Thanks for this but how about for the application that I want to monitor? I mean not http my concern is Ive encountered traffic interuption when I put http profile.
  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    If this is for HTTP, I recommend using a Request Logging Profile:

    If that is not suitable, however:

    when LB_SELECTED {
        set hsl [HSL::open -publisher your_publisher]
        
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    

    If you wish to do this for HTTP, it's prudent to do this instead (if you want to log on each HTTP Request message):

    when CLIENT_ACCEPTED {
        set hsl [HSL::open -publisher your_publisher]
    }
    
    when HTTP_REQUEST {
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    
    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Hi Vernon, Thanks for this but how about for the application that I want to monitor? I mean not http my concern is Ive encountered traffic interuption when I put http profile.
  • The http profile itself should not interrupt traffic, though its application will cause the VS to drop any traffic that is improperly formatted HTTP (or which is not HTTP at all). It should also not cause any traffic drops at the moment it is applied.

     

    In any case, I admit that you follow-on question is somewhat unclear to me. When you write "... how about for the application that I want to monitor", do you mean that you want to log something from a BIG-IP monitor used to health check a pool member/node? Or do am I misreading your request?

     

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Vernon Hi! Apologies for misleading you. What I mean is I will also want iRule for success/fail but this time not for http. And I am little confused with the http profile due to I encounter problem on this. When I add http profile vs is not working but when I remove it is working
  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    The http profile itself should not interrupt traffic, though its application will cause the VS to drop any traffic that is improperly formatted HTTP (or which is not HTTP at all). It should also not cause any traffic drops at the moment it is applied.

     

    In any case, I admit that you follow-on question is somewhat unclear to me. When you write "... how about for the application that I want to monitor", do you mean that you want to log something from a BIG-IP monitor used to health check a pool member/node? Or do am I misreading your request?

     

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Vernon Hi! Apologies for misleading you. What I mean is I will also want iRule for success/fail but this time not for http. And I am little confused with the http profile due to I encounter problem on this. When I add http profile vs is not working but when I remove it is working
  • If you add the http profile to a Virtual Server that is receiving non-HTTP traffic, that traffic flow will fail (because the HTTP parser will reject the traffic). On the other hand, if you believe the traffic is in fact HTTP, then one of three things is happening:

    1. the traffic is malformed HTTP (in which case the HTTP parser rejects the message);
    2. the HTTP traffic violates http profile configured protections (for example, there is a maximum header size limit that is configurable on the profile. If a message is received with headers exceeding the limit, the message is dropped);
    3. you are encountering a bug (in which case, you should open a support case).

    At any rate, as I mention above, you can log any arbitrary traffic by using the CLIENT_ACCEPTED, LB_SELECTED or SERVER_CONNECTED events, all of which happen on any full-proxy connection. For example:

    when LB_SELECTED {
        set hsl [HSL::open -publisher your_publisher]
    
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    

    This assume the traffic is TCP. If it is UDP, the change each instance of

    TCP::
    to
    UDP::
    .

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Hi Vernon, but isnt it we need http profile to have an iRule? I really appreciate you buddy. Thanks.
  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    If you add the http profile to a Virtual Server that is receiving non-HTTP traffic, that traffic flow will fail (because the HTTP parser will reject the traffic). On the other hand, if you believe the traffic is in fact HTTP, then one of three things is happening:

    1. the traffic is malformed HTTP (in which case the HTTP parser rejects the message);
    2. the HTTP traffic violates http profile configured protections (for example, there is a maximum header size limit that is configurable on the profile. If a message is received with headers exceeding the limit, the message is dropped);
    3. you are encountering a bug (in which case, you should open a support case).

    At any rate, as I mention above, you can log any arbitrary traffic by using the CLIENT_ACCEPTED, LB_SELECTED or SERVER_CONNECTED events, all of which happen on any full-proxy connection. For example:

    when LB_SELECTED {
        set hsl [HSL::open -publisher your_publisher]
    
        HSL::send $hsl "[clock format [clock seconds]] [IP::client_addr] [LB::server name] [clientside {IP::local_addr}]:[clientside {TCP::local_port}]"
    }
    

    This assume the traffic is TCP. If it is UDP, the change each instance of

    TCP::
    to
    UDP::
    .

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Hi Vernon, but isnt it we need http profile to have an iRule? I really appreciate you buddy. Thanks.
  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    The application of the http profile is not necessary for iRules to work. It is necessary to utilize HTTP events (e.g., HTTP_REQUEST) and HTTP primitives (e.g.,

    HTTP::header
    ). However, events like CLIENT_ACCEPTED and LB_SELECTED are available with any layer4 profile, as are primitives such as
    IP::client_addr
    .

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Vernon Hi much thanks on this. it is clear on me now. Thanks again.
  • The application of the http profile is not necessary for iRules to work. It is necessary to utilize HTTP events (e.g., HTTP_REQUEST) and HTTP primitives (e.g.,

    HTTP::header
    ). However, events like CLIENT_ACCEPTED and LB_SELECTED are available with any layer4 profile, as are primitives such as
    IP::client_addr
    .

    • Nath's avatar
      Nath
      Icon for Cirrostratus rankCirrostratus
      Vernon Hi much thanks on this. it is clear on me now. Thanks again.