ArticleDirectory
- Download and install net-snmp package
The following article is reprinted on the network, because I recently encountered the problem of configuring the SNMP agent in Linux, which helped me a lot from the first blur to the final configuration.
For more net-snmp information, can be obtained in the www.net-snmp.org.
In addition, net-snmp can be correctly compiled on fc6, but two errors are found during FC4 compilation. One error is that libbeencrypt cannot be found. the second error is that the file la cannot be linked to the elf library.
If these two errors occur, download the following two software packages on the network for compilation:
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
- Download and install net-snmp,
- Write and install a simple MiB,
- Write a subagent to handle to MiB.
Download and install net-snmp package
This package was previusly known as UCD-SNMP
-
- Download the source from here, or if this link is broken try the net-snmp homepage, to your local directory which we will now refer to as $. For this tutorial we will use net-snmp-5.0-pre2.
-
- Change directory to $, untar and unzip the package using:
$ Gunzip net-snmp-5.0.pre2.tar.gz
$ Tar xvf net-snmp-5.0.pre2.tar
This will dump all the Souce into $/net-snmp-5.0.pre2
- To compile to package:
$./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 shocould
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.
-
- Copy the example configuration file:
$ CP $/example. CONF/usr/local/share/snmp/snmpd. conf
- now we need to modify/usr/local/share/snmp/snmpd. conf as follows:
- replace community with "democommunity". This is your community string.
- comment out 2nd "com2sec" line. We do not allow network access for now.
- On
A new line at the end of the file Add "Master agentx ". this tells the
agents to behave as the master in the master/client agentx protocol.
- We
Now need to fix some library links (this is truely awful... Is this
RedHat or a net-snmp "problem"/"feature "?) (Note: On some machines this
Is not required e. g Redhat 7.1... use your judgement :-))$ 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
-
- To check "snmpd" do:
Become root$ PS awwux | grep SNMP
If you see an earlier snmpd deamon... kill it
$ CD $/net-snmp-5.0.pre2/agent
$./Snmpd-F-l
This
Shocould start the "snmpd" agent but keep it attached to the current
Terminal (which is useful since we want to kill it very soon ).
- On another window:
$ Snmpget-V 1-C democommunity localhost system. sysuptime.0
If
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
Error .. retrace your steps from the beginning.
You can now use "^ C" to kill the snmpd deamon In the first window.
Writing and installing a MIB
In this part of the Tutorial we will write and install a simple MIB.
- First write the MIB that you want to implement. For our tutorial we write a simple MIB called JM-TEST-1-MIB.txt:
JM-TEST-1-MIB definitions: = begin
Imports
Module-identity,
Object-type,
Integer
From SNMPv2-SMI;
Jmtest module-Identity
Last-updated "200203220.z"
Organization "Temple U"
Contact-Info
"None yet ."
Description
"Agentx testing MIB"
Revision "200203220.z"
Description
"None yet ."
::={ Experimental 72}
Firstkey object-type
Syntax INTEGER (0 .. 100)
Read-write MAX-ACCESS
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 shoshould only be used for experiments. For real
World implementation you shoshould 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
-
- Now we need to get the SNMP tools to recognize this MIB. So:
$ Echo "mibs + JM-TEST-1-MIB">/usr/local/share/snmp. conf
This adds a directive to the SNMP tools configuration asking them load our MIB.
- to verify if our MiB is loaded use the verstile snmptranslate command:
$ snmptranslate-ir-TP experimental
This
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 shoshould look like:
unlinked oId in JM-TEST-1-MIB: jmtest ::={ experimental 72}
+ -- Experimental (3)
|
+ -- jmtest (72)
+ ---RW-integer firstkey (1)
range: 0 .. 100
If
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.
Writing and installing a subagent
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:
- Write the agent code in a C file, say example. C. This can be done using the mib2c tool.
- Create the subagent executable using the net-snmp-config tool.
Mib2c
Is (supposed to) Take in the MIB definition as spit out the subagent
Code. However (as far as I cocould figure out) The mib2c Program
Distributed with this version of net-snmp does not generate code
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. C.
We have adapted example. C for our MIB (jm-test-1-mib.txt) as example2.c.
Download example2.c and example1.h
$ Mkdir $/agent/mibgroup/examples/subagent
$ CP example2.c $/agent/mibgroup/examples/subagent
$ CP example. h $/agent/mibgroup/examples/subagent
Now we create the executable using the net-snmp-config tools:
$ Net-snmp-config -- compile-subagent example2 example2.c-ihttp: // www.cnblogs.com/./mibgroup
This producesExecutableCalled example2. example2 is our subagent. Voila!
To test whether things are still working.
In first window:
$ CD $/agent
$./Snmpd-F-l-d
This will start the snmpd deamon In the debugging mode (you will see lots of messages ).
In the second window:
$ CD agent/mibgroup/examples/subagent
$./Example2
Finally in the third window, the command and output shoshould 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 = 13
In
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 cocould be embedded in the application to be managed.
--Jaiwant mulik, March 2002.