External monitor snmp - Member UP/DOWN

This external monitor uses the threshold of CPU and Memory for classify the pool member as available or down. I calculated the results of snmp to have the desired percentage.

Follow the steps:

1. Create the arquive called “script_snmp” in “/config/monitors/” and copy the script below:

!/bin/sh

IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)

IP=`echo ${1} | sed ‘s/::ffff://’`

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

kill -9 `cat $PIDFILE` > /dev/null 2>&1

fi

echo “$$” > $PIDFILE

send request & check for expected response

snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.4.5.0 > /var/tmp/monitor/mem_size_${IP}.log

snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.4.6.0 > /var/tmp/monitor/mem_avail_${IP}.log

snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.11.11 > /var/tmp/monitor/cpu_${IP}.log

mark node UP if expected response was received

size=`cat /var/tmp/monitor/mem_size_${IP}.log | cut -f4 -d" "`

avail=`cat /var/tmp/monitor/mem_avail_${IP}.log | cut -f4 -d" "`

expr $avail \* 100 / $size > /var/tmp/monitor/percentage_${IP}

memory=`cat /var/tmp/monitor/percentage_${IP}`

cpu=`cat /var/tmp/monitor/cpu_${IP}.log | cut -f4 -d" "`

if [ “$memory” -le “85” ]; then

if [ “$cpu” -ge “20” ]; then

echo “UP”

rm -f $PIDFILE

elif [ “$DEBUG” -eq “1” ]; then

echo “The threshold CPU has reached for $IP - DOWN” | logger -p local0.debug

rm -f $PIDFILE

fi

else

echo “The threshold MEMORY has reached for $IP - DOWN” | logger -p local0.debug

rm -f $PIDFILE

fi

2. Give permission by execution: chmod 755 script_snmp;

3. Create folder called “monitors” in “/var/tmp”;

4. In LTM/Monitors, click in “CREATE”

5. write the monitor name

6. Choice the monitor external type

7. Set the runtime

8. Set the path of script

9. In variable, set the value: DEBUG=1

10. Click in “FINISH”

11. Set the monitor the Pool

Feel free to improve the script

Hi Luis,

That looks great. Thanks for sharing the monitor script.

The only change I suggest is to do the PIDFILE removal before echoing anything to standard out, as the script execution will be stopped immediately at this point.

If you want, you could add this to the monitoring codeshare:

http://devcentral.f5.com/wiki/AdvDesignConfig.codeshare.ashx

Thanks, Aaron

Hi Aaron,

Thank for reponse!!!

I insert the PIDFILE in end script because not was functioning the script.

I think that “echo” was classify the pool member as “UP”

You can add thus script in codeshare.

Thanks!!!

Great script, thanks for sharing.

One typo I noticed in step 3, In var/tmp you want to create a folder called monitor not monitors as thats how its written in the script.

"3. Create folder called “monitors” in “/var/tmp”

Also in ver 11 you can import the script file via : System - File Management - External Monitor Program File List - Import.

Then you add the external monitor and under External Program choose that script you just imported from the drop down list, add your DEBUG = 1 variable and save.