{"id":1651,"date":"2015-04-07T18:20:35","date_gmt":"2015-04-07T17:20:35","guid":{"rendered":"http:\/\/www.zarrelli.org\/blog\/?p=1651"},"modified":"2015-04-07T18:30:34","modified_gmt":"2015-04-07T17:30:34","slug":"nagios-check-bigip-f5-memory","status":"publish","type":"post","link":"https:\/\/www.zarrelli.org\/blog\/nagios-check-bigip-f5-memory\/","title":{"rendered":"Nagios \u2013 Check BigIP F5 memory"},"content":{"rendered":"<p>This is the last plugin I coded for F5 BigIP. As usual,\u00a0I just found this\u00a0old Nagios plugin of mine, sitting in a directory, taking dust.<\/p>\n<p>As usual, I\u2019m 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\u2019s 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\u2019ve not changed, it should work with no efforts. It\u2019s based on v3 of SNMP protocol and the auth and priv are \u201chardcoded\u201d, so you may want to change them.<\/p>\n<p>Have fun.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:sh decode:true \">#!\/bin\/sh\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\nSNMP_GET=$(which snmpget)\r\nSED=$(which sed)\r\nBC=$(which bc)\r\nECHO=$(which echo)\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:=\"50\"}\r\nCRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:=\"80\"}\r\nHOST=${HOST:=\"change me\"}\r\nLOGIN=${LOGIN:=\"change me\"}\r\nPASSWORD=${PASSWORD:=\"change me\"}\r\n\r\n# Indico l'OID dei dati che voglio reperire\r\n\r\nTOTAL_HOST_MEMORY=\".1.3.6.1.4.1.3375.2.1.7.1.1.0\"\r\nTOTAL_TMM_MEMORY=\".1.3.6.1.4.1.3375.2.1.1.2.1.44.0\"\r\nUSED_HOST_MEMORY=\".1.3.6.1.4.1.3375.2.1.7.1.2.0\"\r\nUSED_TMM_MEMORY=\".1.3.6.1.4.1.3375.2.1.1.2.1.45.0\"\r\n\r\n\r\n\r\nprint_help() {\r\n        echo \"\"\r\n        echo \"Questo plugin consente di monitorare la banda occupata \"\r\n        echo \"su una interfaccia di rete per gli F5. -w per la percentuale di warning, -c per la critica,\"\r\n        echo \" -H per l'host name o l'host address del server da controllare, -l per la login, -p per la password.\"\r\n        echo \"\"\r\n                exit 0\r\n}\r\n\r\n\r\n\r\n# Parse parameters\r\nwhile [ $# -gt 0 ]; do\r\n    case \"$1\" in\r\n        -h | --help)\r\n            print_help\r\n            exit ${STATE_OK}\r\n            ;;\r\n         -H | --hostname)\r\n            shift\r\n            HOST=$1\r\n            ;;\r\n        -w | --warning)\r\n                shift\r\n                WARNING_THRESHOLD=$1\r\n                ;;\r\n        -c | --critical)\r\n                shift\r\n                CRITICAL_THRESHOLD=$1\r\n                ;;\r\n        -l | --login)\r\n                shift\r\n                LOGIN=$1\r\n                ;;\r\n        -p | --password)\r\n                shift\r\n                PASSWORD=$1\r\n                ;;\r\n        -i | --interface)\r\n                shift\r\n                INTERFACE=$1\r\n                ;;\r\n        *)  echo \"Unknown argument: $1\"\r\n            print_help\r\n            exit ${STATE_UNKNOWN}\r\n            ;;\r\n        esac\r\nshift\r\ndone\r\n\r\n\r\nif [ -n \"${SNMP_GET}\" ] ;\r\n\r\n                                                then\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\n                                                        if [ -f \"${SNMP_GET}\" ] ;\r\n\r\n                                                                then\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\n                                                                else\r\n                                                                        # Se non presente il file echo, non posso stampare a video alcunche'.\r\n                                                                        # Allora esco silenziosamente dal programma\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t${ECHO} \"La variabile SNMP_GET e' istanziata ma non punta a un file preciso\"\r\n                                                                        exit ${STATE_UNKNOWN}\r\n\r\n                                                        # Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile SNMP_GET\r\n\r\n                                                        fi\r\n\r\n                                                else\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\t\t\t\t\t\t\t\t    ${ECHO} \"La variabile SNMP_GET non risulta istanziata\"\r\n\t\t\t\t\t\t\t\t    exit ${STATE_UNKNOWN}\r\n\r\n                                                                    # Chiudo la struttura di controllo relativa all'istanziazione della variabile SNMP_GET (contenuto non vuoto)\r\n\r\n                                          fi\r\n\r\nif [ -n \"${BC}\" ] ;\r\n\r\n                                                then\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\n                                                        if [ -f \"${BC}\" ] ;\r\n\r\n                                                                then\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\n                                                                else\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\n                                                                        exit ${STATE_UNKNOWN}\r\n\r\n                                                        # Chiudo la struttura di controllo sul puntamento a file del contenuto della variabile BC\r\n\r\n                                                        fi\r\n\r\n                                                else\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\n                                                                    exit ${STATE_UNKNOWN}\r\n\r\n                                                                    # Chiudo la struttura di controllo relativa all'istanziazione della variabile BC (contenuto non vuoto)\r\n\r\n                                          fi\r\n\r\n\r\ncontrolla_limiti ()\r\n\r\n        {\r\n\r\n        if\r\n                        (( $(echo \"scale=2; ${WARNING_THRESHOLD} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\n        then\r\n                        echo \"Il valore di WARNING (${WARNING_THRESHOLD}) deve essere minore rispetto a quello di CRITICAL (${CRITICAL_THRESHOLD})\"\r\n                        exit 1\r\n\r\n        else\r\n\r\n                        :\r\n\r\n        fi\r\n\r\n\t}\r\n\r\n\r\n\r\naggiorna ()\r\n\r\n        {\r\n\r\n\r\nif \r\n\r\n! 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}`\r\n\r\nthen\r\n\r\nexit ${STATE_CRITICAL}\r\n\r\nfi\r\n\r\nCONVERT_POLL=$( echo $POLL | awk 'BEGIN{ FS=\" \" } { print $1 \"\\n\" $2 \"\\n\" $3 \"\\n\" $4}' )\r\n\r\nARRAY_POLL=($CONVERT_POLL)\r\n\r\nTOTAL_HOST_MEMORY_POLL=$((${ARRAY_POLL[0]} \/ 1000000))\r\nTOTAL_TMM_MEMORY_POLL=$((${ARRAY_POLL[1]} \/ 1000000))\r\nUSED_HOST_MEMORY_POLL=$((${ARRAY_POLL[2]} \/ 1000000))\r\nUSED_TMM_MEMORY_POLL=$((${ARRAY_POLL[3]} \/ 1000000))\r\n\r\n\r\nHOST_MEMORY_PERCENTUALE=$(echo \"scale=2; (${USED_HOST_MEMORY_POLL} * 100) \/ (${TOTAL_HOST_MEMORY_POLL})\" | bc)\r\n\r\nUSED_MEMORY_PERCENTUALE=$(echo \"scale=2; (${USED_TMM_MEMORY_POLL} * 100) \/ (${TOTAL_TMM_MEMORY_POLL})\" | bc)\r\n\r\n\r\nif      \r\n\r\n\t\t\t(( $(echo \"scale=6; ${HOST_MEMORY_PERCENTUALE} &gt;= ${WARNING_THRESHOLD}\" | bc ) )) &amp;&amp;  (( $(echo \"scale=2; ${HOST_MEMORY_PERCENTUALE} &lt; ${CRITICAL_THRESHOLD}\" | bc ) ))  ;\r\n\r\nthen\r\n\r\n                        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\"\r\n                        exit ${STATE_WARNING}\r\n\r\n\r\nelif    \t\t(( $(echo \"scale=6; ${HOST_MEMORY_PERCENTUALE} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ; \r\n\r\n\r\nthen\r\n\r\n\r\n                        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\"\r\n                        exit ${STATE_CRITICAL}\r\n\r\nelif\r\n\r\n(( $(echo \"scale=2; ${USED_MEMORY_PERCENTUALE} &gt;= ${WARNING_THRESHOLD}\" | bc ) )) &amp;&amp;  (( $(echo \"scale=2; ${USED_MEMORY_PERCENTUALE} &lt; ${CRITICAL_THRESHOLD}\" | bc ) ))  ;\r\n\r\nthen\r\n\r\n\r\n                        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\"\r\n                        exit ${STATE_WARNING}\r\n\r\n\r\nelif                    (( $(echo \"scale=6; ${USED_MEMORY_PERCENTUALE} &gt;= ${CRITICAL_THRESHOLD}\" | bc ) )) ;\r\n\r\n\r\nthen\r\n                        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\"\r\n                        exit ${STATE_CRITICAL}\r\n\r\n\r\nelse\r\n\r\n                        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\"\r\n\r\n                        exit ${STATE_OK}\r\nfi\r\n\r\n\r\n}\r\n\r\ncontrolla_limiti\r\naggiorna<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the last plugin I coded for F5 BigIP. As usual,\u00a0I just found this\u00a0old Nagios plugin of mine, sitting in a directory, taking dust. As usual, I\u2019m 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\u2019s bash glory. &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":[173,454,455,494,138,177],"class_list":["post-1651","post","type-post","status-publish","format-standard","hentry","category-di-tutto-un-po","tag-bash","tag-bigip","tag-f5","tag-nagios","tag-plugin","tag-script","without-featured-image"],"_links":{"self":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/posts\/1651","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=1651"}],"version-history":[{"count":0,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/posts\/1651\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/media?parent=1651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/categories?post=1651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zarrelli.org\/blog\/wp-json\/wp\/v2\/tags?post=1651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}