Forum Discussion

Manu_Nair's avatar
Manu_Nair
Icon for Cirrus rankCirrus
Apr 25, 2019

Redirect connection to a pool member based on http code

Hi, Our DB team has setup two POSTGRESQL servers and one is active and one is passive. They have come up with a request stating, is there anyway the LB can check HTTP error code, and if the error code returns 200 then the connection should go to that particular server.

 

I have seen here in DevCentral lot of posts about iRules checking for http codes. But i am a bit new and not sure about how can i achieve this.

 

So to summarize, the ask is.

 

if http error code is 200 in anyone of the server, then connect to that server.

 

4 Replies

  • Hi ShibuNair,

     

    the request sounds like you need to dive a little more into LTMs Health Monitoring.

     

    A Health Monitors probes your web application by sending HTTP requests to the individual Nodes of a given Pool and then mark the members either online or offline based on the received response.

     

    Your Virtual Servers will finally forward the traffic just to the servers which are marked online.

     

    Cheers, Kai

     

  • Hi ShibuNair,

     

    Without knowing anything else about your configuration, it sounds like you would be better served with a monitor attached to your pool instead of using an iRule. Health monitors check the availability of a pool member.

     

    First, I would look at creating a monitor of type PostgreSQL. That will actually query the database and may be more helpful in determining availability.

     

    Second, if a connection to your PostgreSQL server actually does return an HTTP response code, I would look at creating a monitor of type HTTP (or HTTPS) for your pool. You can use regex in the Receive String, something like '^HTTP\/1.(0|1)\s200' to ensure only a response of 200 is considered "available".

     

    Finally, if you are truly set on using an iRule, the iRule will need to send a request to your PostgreSQL server in order to get a response to inspect. You could use the "scan" command to inspect the HTTP response. Here is a good example: https://devcentral.f5.com/questions/choose-pool-based-on-http-response-54401

     

    Hope this helps.

     

    • Manu_Nair's avatar
      Manu_Nair
      Icon for Cirrus rankCirrus

      Thanks for the reply Krisdams,

       

      My setup is pretty basic :

       

       

      I think , i will go with your Plan.

       

      • However i need to know, do i need setup two health monitors..? 1) for postgresql and other for http code..? Not sure if there is a postgresql monitor available by default. Got to check.

         

      • Either one of the two server will be active per the DB team, so my assumption is the active one will always respond with http code 200. if it is yes, then the request will be forwarded to that server. And the other server will be down since it does not respond with http code 200, do you think this will work..?

         

    • krisdames_52343's avatar
      krisdames_52343
      Icon for Nimbostratus rankNimbostratus

      You do not necessarily need to configure two health monitors. You need to determine what is the best indicator of availability for your environment. If an HTTP response code of 200 is the best indicator for you, then you only need the HTTP/HTTPS health monitor. In that case, you are correct in that the other server would be marked as unavailable by the BIG-IP because it does not respond with the 200 code.