创建完成后,点击右上角的创建自动发现规则。
[root@zabbix zabbix_agentd.d]# /usr/lib/zabbix/externalscripts/apdiscovery.sh
{"data":[ {"{#APID}":"0"},{"{#APID}":"1"},{"{#APID}":"2"},{"{#APID}":"3"},{"{#APID}":"4"},{"{#APID}":"5"},{"{#APID}":"6"},{"{#APID}":"7"},{"{#APID}":"8"},{"{#APID}":"9"},{"{#APID}":"10"},{"{#APID}":"11"},{"{#APID}":"12"},{"{#APID}":"13"},{"{#APID}":"14"},{"{#APID}":"15"},{"{#APID}":"16"},{"{#APID}":"17"},{"{#APID}":"18"},{"{#APID}":"19"},{"{#APID}":"20"},{"{#APID}":"21"},{"{#APID}":"22"},{"{#APID}":"23"} ]}
脚本可取出当前设备的 ID 号;并且写出来的格式必须是 JSON 格式。
对应的宏变量值和脚本中对应的变量要一致,并且大写。
#!/bin/bash
id=$(snmpwalk -v 2c -c limi@2018 10.200.252.8 1.3.6.1.4.1.2011.6.139.13.3.10.1.5 | cut -f1 -d "=" | cut -f10 -d ".")
id_array=(${id})
sum=$(snmpwalk -v 2c -c limi@2018 10.200.252.8 1.3.6.1.4.1.2011.6.139.13.3.10.1.5 | awk '{print $4}' | sed 's/"//g' | wc -l)
name=$(snmpwalk -v 2c -c limi@2018 10.200.252.8 enterprises.2011.6.139.13.3.10.1.5 | awk '{print $4}' | sed 's/"//g')
name_array=($name)
printf '{\"data\":[ '
for ((i=0;i<$sum;i++))
do
printf "{\"{#APID}\":\"${id_array[$i]}\",\"{#APNAME}\":\"${name_array[$i]}\" }"
if [ $i -lt $[ $sum-1 ] ];then
printf ','
fi
done
printf " ]}"
自动发现值:
[root@zabbix ~]# zabbix_get -s 127.0.0.1 -k discovery_apid
{"data":[ {"{#APID}":"0","{#APNAME}":"446a-2e13-01e0" },{"{#APID}":"1","{#APNAME}":"446a-2e13-0900" },{"{#APID}":"2","{#APNAME}":"446a-2e13-01c0" },{"{#APID}":"3","{#APNAME}":"446a-2e13-01a0" },{"{#APID}":"4","{#APNAME}":"446a-2e13-0260" },{"{#APID}":"5","{#APNAME}":"446a-2e13-1220" },{"{#APID}":"6","{#APNAME}":"446a-2e17-db80" },{"{#APID}":"7","{#APNAME}":"446a-2e17-dac0" },{"{#APID}":"8","{#APNAME}":"446a-2e17-db00" },{"{#APID}":"9","{#APNAME}":"3F_DONG" },{"{#APID}":"10","{#APNAME}":"446a-2e17-db40" },{"{#APID}":"11","{#APNAME}":"446a-2e17-da60" },{"{#APID}":"12","{#APNAME}":"446a-2e13-2660" },{"{#APID}":"13","{#APNAME}":"446a-2e13-2680" },{"{#APID}":"14","{#APNAME}":"446a-2e13-0e20" },{"{#APID}":"15","{#APNAME}":"446a-2e13-25e0" },{"{#APID}":"16","{#APNAME}":"446a-2e13-2620" },{"{#APID}":"17","{#APNAME}":"446a-2e13-0160" },{"{#APID}":"18","{#APNAME}":"446a-2e13-0980" },{"{#APID}":"19","{#APNAME}":"446a-2e13-2580" },{"{#APID}":"20","{#APNAME}":"446a-2e13-18e0" },{"{#APID}":"21","{#APNAME}":"446a-2e13-2600" },{"{#APID}":"22","{#APNAME}":"446a-2e20-6780" },{"{#APID}":"23","{#APNAME}":"446a-2e20-6760" } ]}
可通过 zabbix_get 得出结果