Re: How to run the snmpd in debug mode

purushotam rao <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
R/ Sir,

Thankyou for your reply. Now I am able to run net-snmp in debug mode.

I have installed net-snmp ver 5.5. I have configured with the attached
testmodule.c and testmodule .h mib. This mib is having two parameters. First
Parameter is integer and second parameter is string. When I query for second
parametr I am getting the error messag. The query responce is as follows

Query1.  snmpget -v2c -c public localhost .1.3.6.1.4.1.10496.1.1.10
Response     12254

Query2.  snmpget -v2c -c public localhost .1.3.6.1.4.1.10496.1.1.2.0
Responce    enterprices.10496.1.1.2.0 = No such instance currently exists at
this OID.

Can you please guide me where I am wrong.


 Regards,

U.Purushotham Rao,
.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
testmodule.c (text/x-csrc, 6.1 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.old-api.conf 14476 2006-04-18 17:36:51Z hardaker $
 */

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

/* 
 * testmodule_variables_oid:
 *   this is the top level oid that we want to register under.  This
 *   is essentially a prefix, with the suffix appearing in the
 *   variable below.
 */

oid testmodule_variables_oid[] = { 1,3,6,1,4,1,10496,1 };

/* 
 * variable4 testmodule_variables:
 *   this variable defines function callbacks and type return information 
 *   for the testmodule mib section 
 */
char ch[]="AMRUTHASRI-DIVYASRI";
struct variable7 testmodule_variables[] = {
/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
#define INTLEAF		1
{INTLEAF,  ASN_INTEGER,  RWRITE,  var_testmodule, 2,  { 1,1 }},
#define STRLEAF		2
{STRLEAF,  ASN_OCTET_STR,  RWRITE,  var_testmodule, 2,  { 1,2 }},

};
/*    (L = length of the oidsuffix) */


/** Initializes the testmodule module */
void
init_testmodule(void)
{

    DEBUGMSGTL(("UPSR", "Initializing testmodule\n"));

    /* register ourselves with the agent to handle our mib tree */
    REGISTER_MIB("testmodule", testmodule_variables, variable4,
               testmodule_variables_oid);

    /* place any other initialization junk you need here */
}

/*
 * var_testmodule():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_testmodule(struct variable *vp, 
                oid     *name, 
                size_t  *length, 
                int     exact, 
                size_t  *var_len, 
                WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static u_long ulong_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;

    if (header_generic(vp,name,length,exact,var_len,write_method)
                                  == MATCH_FAILED )
    return NULL;

    /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
    case INTLEAF:
         long_ret=12254;
        *write_method = write_intleaf;
	DEBUGMSGTL(("UPSR","Expected Value of integer is 12254\n"));
        return (u_char*) &long_ret;
    case STRLEAF:
         strcpy(string,ch);
	 *var_len=strlen(ch);
        *write_method = write_strleaf;
        return (u_char*)ch;
    default:
      ERROR_MSG("\nUPSR: Error in Query\n");
    }
    return NULL;
}





int
write_intleaf(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    long value;
    int size;

    switch ( action ) {
        case RESERVE1:
          if (var_val_type != ASN_INTEGER) {
              fprintf(stderr, "write to testmodule not ASN_INTEGER\n");
              return SNMP_ERR_WRONGTYPE;
          }
          if (var_val_len > sizeof(long)) {
              fprintf(stderr,"write to testmodule: bad length\n");
              return SNMP_ERR_WRONGLENGTH;
          }
          break;

        case RESERVE2:
          size  = var_val_len;
          value = * (long *) var_val;

          break;

        case FREE:
             /* Release any resources that have been allocated */
          break;

        case ACTION:
             /*
              * The variable has been stored in 'value' for you to use,
              * and you have just been asked to do something with it.
              * Note that anything done here must be reversable in the UNDO case
              */
          break;

        case UNDO:
             /* Back out any changes made in the ACTION case */
          break;

        case COMMIT:
             /*
              * Things are working well, so it's now safe to make the change
              * permanently.  Make sure that anything done here can't fail!
              */
          break;
    }
    return SNMP_ERR_NOERROR;
}


int
write_strleaf(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    char value;
    int size;

    switch ( action ) {
        case RESERVE1:
          if (var_val_type != ASN_OCTET_STR) {
              fprintf(stderr, "write to testmodule not ASN_OCTET_STR\n");
              return SNMP_ERR_WRONGTYPE;
          }
          if (var_val_len > sizeof(char)) {
              fprintf(stderr,"write to testmodule: bad length\n");
              return SNMP_ERR_WRONGLENGTH;
          }
          break;

        case RESERVE2:
          size  = var_val_len;
          value = * (char *) var_val;

          break;

        case FREE:
             /* Release any resources that have been allocated */
          break;

        case ACTION:
             /*
              * The variable has been stored in 'value' for you to use,
              * and you have just been asked to do something with it.
              * Note that anything done here must be reversable in the UNDO case
              */
          break;

        case UNDO:
             /* Back out any changes made in the ACTION case */
          break;

        case COMMIT:
             /*
              * Things are working well, so it's now safe to make the change
              * permanently.  Make sure that anything done here can't fail!
              */
          break;
    }
    return SNMP_ERR_NOERROR;
}
testmodule.h (application/octet-stream, 368 B)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.old-api.conf 14476 2006-04-18 17:36:51Z hardaker $
 */
#ifndef TESTMODULE_H
#define TESTMODULE_H

/* function declarations */
void init_testmodule(void);
FindVarMethod var_testmodule;
    WriteMethod write_intleaf;
    WriteMethod write_strleaf;

#endif /* TESTMODULE_H */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.