首页 > 代码库 > zabbix使用snmp自定义key

zabbix使用snmp自定义key

1、配置/etc/snmp/snmpd.conf文件增加如下配置,配置在重启snmpd服务后生效

 extend .1.3.6.1.4.1.2021.52 regnum39 /etc/snmp/scripts/regnum.sh regnum39
 extend .1.3.6.1.4.1.2021.52 regnum40 /etc/snmp/scripts/regnum.sh regnum40
 extend .1.3.6.1.4.1.2021.52 totalregnum /etc/snmp/scripts/regnum.sh totalregnum

其中  .1.3.6.1.4.1.2021.52为自定义的oid,regnum39是key名称,/etc/snmp/scripts/regnum.sh是自定义脚本来获取数值,后面的regnum39是regnum.sh的参数


2、zabbix-server上使用下面的命令获取相应的具体的值

[root@zabbix etc]# snmpwalk -v 2c -c public 10.84.10.166 .1.3.6.1.4.1.2021.52 #10.84.10.166为上面修改了snmpd.conf文件的主机ip
UCD-SNMP-MIB::ucdavis.52.1.0 = INTEGER: 3
UCD-SNMP-MIB::ucdavis.52.2.1.2.8.114.101.103.110.117.109.51.57 = STRING: "/etc/snmp/scripts/regnum.sh"
UCD-SNMP-MIB::ucdavis.52.2.1.2.8.114.101.103.110.117.109.52.48 = STRING: "/etc/snmp/scripts/regnum.sh"
UCD-SNMP-MIB::ucdavis.52.2.1.2.11.116.111.116.97.108.114.101.103.110.117.109 = STRING: "/etc/snmp/scripts/regnum.sh"
UCD-SNMP-MIB::ucdavis.52.2.1.3.8.114.101.103.110.117.109.51.57 = STRING: "regnum39"
UCD-SNMP-MIB::ucdavis.52.2.1.3.8.114.101.103.110.117.109.52.48 = STRING: "regnum40"
UCD-SNMP-MIB::ucdavis.52.2.1.3.11.116.111.116.97.108.114.101.103.110.117.109 = STRING: "totalregnum"
UCD-SNMP-MIB::ucdavis.52.2.1.4.8.114.101.103.110.117.109.51.57 = ""
UCD-SNMP-MIB::ucdavis.52.2.1.4.8.114.101.103.110.117.109.52.48 = ""
UCD-SNMP-MIB::ucdavis.52.2.1.4.11.116.111.116.97.108.114.101.103.110.117.109 = ""
UCD-SNMP-MIB::ucdavis.52.2.1.5.8.114.101.103.110.117.109.51.57 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.52.2.1.5.8.114.101.103.110.117.109.52.48 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.52.2.1.5.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.52.2.1.6.8.114.101.103.110.117.109.51.57 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.6.8.114.101.103.110.117.109.52.48 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.6.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.7.8.114.101.103.110.117.109.51.57 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.7.8.114.101.103.110.117.109.52.48 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.7.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.20.8.114.101.103.110.117.109.51.57 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.52.2.1.20.8.114.101.103.110.117.109.52.48 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.52.2.1.20.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.52.2.1.21.8.114.101.103.110.117.109.51.57 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.21.8.114.101.103.110.117.109.52.48 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.2.1.21.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.3.1.1.8.114.101.103.110.117.109.51.57 = STRING: "664"
UCD-SNMP-MIB::ucdavis.52.3.1.1.8.114.101.103.110.117.109.52.48 = STRING: "662"
UCD-SNMP-MIB::ucdavis.52.3.1.1.11.116.111.116.97.108.114.101.103.110.117.109 = STRING: "1326"
UCD-SNMP-MIB::ucdavis.52.3.1.2.8.114.101.103.110.117.109.51.57 = STRING: "664"
UCD-SNMP-MIB::ucdavis.52.3.1.2.8.114.101.103.110.117.109.52.48 = STRING: "662"
UCD-SNMP-MIB::ucdavis.52.3.1.2.11.116.111.116.97.108.114.101.103.110.117.109 = STRING: "1326"
UCD-SNMP-MIB::ucdavis.52.3.1.3.8.114.101.103.110.117.109.51.57 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.3.1.3.8.114.101.103.110.117.109.52.48 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.3.1.3.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.52.3.1.4.8.114.101.103.110.117.109.51.57 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.52.3.1.4.8.114.101.103.110.117.109.52.48 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.52.3.1.4.11.116.111.116.97.108.114.101.103.110.117.109 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.52.4.1.2.8.114.101.103.110.117.109.51.57.1 = STRING: "664" #regnum39输出的值
UCD-SNMP-MIB::ucdavis.52.4.1.2.8.114.101.103.110.117.109.52.48.1 = STRING: "662" #regnum40输出的值
UCD-SNMP-MIB::ucdavis.52.4.1.2.11.116.111.116.97.108.114.101.103.110.117.109.1 = STRING: "1326" #totalregnum输出的值


3、在zabbix的web界面增加item

注意snmp oid为snmpd.conf配置文件中的oid+snmpwalk获取到的后半部分

比如说,

regnum39这个key的snmp oid为 .1.3.6.1.4.1.2021.52.4.1.2.8.114.101.103.110.117.109.51.57.1

regnum40这个key的snmp oid为.1.3.6.1.4.1.2021.52.4.1.2.8.114.101.103.110.117.109.52.48.1

totalregnum这个key的snmp oid为.1.3.6.1.4.1.2021.52.4.1.2.11.116.111.116.97.108.114.101.103.110.117.109.1

技术分享


技术分享

zabbix使用snmp自定义key