3

I've been working on my own SNMP agent using the example found here : http://www.net-snmp.org/dev/agent/example_8c_source.html

I am wanting to better organize my tree structure to make more sense which in turn makes using client commands easier.

I am using the traditional old C API to achieve this and is what is used in the example link.

I have a tree I want to implement

Sample OID Tree

My MIB :

    MIB-NAME-HERE DEFINITIONS ::= BEGIN

    IMPORTS
        MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises,
        NOTIFICATION-TYPE                       FROM SNMPv2-SMI
        OBJECT-GROUP, NOTIFICATION-GROUP        FROM SNMPv2-CONF
    ;

    myProduct MODULE-IDENTITY
        LAST-UPDATED "201505200000Z"
        ORGANIZATION "www.example.com"
        CONTACT-INFO
             "email: support@example.com"
        DESCRIPTION
            "MIB Example."
        REVISION     "201505200000Z"
        DESCRIPTION
            "version 1.0"
        ::= { enterprises 54321 }

    --
    -- top level structure
    --
       IPConfig OBJECT IDENTIFIER ::= { myProduct 1 }
       Services OBJECT IDENTIFIER ::= { myProduct 3 }

    IPConfigValuesGroup OBJECT-GROUP
        OBJECTS { ObjectA,
                  ObjectB,
                  ObjectC
                }

        STATUS current
        DESCRIPTION
               "Group of all blahblah variables."

        ::= { myProduct 4 } <----**How would this affect a client request?**

    --
    -- Values
    --

    ObjectA OBJECT-TYPE
        SYNTAX      OCTET STRING (SIZE(1..4096))
        MAX-ACCESS  read-write
        STATUS      current
        DESCRIPTION
            "Test Example"
        ::= { IPConfig 1 }

    ObjectB OBJECT-TYPE
        SYNTAX      OCTET STRING (SIZE(1..4096))
        MAX-ACCESS  read-write
        STATUS      current
        DESCRIPTION
            "Test Example"
        ::= { IPConfig 2 } 

--MORE STUFF...
    .... END 

I want to be able to group relative objects together so the user could do an

snmpset -v 2c -c communityNameHere -m MIB-NAME-HERE.txt 10.20.30.40 1.3.6.1.4.1.54321.x.1.3 s "I am a string"

to access ObjectC under the IPConfig group.

Question : How do I implement subtrees into my 'subagent'?

This is an excerpt from the link shown above.
    /*
     * This array defines the OID of the top of the mib tree that we're
     *  registering underneath.
     * Note that this needs to be the correct size for the OID being 
     *  registered, so that the length of the OID can be calculated.
     *  The format given here is the simplest way to achieve this.
     */
oid             example_variables_oid[] = { 1, 3, 6, 1, 4, 1, 54321, x};

Do I have to declare another array to include, per say, the Services OID?

oid             example_variables_oid[] = { 1, 3, 6, 1, 4, 1, 54321, x, 3};

Or for each subtree do they need to have an example.c*-type* file?

Question : Would this MIB achieve what I want? What would need to be done different? I've read up on OBJECT-GROUPS, SEQUENCE, O'Reily's book as well as the RFCs. I'm still trying to grasp everything.

jtor
  • 133
  • 1
  • 4
  • 13

1 Answers1

2

There is a lot of questions here, and honestly it would take a super long post to answer them all. So, I'll answer them at a high level and then provide you a bunch of links to go read longer and more in depth articles on.

First, writing mibs is not exactly straight forward. The most referenced book on the subject is probably Understand SNMP MIBs and is quite good (I have a copy). All your mib writing questions are well answered in there, but a couple of quick points about what you have above:

1) Almost all MIB objects should start with a lower case letter (except table sequences which you're not to yet).

2) There is no 'x' in your oids above. You've created a tree structure in the definitions that derive straight to 1.3.6.1.4.1.54321.1.3, for example.

3) Just throw out the object group clause for now. It'll only confuse you at first and isn't needed. It's only there to really write a standards-definition for listing objects you must implement in order to conform to the mib (using a conformance statement). For you right now, this is not at all needed. Just kill the whole thing.

As for writing code to support the object you're trying to define, you'll need to do that in C code within the agent or subagent that you're writing. There is already a lot of documentation on the Net-SNMP project site about that, so you should really go look there. The links that will help you get started are:

Generally how to write mib code for a net-smnp based agent:

http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module

How to use the mib2c translator to produce some template code to start with:

http://www.net-snmp.org/wiki/index.php/TUT:mib2c_General_Overview

And more generically, all the coding tutorials for Net-SNMP can be found here:

http://www.net-snmp.org/wiki/index.php/Tutorials#Coding_Tutorials

And one final comment: the objects you're defining above are called "scalars". IE, there is only a single instance of them in the tree. So when you're reading the tutorials or the mib2c questions it asks you, the above are "scalars". Tables will likely come next in your project, as everyone seems to end up with tables! Good luck!

Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69
  • To explain items 1) & 2) - These were just for example purposes. The '54321' would be our organization and the 'x' would be some number (probably 1) to distinguish one product from another (if we ever decided to merge two products into 1 MIB - is that even recommended in practice?). I have an existing implementation of old API – jtor Jun 03 '15 at 12:54
  • cont - I have an existing implementation with old API code and I've be able to get/set objects and have them do the appropriate 'ACTION'. I have no problem creating objects at the level below our OID, but I want it more organized. Right now my commands to get/set specify enterprises.54321.(1,2,3,.n). I want to use enterprises.54321.1.(subgroup-OID).(1,2,3...n) with different subgroups to better organize the objects. – jtor Jun 03 '15 at 13:03
  • Then just add a new line like this: "mySubProduct OBJECT IDENTIFIER ::= { myProduct 1 }" and change "IPConfig OBJECT IDENTIFIER ::= { myProduct 1 }" to "IPConfig OBJECT IDENTIFIER ::= { mySubProduct 1 }" – Wes Hardaker Jun 08 '15 at 16:18
  • The solution I needed was to not only do that, but I needed to setup my variables2 structure correctly. The example.c provided with net-snmp had comments that confused me with the verbage from other tutorial pages. I (believe) got things taken care of for now. Thanks Wes. – jtor Jun 09 '15 at 16:56
  • http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module is broken – PHD Aug 18 '21 at 02:41