snmp-check external monitor

Problem this snippet solves:

This external monitor script runs an snmpget to pool members and marks the members up or down based upon the result. Specifically created for this GTM/APM use case, but can be modified as needed.

How to use this snippet:

copy the contents of this file into /config/monitors/snmp-check, and then in the external monitor configuration, reference the monitor and provide the following variable key/value pairs:


result=<result>

community=<community>

OID=<oid>

Code :

#!/bin/sh

#
# (c) Copyright 1996-2005 F5 Networks, Inc.
#
# This software is confidential and may contain trade secrets that are the
# property of F5 Networks, Inc.  No part of the software may be disclosed
# to other parties without the express written consent of F5 Networks, Inc.
# It is against the law to copy the software.  No part of the software may
# be reproduced, transmitted, or distributed in any form or by any means,
# electronic or mechanical, including photocopying, recording, or information
# storage and retrieval systems, for any purpose without the express written
# permission of F5 Networks, Inc.  Our services are only available for legal
# users of the program, for instance in the event that we extend our services
# by offering the updating of files via the Internet.
#
# @(#) $Id: sample_monitor,v 1.3 2005/02/04 18:47:17 saxon Exp $
#
#
# these arguments supplied automatically for all external pingers:
# $1 = IP (nnn.nnn.nnn.nnn notation or hostname)
# $2 = port (decimal, host byte order)
# $3 and higher = additional arguments
#
# $MONITOR_NAME = name of the monitor
#
# In this sample script, $3 is the regular expression
#

#These lines are required to control the process ID of the monitor
pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"

if [ -f $pidfile ]
then
   kill -9 `cat $pidfile` > /dev/null 2>&1
fi

echo "$$" > $pidfile

#Since version9 uses the ipv6 native version of the IP address, parse that down
#for usage

node_ip=`echo $1 | sed 's/::ffff://'`

#Log the variables for debugging
#echo IP= $node_ip Port =$2 OID= $OID comm= $community result= $result >> /var/tmp/test

#Create a variable called answer that contains the result of the snmpwalk.
answer=`snmpget $node_ip -c $community -O v $OID | awk '{print $2}'`

#Log the answer for debugging
#echo Answer= $answer >> /var/tmp/test


if [ $answer -lt $result ]
then
    echo "up"
fi

rm -f $pidfile

Tested this on version:

No Version Found
Published Mar 16, 2020
Version 1.0

Was this article helpful?

5 Comments

  • Are there any prerequisites?

     

    I implemented the monitor, but it continues to timeout.

     

    Log indicates:

    [0][14302] 2020-03-17 14:25:27.290399: ID 100  :(_do_ping): time to ping, now=[1584473130.290513][2020-03-17 14:25:30], status=UNKNOWN [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxx-apm01_current_active_sessions fd=-1 pend=0 #conn=0 up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473130.256451][2020-03-17 14:25:30] last_ping=[1584473125.262704][2020-03-17 14:25:25] deadline=[1584473130.358088][2020-03-17 14:25:30] on_service_list=True snd_cnt=4 rcv_cnt=0 ]

    [0][14302] 2020-03-17 14:25:27.290447: ID 100  :(_spawn_external_pinger): /config/filestore/files_d/Common_d/external_monitor_d/:Common:snmp-check_62638_1 [ addr=::ffff:xxx.xxx.xxx.xxx:161 ]

    [0][14302] 2020-03-17 14:25:27.290857: ID 100  :(_spawn_external_pinger): spawned EAV pid=19475 [ addr=::ffff:xxx.xxx.xxx.xxx:161 fd=13 ]

    [0][14302] 2020-03-17 14:25:27.290885: ID 100  :(_do_ping): post ping, status=UNKNOWN [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxxxx-apm01_current_active_sessions fd=13 pend=0 #conn=0 up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473135.256451][2020-03-17 14:25:35] last_ping=[1584473130.290513][2020-03-17 14:25:30] deadline=[1584473130.358088][2020-03-17 14:25:30] on_service_list=True snd_cnt=5 rcv_cnt=0 ]

    [0][14302] 2020-03-17 14:25:27.291532: ID 100  :(spawn_external_pinger): EAV execve: No such file or directory

    [0][14302] 2020-03-17 14:25:27.291998: ID 100  :(_main_loop): Service ready for read, now=[1584473130.292158][2020-03-17 14:25:30] [ addr=::ffff:xxx.xxx.xxx.xxx:161 srcaddr=::%0:0 fd=13 pend=0 #conn=0 ]

    [0][14302] 2020-03-17 14:25:27.292029: ID 100  :(_recv_external_node_ping): reading [ addr=::ffff:xxx.xxx.xxx.xxx:161 ]

    [0][14302] 2020-03-17 14:25:27.292039: ID 100  :(recv_external_node_ping): EAV failed [ addr=::ffff:xxx.xxx.xxx.xxx:161 ]

    [0][14302] 2020-03-17 14:25:27.292045: ID 100  :(_kill_external_pinger): killing pid=19475 [ addr=::ffff:xxx.xxx.xxx.xxx:161 fd=13 ]

    [0][14302] 2020-03-17 14:25:27.992132: ID 100  :(service_ping_timeout_message): timed out, status=DOWN, now=[1584473130.992221][2020-03-17 14:25:30] [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxx-apm01_current_active_sessions fd=-1 pend=0 #conn=0 up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473135.256451][2020-03-17 14:25:35] last_ping=[1584473130.290513][2020-03-17 14:25:30] deadline=[1584473130.358088][2020-03-17 14:25:30] on_service_list=True snd_cnt=5 rcv_cnt=0 ]

    [0][14302] 2020-03-17 14:25:27.992185: ID 100  :(_change_state_to_failure) [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxx-apm01_current_active_sessions up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473135.256451][2020-03-17 14:25:35] last_ping=[1584473130.290513][2020-03-17 14:25:30] deadline=[1584473130.358088][2020-03-17 14:25:30] on_service_list=True ]

    [0][14302] 2020-03-17 14:25:27.992222: ID 100  :(change_state_common) monitor test completed, result DOWN [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxxx-apm01_current_active_sessions ]

    [0][14302] 2020-03-17 14:25:27.992230: ID 100  :(_change_state_common): Node DOWN (was UNKNOWN) [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxxxx-apm01_current_active_sessions up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473135.256451][2020-03-17 14:25:35] last_ping=[1584473130.290513][2020-03-17 14:25:30] deadline=[1584473130.358088][2020-03-17 14:25:30] on_service_list=True snd_cnt=5 rcv_cnt=0 ]

    [0][14302] 2020-03-17 14:25:27.992248: ID 100  :(adjust_deadline): from [1584473130.358088][2020-03-17 14:25:30] to [1584473135.992221][2020-03-17 14:25:35] [ addr=::ffff:xxx.xxx.xxx.xxx:161 mon=/Common/snmp_monitor-xxxxxxxx-apm01_current_active_sessions fd=-1 pend=0 #conn=0 up_intvl=5 dn_intvl=5 timeout=16 time_until_up=0 immed=0 next_ping=[1584473135.256451][2020-03-17 14:25:35] last_ping=[1584473130.290513][2020-03-17 14:25:30] deadline=[1584473135.992221][2020-03-17 14:25:35] on_service_list=True snd_cnt=5 rcv_cnt=0 ]

  • what does your ltm object monitor look like? Did you set the variables appropriately?

  • I found it. I had to define the public community in the system snmp settings and also allow the self-IP to call it.

  • wtl1's avatar
    wtl1
    Icon for Nimbostratus rankNimbostratus

    I am trying to implement this based off the GTM/APM use case article but have some questions:

     

    1. For the SNMP monitor- what would be the alias address? Would it be the floating external or internal IP running in an HA environment? Or would it be the external or internal self IP still?
    2. For the Pool, what IP should go in the pool as the member? I know it says it doesnt matter but when i added an IP it was showing as down. And is that ok if it does? And does the service port matter at all if the pool address really doesnt matter.
    3. I the vs http client and server profile and added the irule resource but it is showing offline (Enabled)