Simple Is Not Easy

Simple is not always Easy, and SNMP is a good example for this. In this blog I will try to broach on a few simple things about SNMP, and I hope you will find this introduction useful.

SNMP stands for Simple Network Management Protocol - and is one of the most widely spread internet management protocols. It is based on UDP (though there exists an RFC defining SNMP over TCP) and uses BER for encoding.

SNMP is an internet technology - specified by means of RFCs (Requests For Comments), which are issued through the Internet Engineering Task Force (IETF)

SNMP defines both how to structure management information (data model exposed for management), and how to access it (protocol). According to SNMP, the management information is structured into MIBs (Management Information Bases). A MIB is defined using a formal language called Structure of Management Information (SMI) - whose syntax uses a subset of ASN.1.

So when we speak of SNMP we usually mean two things:

  • The protocol itself - of which there exists three main versions: SNMPv1, SNMPv2c, and SNMPv3 (see below).
  • The Structure of Management Information - which is the formal language in which MIBs are specified, and of which there exists two versions, SMIv1 and SMIv2

The basic verbs of the SNMP protocol are GET, SET, and GETNEXT (SNMPv2 adds GETBULK). An SNMP entity can also send asynchronous events (a TRAP in SNMPv1, a NOTIFICATION or an INFORM in SNMPv2). What you GET and SET are individual variables of simple types (to simplify, strings/integers/enumerations) which can be either scalar - or located in tables.
These are the simple things about SNMP. Rest assure, I will not enter into more details today. But if you want to dig it further, here are a few additional links that will help you:

Looking for an RFC? Just type its number here:

I can also recommend some good books on SNMP:

  • Understanding SNMP MIBs, by Perkins and McGinnis, published by Prentice Hall
  • Practical Guide to SNMPv3 and Network Management by David Zeltserman, Published by Prentice Hall.

Now at this point, you're probably wondering why you're reading this blog, and what all of this has to do with JMX, Java, etc...
Well the thing is that starting with Tiger, and following with Mustang, Java SE now comes with a built-in SNMPv2 agent, that makes it possible to access the data exposed by the JVM Management and Monitoring API through SNMP.
As we have seen, SNMP requires that the data exposed for management is described in a MIB - and the MIB that describes the data of the Management and Monitoring of the JVM is the JVM-MANAGEMENT-MIB.

In a further blog, I am planning to delve further into the workings of SNMP and the JVM-MANAGEMENT-MIB. I may also make use of the Java Dynamic Management Kit - which includes a Java SNMP toolkit - in order to demonstrate how the JVM can be monitored through SNMP

So until then, stay tuned!

PS: see also my next entries in this series: [What is the JVM SNMP Agent?] [Life, the Universe, and Everything... or the Hitchhiker's Guide to SNMP] [Understanding the Structure of Management Information (SMI)... or the Hitchhiker's Guide to SNMP, Part-II] [Don't fall in the traps... or the Hitchhiker's Guide to SNMP, Part-III] [Traces in the JVM SNMP Agent], [Welcome to the SNMP table!.. or the Hitchhiker's Guide to SNMP, Part-IV].


Excellent, just when I need to use an SNMP agent, along one comes. I'd be interested to know whether the Java SE SNMPv2 agent can get information from all network devices, or just ones related to the JVM.

Posted by Rory on February 16, 2006 at 05:02 AM CET #

Hi Rory,

The JVM SNMP agent just provides information about the JVM in which it's running - it won't allow you to get information from any other SNMP devices.

If you want to retrieve information from SNMP devices - you will need to use an SNMP API for Java - like for instance the Java DMK (see link on this page) - or other libraries/toolkit which you will easily find with a Google Search.

Does that answer your question?

Posted by Daniel Fuchs on February 16, 2006 at 08:20 AM CET #

Hi, I ned to convert JMX notifications (which are in .dat format) to SNMP traps.I have been told that I can use mibgen to create the MIB based MBeans in which I can add more functionalities later on.However, the mibgen tool takes SNMP MIB files as input.Could you suggest a way to convert these dat files to SNMP MIB? Or a better workaround? I had posted my query earlier also but the mail got deleted by mistake! :( Thanks in advance! Pooja

Posted by pooja on May 07, 2007 at 01:27 AM CEST #

Hi Pooja,

You're heading the wrong way here.
What you need to do is:

1) Understand what an SNMP trap is and how it is used
2) Understand what are the requirement that drives you to convert a JMX Notification into a trap
3) Understand what the SNMP manager who will receive the trap will do with it.

By answering these three questions you will be able to know what kind of traps you need, and how they should look like.

Then you will a) write a MIB in which you will define these trap, or b) you will find MIBs which already define the traps you need.

If it's a) then you will need to find out whether you company as an IANA assigned number for SNMP. For instance, as I have already explained, Sun Microsystems has number 42.

If your company doesn't have such a number and you want to write your MIB, then you will need to apply for that.

When your MIB is written, you can use mibgen if you want to generate a table [OID-label,OID-value]. It's the only interesting thing that mibgen generates for traps. However, you do not really need to perform this step. You can use directly the OID-values when you build your Trap PDU. You don't really need mibgen to send trap. Just send them.

What you really need to do is to define the traps you want to send, and write this definition into a MIB, so that you can explain what the trap is and how it is supposed to be used.

See: Don't fall in the traps... to learn more about traps, and the Java DMK 5.1 Tutorial to learn how to send traps.

I also suggest reading "Understanding SNMP MIBs", by Perkins & McGinnis, Prentice Hall.

-- daniel

Posted by daniel on May 09, 2007 at 09:27 AM CEST #

Excellent post, I am new to snmp this blog has helped me a lot in understanding it. We need to generate snmp traps from our java application, can you suggest me from where to start? what open source libraries are available?
some tutorials?

Posted by sudhir on November 26, 2007 at 12:07 AM CET #

Hi Sudhir,

What I would suggest is to start with the trap defininition. First you should determine what kind of application is going to consume the traps, and what it will do with these traps. This will help you understand which trap you need to generate, and what kind of information they should contain.

While doing this you must take into account the limitation of the SNMP protocol: size limitation, and the fact that the trap may be lost - either by the network, or because of buffer overflow on the client side if your application emits too many traps with a high frequency.

When this is done you can start writing your trap definitions (your MIB). Put as much explanation as you can in the object descriptions: the reader should understand what this is all about just by reading the MIB.

You may have already read this post:
"Don't fall in the traps"
if not you probably should ;-)

As regards to open source libraries you might want to use OpenDMK - or else I'm sure that a quick google for snmp+java will reveal other candidates.

Hope this helps!
-- daniel

Posted by daniel on November 26, 2007 at 02:48 AM CET #

Hi denial,
Thanks for your reply.
We need to generate simple application alerts, this traps will be consumed by snmp manager (IBM Tivoli).

Posted by sudhir on November 26, 2007 at 03:37 AM CET #

This is great.. Valuable info.
I've been referring to many SNMP docs. But one you specified "Understanding SNMP MIBs" is one of the best I found. Got cleared lot of grey areas.. Thanks for that.

Posted by guest on November 23, 2011 at 05:14 PM CET #

Post a Comment:
Comments are closed for this entry.

Daniel Fuchs blogs on Scene Builder, JMX, SNMP, Java, etc...

The views expressed on this blog are those of the author and do not necessarily reflect the views of Oracle.


« July 2016