write mib and let it run

来源:互联网 发布:云计算培训有价值吗 编辑:程序博客网 时间:2024/05/21 20:03

1.write mib
尽管这里没有具体写,但是写一个mib文件是很费力的事情。
将自己的mib文件放到: /etc/sma/snmp/mibs
(refs:
http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS)
让snmpd加载你写的mib文件:
/etc/sma/snmp/snmp.conf:
追加一行: mibs +NET-SNMP-TUTORIAL-MIB
或者:
export MIBS=+NET-SNMP-TUTORIAL-MIB
svcadm restart svc:/application/management/sma:default
test your mib with snmptranslate:
根据名字得到OID:
snmptranslate -m +NET-SNMP-TUTORIAL-MIB -IR -On nstAgentPluginObject
或者:
snmptranslate -On NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject
(.1.3.6.1.4.1.8072.2.4.1.1.3:numeric OID
NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject:textual MIB name)
根据OID得到名字:
snmptranslate .1.3.6.1.4.1.8072.2.4.1.1.3
根据部分名字查找;
snmptranslate -IR nstAgentPluginObject
遍历mib树:
snmptranslate -Tp -IR system
显示详细:
snmptranslate -On -Td -IR sysUpTime
(refs:
http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmptranslate)

2.write c
use mib2c to generate c code template:
pfexec mib2c -c /etc/sma/snmp/mib2c.int_watch.conf nstAgentPluginObject
write the implement nstAgentPluginObject.c
3.compile source
先要确认现在使用的snmpd是否支持dlmod,如果不支持的话,就要从source自己编译了,确认方法是snmpd -H,然后查看输出是否有dlmod关键字,有的话,就是支持;
(注意系统中正在使用的snmpd版本是否和自己下载的source版本一致,如果相差很多的话,请下载相差最小的source,然后再运行下面的命令,否则的话会出现动态链接库被加载,但是实际上没有生效的情况)
./configure --enable-shared --with-mib-modules="ucd_snmp"
cc -m64 -I yourSNMPSourcePath/net-snmp-5.0.11.2/include `net-snmp-config --cflags` -fPIC -shared -g -O0 -o nstAgentPluginObject.so nstAgentPluginObject.c `net-snmp-config --libs`
modify snmpd.conf file:
dlmod nstAgentPluginObject yourDemoPath/nstAgentPluginObject.so
pfexec svcadm disable svc:/application/management/sma:default
pfexec svcadm enable svc:/application/management/sma:default
cat /var/log/snmpd.log
pfexec snmptable -v2c -c public localhost UCD-DLMOD-MIB::dlmodTable
pfexec snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0
pfexec snmpset -v2c -c private localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0 = 5
pfexec snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0

 

参见我写的另外一篇文章:

http://blog.csdn.net/lantianjialiang/archive/2010/04/22/5515152.aspx