对于更多的net-snmp的资料,可以去www.net-snmp.org中获得.
另外,net-snmp在FC6上可以正确编译通过,在FC4上编译时却发现二个错误,一个是找不到libbeencrypt.la这个文件,第二个错误是无法链接到elf库.
如果出现这二个错误,去网络上下载以下二个软件包进行编译就行了:
1.beecrypt-4.1.2.tar.gz
2.libelf-0.8.10.tar.gz
On Redhat 7.1 or above, NetSnmp has become the default snmp...
But on other linux version. It is still a good guide.
In this tutorial we will
This package was previously known as ucd-snmp
$gunzip net-snmp-5.0.pre2.tar.gz $tar xvf net-snmp-5.0.pre2.tarThis will dump all the souce into $/net-snmp-5.0.pre2
$./configure --with-mib-modules="agentx" $make $make install $cd local; make install; cd .. $cd mibs; make install; cd ..The "configure" command configure the agent to use the AgentX protocol. This is a IETF defined protocol that allows a master/client relationship between agents and subagents. The last two command should not theoretically have to be to used ... but without them .. things do not seem to work. Now, we have to setup the snmpd configuration file, before "snmpd" can work properly.
$ cp $/EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
$ln -s /usr/local/lib/libnetsnmp-0.5.0.0.2.so /lib/libnetsnmp-0.5.0.0.2.so $ln -s /usr/local/lib/libnetsnmpagent-0.5.0.0.2.so /lib/libnetsnmpagent-0.5.0.0.2.so $ln -s /usr/local/lib/libnetsnmphelpers-0.5.0.0.2.so /lib/libnetsnmphelpers-0.5.0.0.2.so $ln -s /usr/local/lib/libnetsnmpmibs-0.5.0.0.2.so /lib/libnetsnmpmibs-0.5.0.0.2.so
$ ps awwux | grep snmpif you see an earlier snmpd deamon ... kill it
$ cd $/net-snmp-5.0.pre2/agent $ ./snmpd -f -LThis should start the "snmpd" agent but keep it attached to the current terminal (which is useful since we want to kill it very soon).
$snmpget -v 1 -c democommunity localhost system.sysUpTime.0If snmpd was installed correctly, this gives up the timeticks the snmpd agent has been up (NOT how long your system was up !!). If you get an error .. retrace your steps from the beginning.
You can now use "^C" to kill the snmpd deamon in the first window.
In this part of the the tutorial we will write and install a simple MIB.
JM-TEST-1-MIB DEFINITIONS ::= BEGIN IMPORTS MODULE-IDENTITY, OBJECT-TYPE, INTEGER FROM SNMPv2-SMI; jmtest MODULE-IDENTITY LAST-UPDATED "200203210000Z" ORGANIZATION "Temple U" CONTACT-INFO "None yet." DESCRIPTION "AgentX testing MIB" REVISION "200203210000Z" DESCRIPTION "None yet." ::= { experimental 72} firstKey OBJECT-TYPE SYNTAX INTEGER (0..100) MAX-ACCESS read-write STATUS current DESCRIPTION "Value initialized to 0 and on each access: - Return current val. - increment" ::= { jmtest 1 } END
This mib represents a resource "firstKey" whose initial value is 0 and whose value gets incremented every time it is queried.
Note that this MIB will be registered under the 1.3.6.1.3.72 heirarchy. This choice is arbitrary and should only be used for experiments. For real world implementation you should get a "real" OID. Existing OIDs and guidelines on getting new ones can be fo und here. This page is maintained by the current (March 2002) IETF/IESG chair, so he probably knows what he is talking about.
Copy this mib into the mibs directory
$cp JM-TEST-1-MIB.txt /usr/local/share/snmp/mibs
$echo "mibs +JM-TEST-1-MIB" >> /usr/local/share/snmp/snmp.confThis adds a directive to the snmp tools configuration asking them load our mib.
$snmptranslate -IR -Tp experimentalThis command will draw the present tree under the experimental branch. Omit the last parameter and you will get the whole tree (as currenly understood by the snmp tools). The output should look like:
Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } +--experimental(3) | +--jmtest(72) +-- -RW- INTEGER firstKey(1) Range: 0..100If you get the above output, then we are in good shape so far. The real work, howeve still remains. We must now write the subagent that will handle queries on under this OID branch.
In this section we will write and install a subagent that serves the mib we installed in the previous section.
The subagent is an independent program that communicates with the master agent (snmpd in our case) using the AgentX protocol.
The basic steps of writing the code is as follows:
mib2c is (supposed to) take in the MIB definition as spit out the subagent code. However (as far as I could figure out) the mib2c program distributed with this version of net-snmp does not generate code for simple scalar mibs, instead dealing with mibs th at have tables.
So for an example of subagent code for simple scalar objects look at $/agent/mibgroups/example/example.c.
We have adapted example.c for our mib (JM-TEST-1-MIB.txt) as example2.c.
$mkdir $/agent/mibgroup/examples/subagent $cp example2.c $/agent/mibgroup/examples/subagent $cp example.h $/agent/mibgroup/examples/subagentNow we create the executable using the net-snmp-config tools as:
$net-snmp-config --compile-subagent example2 example2.c -I../../../mibgroupThis produces a executable called example2. example2 is our subagent. Voila !
To test whether things are still working.
In first window:
$cd $/agent $./snmpd -f -L -DThis will start the snmpd deamon in the debugging mode (you will see LOTS of messages).
In the second window:
$cd agent/mibgroup/examples/subagent $./example2Finally in the third window, the command and output should look like (output is shown in bold):
[root@x mibs]# snmpget -v 1 -c democommunity localhost firstKey.0 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 1 [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 2 [root@x mibs]# snmpset -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0 i 10 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 10 [root@x mibs]# snmpget -v 1 -c democommunity localhost firstKey.0 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 10 [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 11 [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0 Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 12 [root@x mibs]# snmpwalk -v 1 -c democommunity localhost firstKey Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 } JM-TEST-1-MIB::firstKey.0 = 13In the output above notice that every snmpget query returns an increasing value of "firstKey" and snmpset lets us set "firstKey" to an arbitrary value (within a defined range).
We now have a working subagent. In real applications the subagent could be embedded in the application to be managed.
--by Jaiwant Mulik, March 2002.
------------------------------------------------------------------------------------------------------------------------