自学Zabbix11.6 Zabbix SNMP自定义OID
为什么要自定义OID?
前面已经讲过zabbix如何使用snmp监控服务器,但是他有一个很明显的局限性:只能监控定义好的OID项目,假如我们想知道nginx进程是否在运行?在没有zabbix agent的情况下,我们该怎么做呢?接下来就用这个实力来讲解自定义OID
确认SNMP OID是否存在?
首先我们需要找一个oid是否被系统暂用,比如.1.3.6.1.4.1.2021.5000
1
2
|
# snmpwalk -v 2c -c public www.ttlsa.com .1.3.6.1.4.1.2021.5000
UCD-SNMP-MIB::ucdavis.5000 = No Such Object available on this agent at this OID
|
如上说明不存在。
增加自定SNMP OID
编写脚本
1
2
3
4
|
# cat /root/scripts/check_nginx.sh
#!/bin/bash
nginxNum=`/bin/ps aux | /bin/grep nginx | wc -l`
echo $nginxNum
|
修改配置
1
2
|
# vim /etc/snmp/snmpd.conf
extend .1.3.6.1.4.1.2021.5000 check_nginx /root/scripts/check_nginx.sh // 增加这一行
|
获取snmp信息
以下获取自定义的oid的所有数据,第一行便是我们需要获取的数据,那么在zabbix中写oid .1.3.6.1.4.1.2021.5000.4.1.2.11.99.104.101.99.107.95.110.103.105.110.120.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# snmpwalk -v 1 -c public 173.219.255.122 .1.3.6.1.4.1.2021.5000
UCD-SNMP-MIB::ucdavis.5000.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.5000.2.1.2.11.99.104.101.99.107.95.110.103.105.110.120 = STRING: "/root/scripts/check_nginx.sh"
UCD-SNMP-MIB::ucdavis.5000.2.1.3.11.99.104.101.99.107.95.110.103.105.110.120 = ""
UCD-SNMP-MIB::ucdavis.5000.2.1.4.11.99.104.101.99.107.95.110.103.105.110.120 = ""
UCD-SNMP-MIB::ucdavis.5000.2.1.5.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.5000.2.1.6.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.5000.2.1.7.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.5000.2.1.20.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.5000.2.1.21.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.5000.3.1.1.11.99.104.101.99.107.95.110.103.105.110.120 = STRING: "6"
UCD-SNMP-MIB::ucdavis.5000.3.1.2.11.99.104.101.99.107.95.110.103.105.110.120 = STRING: "6"
UCD-SNMP-MIB::ucdavis.5000.3.1.3.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.5000.3.1.4.11.99.104.101.99.107.95.110.103.105.110.120 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.5000.4.1.2.11.99.104.101.99.107.95.110.103.105.110.120.1 = STRING: "6"
|