{"id":1635,"date":"2015-03-13T12:16:54","date_gmt":"2015-03-13T11:16:54","guid":{"rendered":"http:\/\/www.zarrelli.org\/blog\/?p=1635"},"modified":"2015-03-31T12:28:49","modified_gmt":"2015-03-31T11:28:49","slug":"nagios-check-bigip-f5-bandwidth","status":"publish","type":"post","link":"https:\/\/www.zarrelli.org\/blog\/nagios-check-bigip-f5-bandwidth\/","title":{"rendered":"Nagios &#8211; Check BigIP F5 bandwidth"},"content":{"rendered":"<p>I just found an old Nagios plugin of mine, it was sitting in a directory, taking dust.<\/p>\n<p>As usual, I&#8217;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&#8217;s bash glory.<\/p>\n<p>The plugin is commented, although in Italian, but google can translate the comments.<\/p>\n<p>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&#8217;ve not changed, it should work with no efforts. It&#8217;s based on v3 of SNMP protocol and the auth and priv are &#8220;hardcoded&#8221;, so you may want to change them.<\/p>\n<p>Have fun.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"BigIp F5 check bandwidth\">#!\/bin\/sh\r\n\r\n#\r\n# License: GPL\r\n# \r\n# Author: Giorgio Zarrelli &lt;zarrelli@linux.it&gt;\r\n#\r\n# This program is free software; you can redistribute it and\/or modify\r\n# it under the terms of the GNU General Public License version 2 as\r\n# published by the Free Software Foundation.\r\n#\r\n# This program is distributed in the hope that it will be useful,\r\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n# GNU General Public License for more details.\r\n#\r\n# You should have received a copy of the GNU General Public License\r\n# along with this program. If not, see &lt;http:\/\/www.gnu.org\/licenses\/&gt;.\r\n#\r\n\r\n\r\nSNMP_GET=$(which snmpget)\r\nSED=$(which sed)\r\nBC=$(which bc)\r\nOD=$(which od)\r\nECHO=$(which echo)\r\nSLEEP=$(which sleep)\r\nSLEEP_TIME=15\r\n\r\n# Nagios return codes\r\nSTATE_OK=0\r\nSTATE_WARNING=1\r\nSTATE_CRITICAL=2\r\nSTATE_UNKNOWN=3\r\n\r\nWARNING_THRESHOLD=${WARNING_THRESHOLD:=\"33\"}\r\nCRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:=\"50\"}\r\nHOST=${HOST:=\"change me\"}\r\nLOGIN=${LOGIN:=\"change me\"}\r\nPASSWORD=${PASSWORD:=\"change me\"}\r\nINTERFACE=${INTERFACE:=\"1.1\"}\r\n\r\n# Indico l'OID di base, compreso del valore di leaf, per le interfacce di rete:\r\n\r\nBASE_IN_OID=\".1.3.6.1.4.1.3375.2.1.2.4.4.3.1.3.3\"\r\nBASE_OUT_OID=\".1.3.6.1.4.1.3375.2.1.2.4.4.3.1.5.3\"\r\nBASE_SPEED_OID=\".1.3.6.1.4.1.3375.2.1.2.4.1.2.1.4.3\"\r\nSYS_UPTIME_OID=\".1.3.6.1.4.1.3375.2.1.6.6.0\"\r\n\r\nprint_help() {\r\necho \"\"\r\necho \"Questo plugin consente di monitorare la banda occupata \"\r\necho \"su una interfaccia di rete per gli F5. -w per la percentuale di warning, -c per la critica,\"\r\necho \" -H per l'host name o l'host address del server da controllare, -l per la login, -p per la password.\"\r\necho \"\"\r\nexit 0\r\n}\r\n\r\n\r\n\r\n# Parse parameters\r\nwhile [ $# -gt 0 ]; do\r\ncase \"$1\" in\r\n-h | --help)\r\nprint_help\r\nexit ${STATE_OK}\r\n;;\r\n-H | --hostname)\r\nshift\r\nHOST=$1\r\n;;\r\n-w | --warning)\r\nshift\r\nWARNING_THRESHOLD=$1\r\n;;\r\n-c | --critical)\r\nshift\r\nCRITICAL_THRESHOLD=$1\r\n;;\r\n-l | --login)\r\nshift\r\nLOGIN=$1\r\n;;\r\n-p | --password)\r\nshift\r\nPASSWORD=$1\r\n;;\r\n-i | --interface)\r\nshift\r\nINTERFACE=$1\r\n;;\r\n*) echo \"Unknown argument: $1\"\r\nprint_help\r\nexit ${STATE_UNKNOWN}\r\n;;\r\nesac\r\nshift\r\ndone\r\n\r\n\r\nINTERFACE_OID=$( ${ECHO} ${INTERFACE} | ${OD} -An -N3 -td1 | ${SED} 's\/ \/.\/g')\r\n\r\nFULL_IN_OID=${BASE_IN_OID}${INTERFACE_OID}\r\nFULL_OUT_OID=${BASE_OUT_OID}${INTERFACE_OID}\r\n\r\nif\r\n\r\n! NOM_SPEED=`${SNMP_GET} -v 3 -t 1 -r 5 -m '' -v 3 -l authPriv -a MD5 -u ${LOGIN} -A ${PASSWORD} -x DES -X ${PASSWORD} ${HOST}:161 ${BASE_SPEED_OID}${INTERFACE_OID} | cut -d \" \" -f 4`\r\n\r\nthen\r\n\r\nexit ${STATE_CRITICAL}\r\n\r\nfi\r\n\r\n\r\nSPEED=$(echo \"scale=0; (${NOM_SPEED} * 1000000 \/ 8)\" | bc)\r\n\r\n\r\nif [ -n \"${SNMP_GET}\" ] ;\r\n\r\nthen\r\n\r\n# Se la variabile SNMP_GET contiene almeno un carattere, controllo che il suo contenuto punti\r\n# al percorso dell'eseguibile echo\r\n\r\nif [ -f \"${SNMP_GET}\" ] ;\r\n\r\nthen\r\n# Se il contenuto di SNMP_GET punta al file binario snmpget\r\n# allora non faccio nulla\r\n\r\n:\r\n\r\n\r\nelse\r\n# Se non presente il file echo, non posso stampare a video alcunche'.\r\n# Allora esco silenziosamente dal programma\r\n\r\n${ECHO} \"La variabile SNMP_GET e' istanziata ma non punta a un file preciso\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile SNMP_GET\r\n\r\nfi\r\n\r\nelse\r\n# Se il contenuto di SNMP_GET risulta vuoto, non e' presente il file echo\r\n# e quindi non posso stampare a video dei messaggi ed esco silenziosamente\r\n\r\n${ECHO} \"La variabile SNMP_GET non risulta istanziata\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo relativa all'istanziazione della variabile SNMP_GET (contenuto non vuoto)\r\n\r\nfi\r\n\r\nif [ -n \"${BC}\" ] ;\r\n\r\nthen\r\n\r\n# Se la variabile BC contiene almeno un carattere, controllo che il suo contenuto punti\r\n# al percorso dell'eseguibile echo\r\n\r\nif [ -f \"${BC}\" ] ;\r\n\r\nthen\r\n# Se il contenuto di BC punta al file binario snmpget\r\n# allora non faccio nulla\r\n\r\n:\r\n\r\n\r\nelse\r\n# Se non presente il file echo, non posso stampare a video alcunche'.\r\n# Allora esco silenziosamente dal programma\r\n\r\n${ECHO} \"La variabile BC e' istanziata ma non punta a un file preciso\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile BC\r\n\r\nfi\r\n\r\nelse\r\n# Se il contenuto di BC risulta vuoto, non e' presente il file echo\r\n# e quindi non posso stampare a video dei messaggi ed esco silenziosamente\r\n\r\n${ECHO} \"La variabile BC non risulta istanziata\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo relativa all'istanziazione della variabile BC (contenuto non vuoto)\r\n\r\nfi\r\nif [ -n \"$SLEEP\" ] ;\r\n\r\nthen\r\n\r\n# Se la variabile SLEEP contiene almeno un carattere, controllo che il suo contenuto punti\r\n# al percorso dell'eseguibile echo\r\n\r\nif [ -f \"$SLEEP\" ] ;\r\n\r\nthen\r\n# Se il contenuto di SLEEP punta al file binario snmpget\r\n# allora non faccio nulla\r\n\r\n:\r\n\r\n\r\nelse\r\n# Se non presente il file echo, non posso stampare a video alcunche'.\r\n# Allora esco silenziosamente dal programma\r\n\r\n${ECHO} \"La variabile SLEEP e' istanziata ma non punta a un file preciso\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile SLEEP\r\n\r\nfi\r\n\r\nelse\r\n# Se il contenuto di SLEEP risulta vuoto, non e' presente il file echo\r\n# e quindi non posso stampare a video dei messaggi ed esco silenziosamente\r\n\r\n${ECHO} \"La variabile SLEEP non risulta istanziata\"\r\nexit ${STATE_UNKNOWN}\r\n\r\n# Chiudo la struttura di controllo relativa all'istanziazione della variabile SLEEP (contenuto non vuoto)\r\n\r\nfi\r\n\r\n\r\n\r\ncontrolla_limiti ()\r\n\r\n{\r\n\r\nif\r\n(( $(echo \"scale=2; ${WARNING_THRESHOLD} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\nthen\r\necho \"Il valore di WARNING (${WARNING_THRESHOLD}) deve essere minore rispetto a quello di CRITICAL (${CRITICAL_THRESHOLD})\"\r\nexit 1\r\n\r\nelse\r\n\r\n:\r\n\r\nfi\r\n\r\n}\r\n\r\n\r\n\r\naggiorna ()\r\n\r\n{\r\n\r\n\r\nFIRST_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 ${FULL_IN_OID} ${FULL_OUT_OID} ${SYS_UPTIME_OID}`\r\n\r\n\r\n${SLEEP} ${SLEEP_TIME}\r\n\r\nSECOND_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 ${FULL_IN_OID} ${FULL_OUT_OID} ${SYS_UPTIME_OID}`\r\n\r\nCONVERT_FIRST_POLL=$( echo $FIRST_POLL | awk 'BEGIN{ FS=\" \" } { print $1 \"\\n\" $2 \"\\n\" $3 }' )\r\n\r\nARRAY_FIRST_POLL=($CONVERT_FIRST_POLL)\r\n\r\nIN_FIRST_POLL=${ARRAY_FIRST_POLL[0]}\r\nOUT_FIRST_POLL=${ARRAY_FIRST_POLL[1]}\r\nTIME_FIRST_POLL=${ARRAY_FIRST_POLL[2]}\r\n\r\n\r\nCONVERT_SECOND_POLL=$( echo $SECOND_POLL | awk 'BEGIN{ FS=\" \" } { print $1 \"\\n\" $2 \"\\n\" $3 }' )\r\n\r\nARRAY_SECOND_POLL=($CONVERT_SECOND_POLL)\r\n\r\nIN_SECOND_POLL=${ARRAY_SECOND_POLL[0]}\r\nOUT_SECOND_POLL=${ARRAY_SECOND_POLL[1]}\r\nTIME_SECOND_POLL=${ARRAY_SECOND_POLL[2]}\r\n\r\n\r\nENTRATA=$(echo \"scale=6; (${IN_SECOND_POLL}) - (${IN_FIRST_POLL})\" | bc)\r\n\r\nUSCITA=$(echo \"scale=6; (${OUT_SECOND_POLL}) - (${OUT_FIRST_POLL})\" | bc)\r\n\r\nDELTA=\"$[(${TIME_SECOND_POLL} - ${TIME_FIRST_POLL}) \/100]\"\r\n\r\nBANDA_PERCENTUALE_IN_ENTRATA=$(echo \"scale=6; (${ENTRATA}) \/ (${DELTA} * ${SPEED})\" | bc)\r\n\r\nBANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA=$(echo \"scale=6; (${ENTRATA} \/ ${DELTA}) \/1024\" | bc)\r\n\r\n\r\nBANDA_PERCENTUALE_IN_USCITA=$(echo \"scale=6; (${USCITA}) \/ (${DELTA} * ${SPEED})\" | bc)\r\n\r\nBANDA_AL_SECONDO_IN_KBYTE_IN_USCITA=$(echo \"scale=6; (${USCITA} \/ ${DELTA}) \/1024\" | bc)\r\n\r\nif\r\n\r\n(( $(echo \"scale=6; ${BANDA_PERCENTUALE_IN_ENTRATA} &gt;= ${WARNING_THRESHOLD}\" | bc ) )) &amp;&amp; (( $(echo \"scale=2; ${BANDA_PERCENTUALE_IN_ENTRATA} &lt; ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\nthen\r\n\r\necho \"BANDWIDTH WARNING - IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s | IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s;${WARNING_THRESHOLD}\"\r\nexit ${STATE_WARNING}\r\n\r\n\r\nelif (( $(echo \"scale=6; ${BANDA_PERCENTUALE_IN_ENTRATA} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\n\r\nthen\r\n\r\necho \"BANDWIDTH CRITICAL - IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s | IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s;${CRITICAL_THRESHOLD}\"\r\nexit ${STATE_CRITICAL}\r\n\r\nelif\r\n\r\n(( $(echo \"scale=2; ${BANDA_PERCENTUALE_IN_USCITA} &gt;= ${WARNING_THRESHOLD}\" | bc ) )) &amp;&amp; (( $(echo \"scale=2; ${BANDA_PERCENTUALE_IN_USCITA} &lt; ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\nthen\r\n\r\necho \"BANDWIDTH WARNING - IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s | IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA}KB\/s;${WARNING_THRESHOLD}\"\r\nexit ${STATE_WARNING}\r\n\r\n\r\nelif (( $(echo \"scale=6; ${BANDA_PERCENTUALE_IN_USCITA} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\n\r\nthen\r\n\r\necho \"BANDWIDTH CRITICAL - IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s | IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s;${CRITICAL_THRESHOLD}\"\r\nexit ${STATE_CRITICAL}\r\n\r\n\r\nelse\r\necho \"BANDWIDTH OK - IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s | IN=${BANDA_AL_SECONDO_IN_KBYTE_IN_ENTRATA} KB\/s;OUT=${BANDA_AL_SECONDO_IN_KBYTE_IN_USCITA} KB\/s;${WARNING_THRESHOLD};${CRITICAL_THRESHOLD}\"\r\n\r\n\r\n\r\nexit ${STATE_OK}\r\nfi\r\n\r\n\r\n}\r\n\r\ncontrolla_limiti\r\naggiorna<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I just found an old Nagios plugin of mine, it was sitting in a directory, taking dust. As usual, I&#8217;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&#8217;s bash glory. The plugin is commented, although in Italian, but &hellip;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[456,454,455,494,138],"class_list":{"0":"post-1635","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-di-tutto-un-po","7":"tag-bandwidth","8":"tag-bigip","9":"tag-f5","10":"tag-nagios","11":"tag-plugin","13":"without-featured-image"},"_links":{"self":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/posts\/1635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/comments?post=1635"}],"version-history":[{"count":0,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/posts\/1635\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/media?parent=1635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/categories?post=1635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/tags?post=1635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}