Forum Discussion

Mangretta's avatar
Mangretta
Icon for Nimbostratus rankNimbostratus
May 15, 2024

monitor a pool that consists of Linux Squid Servers

I am trying to monitor a pool that consists of Linux Squid Servers.  The issue I am having is when a squid servers service stops processing requests and the port 3128 is sgtill responding,
the pool members do not go down.  The squid server then starts to generate timeouts to the client.   
 
We have created a custom script/external monitor that does a CURL to a paticular destination while expecting a specific return string.  We used the following KB artical to 
attempt to monitor them (https://my.f5.com/manage/s/article/K31435017).   The issue is, When we apply the External monitor to the pool,  it has no way of accepting the UP or DOWN status that is being returned 
by the script. 
 
How do I tell the F5 to expect a receive string and remove the node from the pool using this external monitor.
 
Script:
 
# start sample script
#!/bin/sh
# (c) Copyright 1996-2007 F5 Networks, Inc.
#
# @(#) $Id: http_monitor_cURL+GET,v 1.0 2007/06/28 16:10:15 deb Exp $
# (based on sample_monitor,v 1.3 2005/02/04 18:47:17 saxon)
#
# these arguments supplied automatically for all external monitors:
# $1 = IP (IPv6 notation. IPv4 addresses are passed in the form 
#                         ::ffff:w.x.y.z
#                         where "w.x.y.z" is the IPv4 address)
# $2 = port (decimal, host byte order)
#
# Additional command line arguments ($3 and higher) may be specified in the monitor template
# This example does not expect any additional command line arguments
#
# Name/Value pairs may also be specified in the monitor template
# This example expects the following Name/Vaule pairs:
#  URI  = the URI to request from the server
#  RECV = the expected response (not case sensitive)
#
# remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
IP=`echo ${1} | sed 's/::ffff://'`
PORT=${2}
 
PIDFILE="/var/run/`basename ${0}`.${IP}_${PORT}.pid"
# kill of the last instance of this monitor if hung and log current pid
if [ -f $PIDFILE ]
then
   echo "EAV exceeded runtime needed to kill ${IP}:${PORT}" | logger -p local0.error
      kill -9 `cat $PIDFILE` > /dev/null 2>&1
fi
echo "$$" > $PIDFILE
 
# send request & check for expected response
website="https://mywebsite.com"
timeout_seconds=5
 
response_code=$(curl --write-out "%{http_code}" --silent --output /dev/null --max-time $timeout_seconds $website)
 
if [ "$response_code" == "200" ]; 
then
  rm -f $PIDFILE
  echo "UP"
  else
  rm -f $PIDFILE
#   echo "DOWN"
fi
exit
  • As per the original script you mentioned, the receive string must be tested using the script and not from the GUI config (RECV = the expected response).

    "if [ $? -eq 0 ]" checks if the last command was executed without errors, which seems to be always the case with your command.

    Additionally, whatever your script send to the standard output (wether UP or Down or Simpsons...) it will cause the member to be marked up. For a member to be marked Down the script should output nothing.

    So, to summarize, you must test for the receive string within your script, and you must not send data to standard output if the pool member has to be marked down.

    More on external monitors here: Overview of BIG-IP EAV external monitors (f5.com)

  • Ok.  I have adjusted the code and have proven that I am indeed receiving a 0 back but the pool does not come up.   Does anyone have any experience with this?  I am using the F5 KB article mentioned with no success. 

     

    Here is the updated script and output.

     

    # start sample script
    #!/bin/sh
    # (c) Copyright 1996-2007 F5 Networks, Inc.
    #
    # @(#) $Id: http_monitor_cURL+GET,v 1.0 2007/06/28 16:10:15 deb Exp $
    # (based on sample_monitor,v 1.3 2005/02/04 18:47:17 saxon)
    #
    # these arguments supplied automatically for all external monitors:
    # $1 = IP (IPv6 notation. IPv4 addresses are passed in the form 
    #                         ::ffff:w.x.y.z
    #                         where "w.x.y.z" is the IPv4 address)
    # $2 = port (decimal, host byte order)
    #
    # Additional command line arguments ($3 and higher) may be specified in the monitor template
    # This example does not expect any additional command line arguments
    #
    # Name/Value pairs may also be specified in the monitor template
    # This example expects the following Name/Vaule pairs:
    #  URI  = the URI to request from the server
    #  RECV = the expected response (not case sensitive)
    #
    # remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
    IP=`echo ${1} | sed 's/::ffff://'`
    PORT=${2}
     
    PIDFILE="/var/run/`basename ${0}`.${IP}_${PORT}.pid"
    # kill of the last instance of this monitor if hung and log current pid
    if [ -f $PIDFILE ]
    then
       echo "EAV exceeded runtime needed to kill ${IP}:${PORT}" | logger -p local0.error
          kill -9 `cat $PIDFILE` > /dev/null 2>&1
    fi
    echo "$$" > $PIDFILE
     
    # send request & check for expected response
    website="https://mywebsite.com.com"
    timeout_seconds=5
     
    curl -x X.X.X.X:3128 --silent --output /dev/null --max-time $timeout_seconds $website
     
    #if [ "$response_code" == "302" ]; 
    if [ $? -eq 0 ]
    then
      rm -f $PIDFILE
      echo "UP"
      else
      rm -f $PIDFILE
    #   echo "DOWN"
    fi
    exit
     
     
    Output from F5 command line:
     
    [admin@dc-pxy-rcp-f5a-inf-a1:Active:Changes Pending] / # curl  -x X.X.X.X:3128 https://mywebsite.com
    [admin@dc-pxy-rcp-f5a-inf-a1:Active:Changes Pending] / # echo $?
    0
    [admin@dc-pxy-rcp-f5a-inf-a1:Active:Changes Pending] / #