Nagios – Check BigIP F5 memory
This is the last plugin I coded for F5 BigIP. As usual, I just found this old Nagios plugin of mine, sitting in a directory, taking dust.
As usual, I’m not a programmer, so I just do quick and dirty tricks to get what I need, so here it is the plugin in all it’s bash glory.
The plugin is commented, although in Italian, but google can translate the comments.
I wrote this plugins some years ago, it works using SNMP as protocol and with the standard (at those times) OID for BigIP. If they’ve not changed, it should work with no efforts. It’s based on v3 of SNMP protocol and the auth and priv are “hardcoded”, so you may want to change them.
Have fun.
#!/bin/sh # License: GPL # # Author: Giorgio Zarrelli <zarrelli@linux.it> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # SNMP_GET=$(which snmpget) SED=$(which sed) BC=$(which bc) ECHO=$(which echo) # Nagios return codes STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 WARNING_THRESHOLD=${WARNING_THRESHOLD:="50"} CRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:="80"} HOST=${HOST:="change me"} LOGIN=${LOGIN:="change me"} PASSWORD=${PASSWORD:="change me"} # Indico l'OID dei dati che voglio reperire TOTAL_HOST_MEMORY=".1.3.6.1.4.1.3375.2.1.7.1.1.0" TOTAL_TMM_MEMORY=".1.3.6.1.4.1.3375.2.1.1.2.1.44.0" USED_HOST_MEMORY=".1.3.6.1.4.1.3375.2.1.7.1.2.0" USED_TMM_MEMORY=".1.3.6.1.4.1.3375.2.1.1.2.1.45.0" print_help() { echo "" echo "Questo plugin consente di monitorare la banda occupata " echo "su una interfaccia di rete per gli F5. -w per la percentuale di warning, -c per la critica," echo " -H per l'host name o l'host address del server da controllare, -l per la login, -p per la password." echo "" exit 0 } # Parse parameters while [ $# -gt 0 ]; do case "$1" in -h | --help) print_help exit ${STATE_OK} ;; -H | --hostname) shift HOST=$1 ;; -w | --warning) shift WARNING_THRESHOLD=$1 ;; -c | --critical) shift CRITICAL_THRESHOLD=$1 ;; -l | --login) shift LOGIN=$1 ;; -p | --password) shift PASSWORD=$1 ;; -i | --interface) shift INTERFACE=$1 ;; *) echo "Unknown argument: $1" print_help exit ${STATE_UNKNOWN} ;; esac shift done if [ -n "${SNMP_GET}" ] ; then # Se la variabile SNMP_GET contiene almeno un carattere, controllo che il suo contenuto punti # al percorso dell'eseguibile echo if [ -f "${SNMP_GET}" ] ; then # Se il contenuto di SNMP_GET punta al file binario snmpget # allora non faccio nulla : else # Se non presente il file echo, non posso stampare a video alcunche'. # Allora esco silenziosamente dal programma ${ECHO} "La variabile SNMP_GET e' istanziata ma non punta a un file preciso" exit ${STATE_UNKNOWN} # Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile SNMP_GET fi else # Se il contenuto di SNMP_GET risulta vuoto, non e' presente il file echo # e quindi non posso stampare a video dei messaggi ed esco silenziosamente ${ECHO} "La variabile SNMP_GET non risulta istanziata" exit ${STATE_UNKNOWN} # Chiudo la struttura di controllo relativa all'istanziazione della variabile SNMP_GET (contenuto non vuoto) fi if [ -n "${BC}" ] ; then # Se la variabile BC contiene almeno un carattere, controllo che il suo contenuto punti # al percorso dell'eseguibile echo if [ -f "${BC}" ] ; then # Se il contenuto di BC punta al file binario snmpget # allora non faccio nulla : else # Se non presente il file echo, non posso stampare a video alcunche'. # Allora esco silenziosamente dal programma ${ECHO} "La variabile BC e' istanziata ma non punta a un file preciso" exit ${STATE_UNKNOWN} # Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile BC fi else # Se il contenuto di BC risulta vuoto, non e' presente il file echo # e quindi non posso stampare a video dei messaggi ed esco silenziosamente ${ECHO} "La variabile BC non risulta istanziata" exit ${STATE_UNKNOWN} # Chiudo la struttura di controllo relativa all'istanziazione della variabile BC (contenuto non vuoto) fi controlla_limiti () { if (( $(echo "scale=2; ${WARNING_THRESHOLD} >= ${CRITICAL_THRESHOLD}" | bc ) )) ; then echo "Il valore di WARNING (${WARNING_THRESHOLD}) deve essere minore rispetto a quello di CRITICAL (${CRITICAL_THRESHOLD})" exit 1 else : fi } aggiorna () { if ! POLL=`/usr/bin/snmpget -Oqvt -t 1 -r 5 -m '' -v 3 -l authPriv -a MD5 -u ${LOGIN} -A ${PASSWORD} -x DES -X ${PASSWORD} ${HOST}:161 ${TOTAL_HOST_MEMORY} ${TOTAL_TMM_MEMORY} ${USED_HOST_MEMORY} ${USED_TMM_MEMORY}` then exit ${STATE_CRITICAL} fi CONVERT_POLL=$( echo $POLL | awk 'BEGIN{ FS=" " } { print $1 "\n" $2 "\n" $3 "\n" $4}' ) ARRAY_POLL=($CONVERT_POLL) TOTAL_HOST_MEMORY_POLL=$((${ARRAY_POLL[0]} / 1000000)) TOTAL_TMM_MEMORY_POLL=$((${ARRAY_POLL[1]} / 1000000)) USED_HOST_MEMORY_POLL=$((${ARRAY_POLL[2]} / 1000000)) USED_TMM_MEMORY_POLL=$((${ARRAY_POLL[3]} / 1000000)) HOST_MEMORY_PERCENTUALE=$(echo "scale=2; (${USED_HOST_MEMORY_POLL} * 100) / (${TOTAL_HOST_MEMORY_POLL})" | bc) USED_MEMORY_PERCENTUALE=$(echo "scale=2; (${USED_TMM_MEMORY_POLL} * 100) / (${TOTAL_TMM_MEMORY_POLL})" | bc) if (( $(echo "scale=6; ${HOST_MEMORY_PERCENTUALE} >= ${WARNING_THRESHOLD}" | bc ) )) && (( $(echo "scale=2; ${HOST_MEMORY_PERCENTUALE} < ${CRITICAL_THRESHOLD}" | bc ) )) ; then echo "MEMORIA BIGIP WARNING - THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB | THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL}MB" exit ${STATE_WARNING} elif (( $(echo "scale=6; ${HOST_MEMORY_PERCENTUALE} >= ${CRITICAL_THRESHOLD}" | bc ) )) ; then echo "MEMORIA BIGIP CRITICAL - THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB | THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB" exit ${STATE_CRITICAL} elif (( $(echo "scale=2; ${USED_MEMORY_PERCENTUALE} >= ${WARNING_THRESHOLD}" | bc ) )) && (( $(echo "scale=2; ${USED_MEMORY_PERCENTUALE} < ${CRITICAL_THRESHOLD}" | bc ) )) ; then echo "MEMORIA BIGIP WARNING - THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB | THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB" exit ${STATE_WARNING} elif (( $(echo "scale=6; ${USED_MEMORY_PERCENTUALE} >= ${CRITICAL_THRESHOLD}" | bc ) )) ; then echo "MEMORIA BIGIP CRITICAL - THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB | THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB" exit ${STATE_CRITICAL} else echo "MEMORIA BIGIP OK - THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB | THM=${TOTAL_HOST_MEMORY_POLL} MB;UHM=${USED_HOST_MEMORY_POLL} MB;TMM=${TOTAL_TMM_MEMORY_POLL} MB;UTM=${USED_TMM_MEMORY_POLL} MB" exit ${STATE_OK} fi } controlla_limiti aggiorna
Fancy and useful bash prompt
Is your old bash prompt a bit “outdated”? Ok, let’s give it some spice.
Open your
/etc/profile
and throw the following line in (no linebreak):
export PS1="\[\033[1;32m\][\$(date +%H:%M)]\[\033[0;36m\][\u@\[\033[0;31m\]\h:\[\033[1;34m\]\w]\[\033[0m\]"
Save, close the file and issue the following command:
source /etc/profile
What do you get? Well…something like this:
[18:05][root@moveaway:/home]
It’s:
[HH:MM][user@hostname:/current_dir]
Have a nice and colorful day!
Bookmarks for Giugno 16th through Giugno 17th
These are my links for Giugno 16th through Giugno 17th: