為什麼要自定義OID?
前面的文章我們已經講過zabbix如何使用snmp監控伺服器,但是他有一個很明顯的局限性:隻能監控定義好的OID項目,假如我們想知道nginx程序是否在運作?在沒有zabbix agent的情況下,我們該怎麼做呢?接下來就用這個實力來講解
自定義OID确認SNMP OID是否存在
首先我們需要找一個oid是否被系統暫用,比如.1.3.6.1.4.1.2021.5000
# 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
編寫腳本
# cat /root/scripts/check_nginx.sh
#!/bin/bash
nginxNum=`/bin/ps aux | /bin/grep nginx | wc -l`
echo $nginxNum
修改配置
# 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
# 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"
建立snmp item
snmp-oid
擷取最新資料
snmp擷取nginx資料