Hi,
I am trying to write an sample using table_tdata.  using cache , I  am unable 
to load xxx_load() function. So I am not able to get any data using snmpcmd.
I did not do much other than implementing the _load and _free() hooks.

What's  the wrong I am doing ?

I do not have anything to initialize in initialize_table_xxx() 


attaching the file here.
Thanks
/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.table_data.conf 19302 2010-08-13 12:19:42Z dts12 $
 */

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

/** Initializes the abctable_cache module */
void
init_abc(void)
{
  /* here we initialize all the tables we're planning on supporting */
    initialize_table_messageTable();
}


/** Initialize the messageTable table by defining its contents and how it's 
structured */
void
initialize_table_messageTable(void)
{
    const oid messageTable_oid[] = {1,3,6,1,4,1,11457,3,3};
    const size_t messageTable_oid_len   = OID_LENGTH(messageTable_oid);
    netsnmp_handler_registration    *reg;
    netsnmp_tdata                   *table_data;
    netsnmp_table_registration_info *table_info;
    netsnmp_cache                   *cache;

    snmp_log(LOG_INFO,"initializing .\n\n");

    reg = netsnmp_create_handler_registration(
              "messageTable",     messageTable_handler,
              messageTable_oid, messageTable_oid_len,
              HANDLER_CAN_RWRITE
              );

    table_data = netsnmp_tdata_create_table( "messageTable", 0 );
    if (NULL == table_data) {
        snmp_log(LOG_ERR,"error creating tdata table for messageTable\n");
        return;
    }
    snmp_log(LOG_INFO,"_tdata_create .\n\n");
    cache = netsnmp_cache_create(MESSAGETABLE_TIMEOUT,
                                  messageTable_load, messageTable_free,
                                  messageTable_oid, messageTable_oid_len);
    if (NULL == cache) {
        snmp_log(LOG_ERR,"error creating cache for messageTable\n");
    }
    else
        cache->magic = (void *)table_data;
    table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
    if (NULL == table_info) {
        snmp_log(LOG_ERR,"error creating table info for messageTable\n");
        return;
    }
    netsnmp_table_helper_add_indexes(table_info,
                           ASN_INTEGER,  /* index: messageIndex */
                           0);

    table_info->min_column = COLUMN_MESSAGETYPE;
    table_info->max_column = COLUMN_CURRENTMSGID;
    
    netsnmp_tdata_register( reg, table_data, table_info );
    snmp_log(LOG_INFO,"netsnmp_tdata_register .\n\n");
    if (cache) 
        netsnmp_inject_handler_before( reg, netsnmp_cache_handler_get(cache),
                                       TABLE_TDATA_NAME);

    /* Initialise the contents of the table here */
}

    /* Typical data structure for a row entry */
struct messageTable_entry {
    /* Index values */
    long messageIndex;

    /* Column values */
    char messageType[10];
    long sentMsgCount;
    long errorMsgCount;
    long currentMsgID;

};

/* Example cache handling - set up table_data list from a suitable file */
int
messageTable_load( netsnmp_cache *cache, void *vmagic ) {
    netsnmp_tdata     *table = (netsnmp_tdata *)vmagic;
    netsnmp_tdata_row *row;
    struct messageTable_entry *this;
    FILE *fp;
    char buf[256];

    char type[10];
    int index = 0;
    int msg_id, msg_sent, msg_err = 0;
    memset(type,0x00,10);
    fp = fopen( "data.txt", "r" );
    snmp_log(LOG_INFO,"loading the data.\n\n");

    if ( !fp ) {
        return -1;
    }
    while ( fgets( buf, 256, fp )) {

        this = SNMP_MALLOC_TYPEDEF( struct messageTable_entry );
        /* Unpick 'buf' and populate 'this' */
        this->messageIndex = index++;
 
            sprintf(type, "%s", strtok(buf, ","));
        strcpy(this->messageType, type);
        
        msg_id = atoi(strtok(NULL, ","));
        this->currentMsgID = msg_id;

        msg_sent = atoi(strtok(NULL, ","));
        this->sentMsgCount = msg_sent;
        
        msg_err = atoi(strtok(NULL, ","));
        this->errorMsgCount = msg_err;

        // insert this in to row->data
        row = netsnmp_tdata_create_row();
        row->data = this;
        netsnmp_tdata_row_add_index( row, ASN_INTEGER,
                                 &(this->messageIndex),
                                 sizeof(this->messageIndex));
        if (table)
            netsnmp_tdata_add_row( table, row );
    }
    fclose(fp);
    return 0;  /* OK */
}

void
messageTable_free( netsnmp_cache *cache, void *vmagic ) {
    netsnmp_tdata     *table = (netsnmp_tdata *)vmagic;
    netsnmp_tdata_row *this;
    struct messageTable_entry *entry;

    while ((this = netsnmp_tdata_row_first(table))) {
        entry = (struct messageTable_entry *)this->data;
        SNMP_FREE( entry );
        netsnmp_tdata_remove_and_delete_row(table, this);
    }
}

/** handles requests for the messageTable table */
int
messageTable_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 messageTable_entry          *table_entry;

    DEBUGMSGTL(("abctable_cache:handler", "Processing request (%d)\n", 
reqinfo->mode));

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request=requests; request; request=request->next) {
            table_entry = (struct messageTable_entry *)
                              netsnmp_tdata_extract_entry(request);
            table_info  =     netsnmp_extract_table_info( request);
    
            switch (table_info->colnum) {
            case COLUMN_MESSAGETYPE:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                          table_entry->messageType,
                                          strlen(table_entry->messageType));
                break;
            case COLUMN_SENTMSGCOUNT:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->sentMsgCount);
                break;
            case COLUMN_ERRORMSGCOUNT:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->errorMsgCount);
                break;
            case COLUMN_CURRENTMSGID:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->currentMsgID);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
------------------------------------------------------------------------------
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-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to