Hi All,

Thanks sir for such detail answer, i tried to followed your instructions, so
i decided to make it simple, mean i started some exercise to understand
template code.  I changed my earlier MIB and made it simpler for me , First
of all i am trying to define a string object in MIB file for READ only.

my MIB file for this purpose is. and i hve object teststr, just want to
apply GET request on agent.
--------------------------------------------------------------
MIB name is TEST-MIB.txt

TEST-ENTERPRISE-MIB DEFINITIONS ::= BEGIN
IMPORTS
    enterprises
        FROM RFC1155-SMI
    MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE,
    TimeTicks, Counter32, snmpModules, mib-2
        FROM SNMPv2-SMI
    DisplayString, TestAndIncr, TimeStamp

        FROM SNMPv2-TC
    MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP
        FROM SNMPv2-CONF;

--                    iso(1).org(3).dod(6).internet(1)
--                                 |
--                              private(4)
--                                 |
--                              enterprises(1)
--                                 |
--                              test(100)
--                                 |
--                 ._______________.________________.
--                 |                                |
--              system(1)
--
--

test               OBJECT IDENTIFIER ::= { enterprises 100 }

testsystem         OBJECT IDENTIFIER ::= { test 1 }

teststr      OBJECT-TYPE
    SYNTAX      DisplayString (SIZE (0..255))
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION
            "An administratively-assigned name for this managed
            node.  By convention, this is the node's fully-qualified
            domain name.  If the name is unknown, the value is
            the zero-length string."
    ::= { testsystem 1 }
END
---------------------


then i run command "mib2c -c mib2c.scalar.conf teststr" in terminal and got
teststr.c and teststr.h files that i move to agent/mibgroups/teststr
directory.

i put following code in my teststr.c file.
----------------------------------------------------------

/*
 * Note: this file originally auto-generated by mib2c using
 *        $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "teststr.h"

/** Initializes the teststr module */
void
init_teststr(void)
{
    const oid teststr_oid[] = { 1,3,6,1,4,1,100,1,1 };

  DEBUGMSGTL(("teststr", "Initializing\n"));

    netsnmp_register_scalar(
        netsnmp_create_handler_registration("teststr", handle_teststr,
                               teststr_oid, OID_LENGTH(teststr_oid),
                               HANDLER_CAN_RONLY
        ));
}

int
handle_teststr(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */

*char *ptr = "test";*

    switch(reqinfo->mode) {

       case MODE_GET:
     *  snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR,ptr,strlen(ptr));*
*            break;*


        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_teststr\n",
reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
------------------------------------------------------------------------------------------------
then i recompiled the source of net-snmp with mib modules
command.  ./configure --with-mib-modules="teststr/teststr"

then I run make and make install commands  and successfully compiled the
code.

--------------------------------------------
i performed following snmptranslate steps and got responses.

snmptranslate -IR TEST-MIB::teststr
MIB search path: /root/.snmp/mibs:/usr/local/share/snmp/mibs
Cannot find module (TEST-MIB): At line 0 in (none)
Unknown object identifier: TEST-MIB::teststr

but when i run  "snmptranslate 1.3.6.1.4.1.100.1.1" i got following response

TEST-ENTERPRISE-MIB::teststr.
-------------------

snmptranslate -On TEST-ENTERPRISE-MIB::teststr
.1.3.6.1.4.1.100.1.1

----------------------------
snmptranslate -Of TEST-ENTERPRISE-MIB::teststr
.iso.org.dod.internet.private.enterprises.test.testsystem.teststr

---------------------------------------------------------------
snmptranslate -IR teststr
TEST-ENTERPRISE-MIB::teststr
-----------------------------------------

now i run snmpget command to get the value of teststr object but i got
following response

command :  snmpget -v 1 -c public localhost teststr

Error
-------------
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: TEST-ENTERPRISE-MIB::teststr
-----------------------

Can some one guide me where i am wrong? Is there issue in my lines of code
or i made some mistake in MIB file.



Regards



On Thu, Aug 25, 2011 at 2:26 PM, Dave Shield <d.t.shi...@liverpool.ac.uk>wrote:

> On 25 August 2011 09:53, devel tech <devel.te...@gmail.com> wrote:
> > i compiled [my MIB] using mib2c command  and it generated two files .c
> and h of
> > object Namesys.
> >
> > mib2c -c mib2c.scalar.conf Namesys
>
>
> > it was okay, then i run make command and i got following errors
> >
> > --------------------
> > test/Namesys.c: In function 'handle_Namesys':
> > test/Namesys.c:43: error: expected expression before ',' token
> > test/Namesys.c:63: error: expected expression before ')' token
> > test/Namesys.c:76: error: expected expression before ')' token
> > test/Namesys.c:83: error: expected expression before ')' token
> > test/Namesys.c:91: error: expected expression before ')' token
>
> It looks as if you haven't finished writing the code in the MIB template.
> Remember that the output of mib2c is the *starting* point for
> a MIB implementation.   It's not finished code.
>
> From the FAQ entry
>    Why doesn't my new MIB module report anything?
>
>  Remember that 'mib2c' simply generates template code for your MIB module.
>  It's up to you to fill in the details, to report the actual information
> from
>  whatever underlying subsystem is being monitored.   Mib2c cannot help with
>  the semantics of the MIB module - it's purely there to provide an initial
>  code framework, based on the _syntax_ of the MIB module objects.
>
>
>
> Note that word "template".
>
>
>
>
> > I tried to fix above error but i could not. below i pasted mentioned
> lines
> > of errror.
> >
> > line 43 of Namesys.c is  switch(reqinfo->mode) {
> >
> >         case MODE_GET:
> >             snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
> >                                      /* XXX: a pointer to the scalar's
> data */,
> >                                      /* XXX: the length of the data in
> bytes */);
> >             break;
>
>
> You have two comments there, indicating the places where you need to
> provide suitable code.   You need to declare a variable that contains the
> value to be reported, and this goes into the first gap.
>   The size of this value  (typically using 'strlen' for a printable string,
> or 'sizeof' for a fixed buffer binary string) is provided as the final
> parameter.
>
> Just as the comments tell you.
>
>
>
> > lines no. 63..-65
> >  case MODE_SET_RESERVE2:
> >             /* XXX malloc "undo" storage buffer */
> >             if (/* XXX if malloc, or whatever, failed: */) {
> >                 netsnmp_set_request_error(reqinfo, requests,
> > SNMP_ERR_RESOURCEUNAVAILABLE);
> >             }
>
> Again, this block is asking you to provide whatever code
> is necessary to store a temporary copy of the new (or old) value,
> so that the assignment can be reversed if necessary.
>
>
> I will repeat my advice that I *strongly* suggest you spend
> some time getting used to how the agent works before you
> try to develop your own MIB.
>   Both in terms of simply using the agent, to see how it behaves.
> And also looking at the existing MIB code, to see how that works.
>
> There are plenty of examples of scalar objects in the standard tree.
> Please look at those, and try to understand how they have been
> implemented.   That will stand you in good stead when you
> finally come to write your own MIB code.
>
> Dave
>
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to