Return a value on "No such instance"
I needed to check whether an snmp value existed in a table or not. This script will return 'something' if the snmp value doesn't exist so you can use it in triggers etc.
My use case:
We monitor a lot of Cisco switches. I want to know when a port is in "error disabled" state which could by caused by bpduGuard (spanning tree problems) 802.1X auth probblems, floodcontrol etc.
Cisco uses a table which lists all ports that've been disabled:
1.3.6.1.4.1.9.9.548.1.3.1.1.2.{#SNMPINDEX}.0
So, if the value exists in the table, there's a problem with the port and the integer value will tell you exactly what the problem is. If the value is NOT present, that means the port is working as expected.
Because this will cause Zabbix to generate a "No such instance currently exists at this OID' you can't do anything with this. I had a trigger on this which would never recover because Zabbix can't handle the non existing value.
This script takes 5 arguments:
- Host
- The requested oid
- Error value (The error value you want to replace) (optional)
- Return value (something like 0/1, FALSE/TRUE) (optional)
- SNMP Version (optional)
By default, it will return 0 instead of 'No such...'
Script should work on all zabbix versions.
IMPORTANT UPDATE!
The previous version wasn't working! I made an error which caused the script to always return 0. Please use the new version.
Listing Details
3 version, '2018-09-03 14:31' modified