Raw-table doesn't work.

"Naama Bar Menachem" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi,

 

The code below implements a simple rax-table.

Although the initialize function succeeds the handler isn't called when
we send a get or getnext request

The get request is returning with the error
"NOVELSAT-DEMODULATOR-MIB::nsDemodEventsUtcSecondsHigh.1 = No Such
Object available on this agent at this OID"

 

    /*

     * Typical data structure for a row entry 

     */

struct nsDemodEventsTable_entry {

    /*

     * Index values 

     */

    long            nsDemodEventsUtcSecondsHigh;

    long            nsDemodEventsUtcSecondsLow;

    long            nsDemodEventsUtcNanoSecondsHigh;

    long            nsDemodEventsUtcNanoSecondsLow;

 

    /*

     * Column values 

     */

    long            nsDemodEventsSeverity;

    char
nsDemodEventsSource[COLUMN_NSDEMODEVENTSSOURCE_MAX_LEN];

    size_t          nsDemodEventsSource_len;

    char
nsDemodEventsEvent[COLUMN_NSDEMODEVENTSEVENT_MAX_LEN];

    size_t          nsDemodEventsEvent_len;

    char
nsDemodEventsDescription[COLUMN_NSDEMODEVENTSDESCRIPTION_MAX_LEN];

    size_t          nsDemodEventsDescription_len;

 

    int             valid;

};

 

struct nsDemodEventsTable_entry EventsTable_entry;

 

/*

* create a new row in the table 

 */

static struct nsDemodEventsTable_entry *

nsDemodEventsTable_createEntry(int dummy, long
nsDemodEventsUtcSecondsHigh,

                               long nsDemodEventsUtcSecondsLow,

                               long nsDemodEventsUtcNanoSecondsHigh,

                               long nsDemodEventsUtcNanoSecondsLow)

{

    struct nsDemodEventsTable_entry *entry;

 

    entry = SNMP_MALLOC_TYPEDEF(struct nsDemodEventsTable_entry);

    if (!entry)

        return NULL;

    return entry;

}

 

/*

* remove a row from the table 

 */

static void

nsDemodEventsTable_removeEntry(struct nsDemodEventsTable_entry *entry)

{

    if (!entry)

        return;                 /* Nothing to remove */

    if (entry)

        SNMP_FREE(entry);       /* XXX - release any other internal
resources */

}

 

 

/** determine the appropriate row for an exact request */

static struct nsDemodEventsTable_entry *

nsDemodEventsTable_get_entry(netsnmp_variable_list * indexes)

{

    struct nsDemodEventsTable_entry *row = NULL;

    netsnmp_variable_list *idx = indexes;

    long        tmp;

    ns_event    *event;

 

    /*

     * XXX - Use the 'indexes' parameter to retrieve the data

     * structure for the requested row, and return this.

     */

    event = (ns_event *) ns_ipcc_mem_alloc(sizeof(ns_event));

 

    if (!event){

        return NULL;

    }

 

    tmp = *(idx->val.integer) < 32;

    idx = idx->next_variable;

    tmp |= *(idx->val.integer);

    event->utc.tv_sec = tmp;

    idx = idx->next_variable;

    tmp = *(idx->val.integer) < 32;

    idx = idx->next_variable;

    tmp |= *(idx->val.integer);

    event->utc.tv_nsec = tmp;

 

    if (ns_events_get_event(event)){

        EventsTable_entry.nsDemodEventsSeverity = event->severity;

 
strncpy(EventsTable_entry.nsDemodEventsSource,event->source,COLUMN_NSDEM
ODEVENTSSOURCE_MAX_LEN);

        EventsTable_entry.nsDemodEventsSource_len =
strlen(EventsTable_entry.nsDemodEventsSource);

 
strncpy(EventsTable_entry.nsDemodEventsEvent,event->event,COLUMN_NSDEMOD
EVENTSEVENT_MAX_LEN);

        EventsTable_entry.nsDemodEventsEvent_len =
strlen(EventsTable_entry.nsDemodEventsSource);

 
strncpy(EventsTable_entry.nsDemodEventsDescription,event->description,CO
LUMN_NSDEMODEVENTSDESCRIPTION_MAX_LEN);

        EventsTable_entry.nsDemodEventsDescription_len =
strlen(EventsTable_entry.nsDemodEventsSource);

        row = &EventsTable_entry;

    }

 

   ns_ipcc_mem_free();

 

    return row;

}

 

/** determine the appropriate row for an fuzzy request */

static struct nsDemodEventsTable_entry *

nsDemodEventsTable_get_next_entry(netsnmp_handler_registration *reginfo,

                                  netsnmp_request_info *request,

                                  int column,

                                  netsnmp_variable_list * indexes)

{

    struct nsDemodEventsTable_entry *row = NULL;

    oid             build_space[MAX_OID_LEN];

    size_t          build_space_len = 0;

    size_t          index_oid_len = 0;

    netsnmp_variable_list *idx = indexes;

    long        tmp;

    ns_event    *event;

 

    /*

     * XXX - Use the 'indexes' parameter to identify the

     * next row in the table.... 

     */

    event = (ns_event *) ns_ipcc_mem_alloc(sizeof(ns_event));

 

    if (!event){

        return NULL;

    }

 

    tmp = *(idx->val.integer) < 32;

    idx = idx->next_variable;

    tmp |= *(idx->val.integer);

    event->utc.tv_sec = tmp;

    idx = idx->next_variable;

    tmp = *(idx->val.integer) < 32;

    idx = idx->next_variable;

    tmp |= *(idx->val.integer);

    event->utc.tv_nsec = tmp;

 

    if (ns_events_get_next_event(event)){

        EventsTable_entry.nsDemodEventsSeverity = event->severity;

 
strncpy(EventsTable_entry.nsDemodEventsSource,event->source,COLUMN_NSDEM
ODEVENTSSOURCE_MAX_LEN);

        EventsTable_entry.nsDemodEventsSource_len =
strlen(EventsTable_entry.nsDemodEventsSource);

 
strncpy(EventsTable_entry.nsDemodEventsEvent,event->event,COLUMN_NSDEMOD
EVENTSEVENT_MAX_LEN);

        EventsTable_entry.nsDemodEventsEvent_len =
strlen(EventsTable_entry.nsDemodEventsSource);

 
strncpy(EventsTable_entry.nsDemodEventsDescription,event->description,CO
LUMN_NSDEMODEVENTSDESCRIPTION_MAX_LEN);

        EventsTable_entry.nsDemodEventsDescription_len =
strlen(EventsTable_entry.nsDemodEventsSource);

        row = &EventsTable_entry;

    }

 

    ns_ipcc_mem_free();

 

    /*

     * XXX   .... update the 'indexes' parameter with the

     * appropriate index values ... 

     */

    idx = indexes;

    *(idx->val.integer) = (event->utc.tv_sec) > 32;

    idx = idx->next_variable;

    *(idx->val.integer) = (event->utc.tv_sec) && 0xFFFFFFFF;

    idx = idx->next_variable;

    *(idx->val.integer) = (event->utc.tv_nsec) > 32;

    idx = idx->next_variable;

    *(idx->val.integer) = (event->utc.tv_nsec) && 0xFFFFFFFF;

 

    /*

     * ... and update the requested OID to match this instance 

     */

    memcpy(build_space, reginfo->rootoid,       /* registered oid */

           reginfo->rootoid_len * sizeof(oid));

    build_space_len = reginfo->rootoid_len;

    build_space[build_space_len++] = 1; /* entry */

    build_space[build_space_len++] = column;    /* column */

    build_oid_noalloc(build_space + build_space_len,

                      MAX_OID_LEN - build_space_len, &index_oid_len,

                      NULL, 0, indexes);

    snmp_set_var_objid(request->requestvb, build_space,

                       build_space_len + index_oid_len);

 

    /*

     * Finally, return the data structure for this row 

     */

    return row;

}

 

 

/** handles requests for the nsDemodEventsTable table */

static int

nsDemodEventsTable_handler(netsnmp_mib_handler *handler,

                           netsnmp_handler_registration *reginfo,

                           netsnmp_agent_request_info *reqinfo,

                           netsnmp_request_info *requests)

{

 

    netsnmp_request_info *request;

    netsnmp_table_request_info *table_info;

    struct nsDemodEventsTable_entry *table_entry;

 

    switch (reqinfo->mode) {

        /*

         * Read-support

         */

    case MODE_GET:

        for (request = requests; request; request = request->next) {

            table_info = netsnmp_extract_table_info(request);

            table_entry =

                nsDemodEventsTable_get_entry(table_info->indexes);

 

            switch (table_info->colnum) {

            case COLUMN_NSDEMODEVENTSSEVERITY:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_integer(request->requestvb,
ASN_INTEGER,

                                           table_entry->

                                           nsDemodEventsSeverity);

                break;

            case COLUMN_NSDEMODEVENTSSOURCE:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

 
table_entry->nsDemodEventsSource,

                                         table_entry->

                                         nsDemodEventsSource_len);

                break;

            case COLUMN_NSDEMODEVENTSEVENT:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

 
table_entry->nsDemodEventsEvent,

                                         table_entry->

                                         nsDemodEventsEvent_len);

                break;

            case COLUMN_NSDEMODEVENTSDESCRIPTION:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

                                         table_entry->

                                         nsDemodEventsDescription,

                                         table_entry->

                                         nsDemodEventsDescription_len);

                break;

            default:

                netsnmp_set_request_error(reqinfo, request,

                                          SNMP_NOSUCHOBJECT);

                break;

            }

        }

        break;

 

    case MODE_GETNEXT:

        for (request = requests; request; request = request->next) {

            table_info = netsnmp_extract_table_info(request);

            table_entry =

                nsDemodEventsTable_get_next_entry(reginfo, request,

                                                  table_info->colnum,

                                                  table_info->indexes);

 

            switch (table_info->colnum) {

            case COLUMN_NSDEMODEVENTSSEVERITY:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_integer(request->requestvb,
ASN_INTEGER,

                                           table_entry->

                                           nsDemodEventsSeverity);

                break;

            case COLUMN_NSDEMODEVENTSSOURCE:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

 
table_entry->nsDemodEventsSource,

                                         table_entry->

                                         nsDemodEventsSource_len);

                break;

            case COLUMN_NSDEMODEVENTSEVENT:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

 
table_entry->nsDemodEventsEvent,

                                         table_entry->

                                         nsDemodEventsEvent_len);

                break;

            case COLUMN_NSDEMODEVENTSDESCRIPTION:

                if (!table_entry) {

                    netsnmp_set_request_error(reqinfo, request,

                                              SNMP_NOSUCHINSTANCE);

                    continue;

                }

                snmp_set_var_typed_value(request->requestvb,
ASN_OCTET_STR,

                                         table_entry->

                                         nsDemodEventsDescription,

                                         table_entry->

                                         nsDemodEventsDescription_len);

                break;

            default:

                netsnmp_set_request_error(reqinfo, request,

                                          SNMP_NOSUCHOBJECT);

                break;

            }

        }

        break;

 

    }

    return SNMP_ERR_NOERROR;

}

 

/** Initialize the nsDemodEventsTable table by defining its contents and
how it's structured */

static void

initialize_table_nsDemodEventsTable(void)

{

    const oid       nsDemodEventsTable_oid[] =

        { 1, 3, 6, 1, 4, 1, 4466, 1, 2, 1, 3, 2, 1 };

    netsnmp_handler_registration *reg;

    netsnmp_table_registration_info *table_info;

 

    reg =

        netsnmp_create_handler_registration("nsDemodEventsTable",

                                            nsDemodEventsTable_handler,

                                            nsDemodEventsTable_oid,

                                            OID_LENGTH

                                            (nsDemodEventsTable_oid),

                                            HANDLER_CAN_RONLY);

 

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);

    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /*
index: nsDemodEventsUtcSecondsHigh */

                                     ASN_INTEGER,       /* index:
nsDemodEventsUtcSecondsLow */

                                     ASN_INTEGER,       /* index:
nsDemodEventsUtcNanoSecondsHigh */

                                     ASN_INTEGER,       /* index:
nsDemodEventsUtcNanoSecondsLow */

                                     0);

 

    table_info->min_column = COLUMN_NSDEMODEVENTSSEVERITY;

    table_info->max_column = COLUMN_NSDEMODEVENTSDESCRIPTION;

 

    netsnmp_register_table(reg, table_info);

 

    /*

     * Initialise the contents of the table here 

     */

}

 

/** Initializes the nsDemodEventsTable module */

void

init_nsDemodEventsTable(void)

{

    /*

     * here we initialize all the tables we're planning on supporting 

     */

    initialize_table_nsDemodEventsTable();

}

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar

_______________________________________________
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
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.