5

After reading up on SNMP and some of the questions help here I think understand the agent role as a SNMP service to device (Like SQL, it is an API to storage).

When you execute a SQL query the SQL engine does all the work and returns the result - You don't need to be aware of how the storage and where the storage is done.

But MIBs are not actual storage , so what is the role of my agent?
if the agent only register the MIB like i follow in this tutorial, so it not used as handler at all and it means that there is a pyhiscal storage that you can set and get to there without bypass the handler. in the tutorial all you do it this:

netsnmp_register_int_instance("my example int variable",
                                  my_registration_oid,
                                  OID_LENGTH(my_registration_oid),
                                  &example1, NULL);

no need in handler to process calls.

Say that I want monitor my application's pending request queue, so I want an agent that all SNMP request for application_pending_request will be fired for it and it will return the queue depth. Why do I need to have an actual MIB when all I need to poll my application queue in order to get result?

Avihai Marchiano
  • 592
  • 3
  • 15
  • 32

1 Answers1

7

You have a fundamental misunderstanding of how SNMP works. Quick and dirty comparison: SNMP MIBs are the like hostnames. MIBs map OIDs to a friendly name -- for example
.1.3.6.1.2.1.1.1.0 => SNMPv2-MIB::sysDescr.0 => Host Description (uname output).

In order to retrieve information from an SNMP server (agent) that information must be published at a specific OID.
In order for an SNMP daemon to publish information it needs (typically) two things:

  1. A way of getting that information (script, program, etc.)
  2. A place to put that information (an OID)
    (Some SNMP daemons may also require a MIB file mapping the OID)

In order for you to retrieve the information you must know the OID - this can either be a numeric OID or a "friendly" name out of a MIB file on your SNMP Client.

SNMP "browsers" typically require a MIB file because without one all they can present to you is a meaningless list of numbers.

So the answer to your question is "You don't NEED MIB files, they're just helpful for humans who need to interact with SNMP".


Taking your example (reporting a queue length), it sounds from the tutorial you liked to like you're using net-snmp (UCD-SNMP).
net-snmp includes built-in facilities for this sort of thing -- read through the man page and example configuration file (pay special attention to the exec directive for running external scripts: Typically you would run a script that prints the queue length, and query that OID in your monitoring software/SNMP Client)

voretaq7
  • 79,345
  • 17
  • 128
  • 213
  • Sorry , but still dosnt understand. I update by question with quote from the tutorial. In the agent i need is to register the MIB, after registration snmpset or snmpget dosnt pass through any handler, so what the benefit of agnent? – Avihai Marchiano Aug 28 '12 at 16:31
  • @user1495181 you are not registering a *MIB*, you are registering an ***OID***. You are saying that this information will be published on this agent with a specific OID, and that the OID value should be populated by a given handler function. (In the tutorial example you pasted the handler is `NULL`, which means net-snmp doesn't do anything. You have to *write a function* to get the data you want and specify it as the handler for that OID...) – voretaq7 Aug 28 '12 at 16:33
  • 1
    @user1495181 If you are out of your depth with SNMP (based on the questions you've been asking **you are**) I strongly suggest two things: (1) Stick to [external scripts](http://www.net-snmp.org/wiki/index.php/Tut:Extending_snmpd_using_shell_scripts), preferably ones called with the `exec` keyword from `snmpd.conf` (they are much simpler to set up and get working than C extensions), and (2) Pick up a copy of [Essential SNMP](http://shop.oreilly.com/product/9780596008406.do) and read through it. – voretaq7 Aug 28 '12 at 16:37
  • agree i register OID (thank you for the correction). but .... 1. you can call snmset from commandline and set value , so this means that there is pyhsical behind and you bypass any agent/ handler. 2. the handler in the API is void. i read a lot but didnt find explain for how can i have pyhisical where i have agent. – Avihai Marchiano Aug 28 '12 at 16:39
  • 2
    @user1495181 The ability to use `snmpset` is provided by the default integer handler (which is what you get when you register an OID of type `int` with a handler function of `NULL`). The agent stores the value in memory and returns it when asked for that OID (until such time as the agent is restarted or a new value is set). You *can* theoretically achieve what you want in terms of monitoring by having a script `snmpset` the OID periodically, but that is sub-optimal. An external script call (or a proper handler function) is the *right* way to do this... – voretaq7 Aug 28 '12 at 16:45
  • yep this is what i do i periodically call to snmpset, so you said that the handler is the key here, but the handler is void and you dont know if its set or get. do you have a reference to write with handler ? lets the the CPU utilization for example, if i understand you correct when i call to snpget for this OID than snmpd know to execute the CPU handler and get the value. it dosnt go to some pyhsical MIB storage for the value. it query the CPU by call handler. – Avihai Marchiano Aug 28 '12 at 16:52
  • @user1495181 Handlers registered in that way must be written in C. That kind of programming is ***way*** beyond the scope of Server Fault - See the book I mentioned and the Net-SNMP wiki. – voretaq7 Aug 28 '12 at 17:15