I have a switch which includes it's firmware version in the 'ifDescr' output. The 'ifName' output references the SNMP OID index so I wanted to write an external LLD script to reformat the returned 'ifDescr' values.
Output when I run my external SNMP LLD script manually (reformats the long interface description to eg 1:1):
I've successfully validated the JSON output using http://jsonlint.com/ but Zabbix doesn't do anything with it as it simply doesn't appear to receive any output...
Zabbix debug log:
Herewith my simple bash script:
Code:
[root@zabbix ~]# snmpwalk -v3 -l AuthPriv -u <context> -a SHA -A <secret1> -x DES -X <secret2> <switchip>:161 -O fn IF-MIB::ifDescr | head .1.3.6.1.2.1.2.2.1.2.1 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 1 on Unit 1 .1.3.6.1.2.1.2.2.1.2.2 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 2 on Unit 1 .1.3.6.1.2.1.2.2.1.2.3 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 3 on Unit 1 .1.3.6.1.2.1.2.2.1.2.4 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 4 on Unit 1 .1.3.6.1.2.1.2.2.1.2.5 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 5 on Unit 1 .1.3.6.1.2.1.2.2.1.2.6 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 6 on Unit 1 .1.3.6.1.2.1.2.2.1.2.7 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 7 on Unit 1 .1.3.6.1.2.1.2.2.1.2.8 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 8 on Unit 1 .1.3.6.1.2.1.2.2.1.2.9 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 9 on Unit 1 .1.3.6.1.2.1.2.2.1.2.10 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 10 on Unit 1
Code:
[root@zabbix externalscripts]# ./snmpwalk_dgs3120.sh <context> <secret1> <secret2> <switchip> IF-MIB::ifDescr
{
"data": [
{ "{#SNMPINDEX}": "1", "{#SNMPVALUE}": "1:1" },
{ "{#SNMPINDEX}": "2", "{#SNMPVALUE}": "1:2" },
{ "{#SNMPINDEX}": "3", "{#SNMPVALUE}": "1:3" },
{ "{#SNMPINDEX}": "4", "{#SNMPVALUE}": "1:4" },
{ "{#SNMPINDEX}": "5", "{#SNMPVALUE}": "1:5" },
{ "{#SNMPINDEX}": "6", "{#SNMPVALUE}": "1:6" },
{ "{#SNMPINDEX}": "7", "{#SNMPVALUE}": "1:7" },
{ "{#SNMPINDEX}": "8", "{#SNMPVALUE}": "1:8" },
{ "{#SNMPINDEX}": "9", "{#SNMPVALUE}": "1:9" },
{ "{#SNMPINDEX}": "10", "{#SNMPVALUE}": "1:10" },
{ "{#SNMPINDEX}": "11", "{#SNMPVALUE}": "1:11" },
{ "{#SNMPINDEX}": "12", "{#SNMPVALUE}": "1:12" },
{ "{#SNMPINDEX}": "13", "{#SNMPVALUE}": "1:13" },
{ "{#SNMPINDEX}": "14", "{#SNMPVALUE}": "1:14" },
{ "{#SNMPINDEX}": "15", "{#SNMPVALUE}": "1:15" },
{ "{#SNMPINDEX}": "16", "{#SNMPVALUE}": "1:16" },
{ "{#SNMPINDEX}": "17", "{#SNMPVALUE}": "1:17" },
{ "{#SNMPINDEX}": "18", "{#SNMPVALUE}": "1:18" },
{ "{#SNMPINDEX}": "19", "{#SNMPVALUE}": "1:19" },
{ "{#SNMPINDEX}": "20", "{#SNMPVALUE}": "1:20" },
{ "{#SNMPINDEX}": "21", "{#SNMPVALUE}": "1:21" },
{ "{#SNMPINDEX}": "22", "{#SNMPVALUE}": "1:22" },
{ "{#SNMPINDEX}": "23", "{#SNMPVALUE}": "1:23" },
{ "{#SNMPINDEX}": "24", "{#SNMPVALUE}": "1:24" },
{ "{#SNMPINDEX}": "897", "{#SNMPVALUE}": "Link Aggregation Group ID 1" },
{ "{#SNMPINDEX}": "1024", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0001" },
{ "{#SNMPINDEX}": "1025", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0002" },
{ "{#SNMPINDEX}": "1026", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0003" },
{ "{#SNMPINDEX}": "1027", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0004" },
{ "{#SNMPINDEX}": "1028", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0005" },
{ "{#SNMPINDEX}": "1029", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0006" },
{ "{#SNMPINDEX}": "1030", "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0007" },
{ "{#SNMPINDEX}": "5121", "{#SNMPVALUE}": "rif0(198.19.25.2)" }
]
}
Zabbix debug log:
Code:
25939:20160409:162629.485 End of substitute_key_macros():SUCCEED data:'snmpwalk_dgs3120.sh[<context>, <secret1>, <secret2>, <switchip>, "IF-MIB::ifDescr"]'
25939:20160409:162629.485 In get_value() key:'snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]'
25939:20160409:162629.485 In get_value_external() key:'snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]'
25939:20160409:162629.486 In zbx_popen() command:'/usr/lib/zabbix/externalscripts/snmpwalk_dgs3120.sh "<context>" "<secret1>" "<secret2>" "<switchip>" "IF-MIB::ifDescr"'
25939:20160409:162629.486 End of zbx_popen():7
25939:20160409:162630.047 In zbx_waitpid()
25939:20160409:162630.047 zbx_waitpid() exited, status:0
25939:20160409:162630.047 End of zbx_waitpid():26398
25939:20160409:162630.047 End of get_value_external():SUCCEED
25939:20160409:162630.047 End of get_value():SUCCEED
25939:20160409:162630.047 In activate_host() hostid:10187 itemid:38307 type:10
25939:20160409:162630.047 End of activate_host()
25939:20160409:162630.048 In lld_process_discovery_rule() itemid:38307
25939:20160409:162630.048 query [txnlev:0] [select hostid,key_,state,evaltype,formula,error,lifetime from items where itemid=38307]
25939:20160409:162630.048 In substitute_simple_macros() data:'0'
25939:20160409:162630.048 query [txnlev:0] [select item_conditionid,macro,value from item_condition where itemid=38307]
25939:20160409:162630.048 In lld_rows_get()
25939:20160409:162630.048 End of lld_rows_get():FAIL
25939:20160409:162630.048 End of lld_process_discovery_rule()
25939:20160409:162630.049 End of get_values():1
Herewith my simple bash script:
Code:
#!/bin/sh
# Usage: snmpwalk_dgs3120.sh <SNMPv3 username> <auth secret> <priv secret> <SNMP Host> <SNMP OID>
# LLD Key: snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]
output=`mktemp /tmp/snmpwalk_dgs3120.XXXXXX`;
error=`mktemp /tmp/snmpwalk_dgs3120.XXXXXX`;
snmpwalk -v3 -l AuthPriv -u $1 -a SHA -A $2 -x DES -X $3 $4:161 -O fn $5 > $output 2> $error;
return=$?;
if [ $return -eq 0 ]; then
echo -e '{\n\t"data": [';
first=1;
cat $output | while read index t t value; do
value=`echo $value | perl -pe 's/D-Link.*Port (\d+) on Unit (\d+)/\2:\1/'`;
[ $first -eq 0 ] && echo -ne ',\n';
echo -ne '\t\t{ "{#SNMPINDEX}": "'${index##.*.}'",\t';
echo -ne '"{#SNMPVALUE}": "'$value'" }';
first=0;
done
echo -e '\n\t]\n}';
else
cat $error >&2;
fi
find /tmp -type f -name 'snmpwalk_dgs3120.*' -mtime +1 -print0 | xargs -r0 rm -f;
rm -f $output $error;
exit $return;

Comment