Saturday, March 6, 2010

Using Net-SNMP - 1

Hi,

In this N part series, I shall post about

What SNMP is - very, very briefly
Install NetSNMP
Configure NetSNMP
Write a MIB
Use Mib2c to generate stubs for the agent
Populate the Stub code in the agent for the MIB you just wrote
Try and GET snmp to WALK through the NEXT few steps :)

Write more complex MIBs


Ok lets begin then, shall we..........

SNMP (Simple Network Management Protocol) is application layer protocol, mostly used in network devices (i.e. routers, printers, etc). In typical SNMP usage scenario SNMP client sends SNMP Get package to the network device in order to read its properties. When device reports any problems it is also possible to change device configuration using SNMP Set packages. Every device supports various queries (i.e. device uptime) and all of them are described in MIB (Management Information Base).


You can read more about SNMP protocol here: http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol


I told you guys I will be brief :)


Ok ....Now for the Installation ........

First, You will need a Linux System.......because all that I am going to explain next will be for that particular OS

I use Suse Linux 11.2, although I guess RedHat and Gentoo and Debian work just as fine .........

Ok, Login to the linux system ............By the way..............The download is available @ http://net-snmp.sourceforge.net/download.html

You need to pick up the SOURCE of the latest version ......Do not pick up binary, then you cannot play around with the source code. Get the tar.gz , since you will intend to use it on linux (Zip format is for wussies :) )

Ok, so you have the download in your home folder ........ (/home/ folder , where is whatever name you are using to log in.) all ready to be untarred

You will need root privilege to install so issue this command at prompt

$su - root you will be asked for root password , so give that and you are in

Navigate to the home folder where the net snmp tar.gz is kept
Issue this command at the prompt

#tar -zxvf net-snmp-5.5.tar.gz (I happen to be using version 5.5)

It will untar the whole thing and give you a directory like so

# ll
total 5408
drwxr-xr-x 19 274 500 4096 Mar 6 13:57 net-snmp-5.5
-rw-r--r-- 1 root root 5531055 Mar 3 23:21 net-snmp-5.5.tar.gz
#


Navigate into the net-snmp-5.5 directory and you should see something like so




Just have a look at the various README's etc. Or take a break.....or watch TV :) ....Till you are ready to go cracking again.......

The steps you need to do now are
1) Run ./configure
(type "./configure --help" for a quick usage summary.)
(--prefix=PATH will change the default /usr/local installation path.)

2) Optionally edit include/net-snmp/net-snmp-config.h
(due to prompting done by the configure script, this is very rarely
necessary.)

3) make

4) make test (This usually tells you right away whether everything on
the system is good to go or not)

5) make install


Ok......it will take some time....print what its doing all the while..... and then its done

You now have netsnmp installed and ready to use.

Ha Ha .....not quite.......theres still a lot of stuff that needs to be done before we can say .....yup....thats working beautifully.......

Navigate to

1. See if
/usr/local/share/bin folder has a bunch of snmp stuff like snmpconf snmptranslate and so on
2. See if the
/usr/local/share/snmp/mibs folder and see if all the MIB files are present

Now you have to
try some configurations checking

First, give
#net-snmp-config --default-mibdirs


/root/.snmp/mibs:/usr/local/share/snmp/mibs
You should get the reply like so....a list of the directories which are used to pick up snmp MIB data

Now run
linux-725y:/usr/local # net-snmp-config --snmpconfpath

/usr/local/etc/snmp:/usr/local/share/snmp:/usr/local/lib/snmp:/root/.snmp:/var/net-snmp
You should get the reply like so....a list of the paths which are used to pick up snmp configuration data

Now run

# ldd /usr/local/bin/snmptranslate
linux-gate.so.1 => (0x00110000)
libnetsnmpagent.so.15 => not found
libnetsnmphelpers.so.15 => not found
libnetsnmpmibs.so.15 => not found
libnetsnmp.so.15 => not found

This means that you might get snmp*: error while loading shared libraries:
like for example as mentioned above libnetsnmp.so.20: It cannot open shared object file

If no error comes like above , no need to do anything, but if error comes, then, you have to do the steps below
Edit ld.so.conf in /etc and add the details of the lib path of /usr/local/lib and then run ldconfig
#vi /etc/ld.so.conf

/usr/X11R6/lib/Xaw3d
/usr/X11R6/lib
/usr/lib/Xaw3d
/usr/i386-suse-linux/lib
/usr/local/lib
/opt/kde3/lib
include /etc/ld.so.conf.d/*.conf

#ldconfig

Now you have to tell netsnmp where to look for MIB files. You use the snmpconf command to do this. Issue this command at the prompt
# snmpconf

I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)

1: snmpd.conf
2: snmptrapd.conf
3: snmp.conf

Other options: quit

Select File: 3

The configuration information which can be put into snmp.conf is divided
into sections. Select a configuration section for snmp.conf
that you wish to create:

1: Debugging output options
2: Textual mib parsing
3: Output style options
4: Default Authentication Options

Other options: finished

Select section: finished

I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)

1: snmpd.conf
2: snmptrapd.conf
3: snmp.conf

Other options: quit

Select File: quit


The following files were created:

snmp.conf

These files should be moved to /usr/local/share/snmp if you
want them used by everyone on the system. In the future, if you add
the -i option to the command line I'll copy them there automatically for you.

Or, if you want them for your personal use only, copy them to
/root/.snmp . In the future, if you add the -p option to the
command line I'll copy them there automatically for you.

#cp snmp.conf /usr/local/share/snmp/

Finally try this
# snmptranslate -Tp -IR ipMIB
+--ipMIB(48)
|
+--ipMIBConformance(2)
|
+--ipMIBCompliances(1)
| |
| +--ipMIBCompliance(1)
| +--ipMIBCompliance2(2)
|
+--ipMIBGroups(2)
|
+--ipGroup(1)
+--icmpGroup(2)
+--ipv4GeneralGroup(3)
+--ipv4IfGroup(4)
+--ipv6GeneralGroup2(5)
+--ipv6IfGroup(6)
+--ipLastChangeGroup(7)
+--ipSystemStatsGroup(8)
+--ipv4SystemStatsGroup(9)
+--ipSystemStatsHCOctetGroup(10)
+--ipSystemStatsHCPacketGroup(11)
+--ipv4SystemStatsHCPacketGroup(12)
+--ipIfStatsGroup(13)
+--ipv4IfStatsGroup(14)
+--ipIfStatsHCOctetGroup(15)
+--ipIfStatsHCPacketGroup(16)
+--ipv4IfStatsHCPacketGroup(17)
+--ipAddressPrefixGroup(18)
+--ipAddressGroup(19)
+--ipNetToPhysicalGroup(20)
+--ipv6ScopeGroup(21)
+--ipDefaultRouterGroup(22)
+--ipv6RouterAdvertGroup(23)
+--icmpStatsGroup(24)
linux-725y:/usr/local #

This means that everything that you have installed is working

So now the errors are not going to be there because of configuration ......whatever gets screwed up , it will be because of your responsibilty :)

Next part will deal with How to write a MIB and add code from the agent.

4 comments:

AsHwin said...

The information was very useful.

We missed the point of accessing the root privileges in the first step itself.

In UBUNTU Linux during installation it does not prompt password for root access. However, this password is set after installation.

just follow this procedure: :)

open a terminal and issue the command at prompt "sudo passwd" (without quotes).

now key in the password you gave during installation.

then it allows you to set new password which is also the root password.
:)

Now the root password is set.

next during the process of installation (for UBUNTU users), you will encounter an abrupt exit during make of the source files (i.e after ./configure).
it is necessary to install perl lib files.

to install this package- @ command prompt issue "sudo apt-get install libperl-dev" (again without quotes).

in few minutes this package gets installed.

now install net-snmp-5.5... :)

AsHwin said...
This comment has been removed by the author.
Unknown said...

hi hope u doing wellllll

i want to know dat how we can get the dynamic value in C file generated by netsnmp mib2c .

u didn't provide any information related to that. please provides some database connectivity like things in those file. i'll be very thankful to you......

Unknown said...

The tutorial is great. Helped me a lot. Thank you.. :)