Interface Failsafe Monitor

Problem this snippet solves:

Another slick solution for a couple of common requirement in high performance environments: To fail over immediately when a physical network connection fails connectivity, or if the number of active members in a trunk falls below the configured minimum.

The first sample supports individual interface monitoring. The second supports the more complex trunk management.

How to use this snippet:

http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=166

Monitor Source: Interface Failsafe only

#!/bin/bash
# (c) Copyright 2007 F5 Networks, Inc.
# Kirk Bauer 
# Pass in each interface to monitor via the Arguments field in the GUI
# Collect arguments (first remove IP and port as we don't use those)
shift
shift
interfaces="$*"
b interface show > /tmp/b_interface_show
for i in $interfaces ; do
   status=`grep "^ *$i " /tmp/b_interface_show | awk '{print $2}'`
   if [ "$status" != "UP" ] ; then
      logger -p local0.notice "$MON_TMPL_NAME: interface $i is not up (status: $status)"
      exit 1
   fi
done
# All specified interfaces are up...
echo "up"
exit 0

Monitor Source: Interface Failsafe w/Trunk Minumum Active Members support

Code :

#!/bin/bash
# (c) Copyright 2007 F5 Networks, Inc.
# Kirk Bauer 
# Pass in each interface to monitor via the Arguments field in the GUI.
# Each interface may be one of the following:
#    Physical interface (1.1, 1.2, etc)
#    Name of a trunk (if at least one interface is up the trunk is considered up)
#    trunk=min where trunk is the name of the trunk and min is the minimum number
#       of physical interfaces in the trunk that must be up

# For example, the following arguments will make sure that the 1.1 interface is 
# up and test_trunk has at least two interfaces in it that are up:
#    1.1 test_trunk=2

# To test on command-line, use fillers for first two arguments:
#    /usr/bin/monitors/interface_monitor.sh X X 1.1 1.2 1.3 ...

# Collect arguments (first remove IP and port as we don't use those)
shift
shift
interfaces="$*"
b interface show > /tmp/b_interface_show
for i in $interfaces ; do
   if grep -q "^ *$i " /tmp/b_interface_show ; then
      # Physical Interface
      status=`grep "^ *$i " /tmp/b_interface_show | awk '{print $2}'`
      if [ "$status" != "UP" ] ; then
         logger -p local0.notice "$MON_TMPL_NAME: interface $i is not up (status: $status)"
         exit 1
      fi
   else
      # Not a physical interface, assume a trunked interface
      trunk="$i"
      reqcount=1
      if echo "$trunk" | grep -q '=' ; then
         trunk="$(echo "$i" | sed 's/=.*//')"
         reqcount="$(echo "$i" | sed 's/^.*=//')"
      fi
      upcount=0
      for status in `grep "$trunk" /tmp/b_interface_show | awk '{print $2}'` ; do
         [ "$status" == "UP" ] && upcount=$[$upcount+1]
      done
      if [ $upcount -lt $reqcount ] ; then
         logger -p local0.notice "$MON_TMPL_NAME: trunk $trunk is down (has only $upcount active interfaces, $reqcount required)"
         exit 1
      fi
   fi
done
# All specified interfaces are up...
echo "up"
exit 0
Published Mar 12, 2015
Version 1.0

Was this article helpful?