registering row AgentX

"Peter Ruzicka" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hello,

(excuse my english please)
I'd like to ask for help with my problem:

I need to work with the shared tables (master-subagents). So I would like to
register table on the master agent and subagents register rows on master agent.

When "an event" is happening on the subagent, I want to insert a row into the
table. 

(I'm doing something similar as logging notifications in notification-log-mib.
But I need more and it is not sufficient to insert row on the master agent
when the trap is received via AgentX on master agent.)

I have generated table with mib2c.create-dataset.conf,v 5.4.:

static netsnmp_table_data_set *fooAlarmModuleTable;
static oid fooAlarmModuleTable_oid[] = {1,3,6,1,4,1,1234,2,1,3,1,2,1};
static size_t fooAlarmModuleTable_oid_len = OID_LENGTH(fooAlarmModuleTable_oid);
static oid fooAlarmModuleRow_oid[] = {1,3,6,1,4,1,1234,2,1,3,1,2,1,1,0,0,0};
static size_t fooAlarmModuleRow_oid_len = OID_LENGTH(fooAlarmModuleRow_oid);

void
initialize_table_fooAlarmModuleTable(void)
{

    /* create the table structure itself */
    fooAlarmModuleTable = netsnmp_create_table_data_set("fooAlarmModuleTable");

    /* comment this out or delete if you don't support creation of new rows */
    fooAlarmModuleTable->allow_creation = 1;

    /***************************************************
     * Adding indexes
     */
    DEBUGMSGTL(("initialize_table_fooAlarmModuleTable",
                "adding indexes to table fooAlarmModuleTable\n"));
    netsnmp_table_set_add_indexes(fooAlarmModuleTable,
                           ASN_INTEGER,  /* index: cfbModuleIndex */
                           ASN_INTEGER,  /* index: fooAlarmModuleIndex */
                           ASN_INTEGER,  /* index: fooAlarmModuleErrorCause */
                           0);

    DEBUGMSGTL(("initialize_table_fooAlarmModuleTable",
                "adding column types to table fooAlarmModuleTable\n"));        
    netsnmp_table_set_multi_add_default_row(fooAlarmModuleTable,
                                            COLUMN_FOOALARMMODULEINDEX,
ASN_INTEGER, 0,
                                            NULL, 0,
                                            COLUMN_FOOALARMMODULEERRORCAUSE,
ASN_INTEGER, 0,
                                            NULL, 0,
                                           
COLUMN_FOOALARMMODULEFUNCTIONALGROUP, ASN_INTEGER, 0,
                                            NULL, 0,
                                           
COLUMN_FOOALARMMODULEALARMSEVERITY, ASN_INTEGER, 0,
                                            NULL, 0,
                                            COLUMN_FOOALARMMODULEALARMCLASS,
ASN_INTEGER, 0,
                                            NULL, 0,
                                            COLUMN_FOOALARMMODULEALARMTIME,
ASN_OCTET_STR, 0,
                                            NULL, 0,
                              0);
    
    /* registering the table with the master agent */
    /* note: if you don't need a subhandler to deal with any aspects
       of the request, change fooAlarmModuleTable_handler to "NULL" */
   
netsnmp_register_table_data_set(netsnmp_create_handler_registration("fooAlarmModuleTable",
fooAlarmModuleTable_handler,
                                                        fooAlarmModuleTable_oid,
                                                       
fooAlarmModuleTable_oid_len,
                                                        HANDLER_CAN_RWRITE),
                            fooAlarmModuleTable, NULL);
}

There is the empty handler:

int
fooAlarmModuleTable_handler(
    netsnmp_mib_handler               *handler,
    netsnmp_handler_registration      *reginfo,
    netsnmp_agent_request_info        *reqinfo,
    netsnmp_request_info              *requests) {
    /* perform anything here that you need to do.  The requests have
       already been processed by the master table_dataset handler, but
       this gives you chance to act on the request in some other way
       if need be. */
    return SNMP_ERR_NOERROR;
}

Then I have created a function for adding a row with registering an oid index.

void fooAlarmModuleTable_insert_row(long moduleIndex, 
        unsigned long fooAlarmModuleIndex,
        unsigned long fooAlarmModuleErrorCause,
        unsigned long fooAlarmModuleFunctionalGroup,
        unsigned long fooAlarmModuleAlarmSeverity,
        unsigned long fooAlarmModuleAlarmClass,
        char  * fooAlarmModuleAlarmTime )
{
   netsnmp_table_row *tmprow=NULL, *oldRow = NULL;
  
    if (!fooAlarmModuleTable)
       return;

   fooAlarmModuleRow_oid[fooAlarmModuleRow_oid_len-3] = moduleIndex;
   fooAlarmModuleRow_oid[fooAlarmModuleRow_oid_len-2] = fooAlarmModuleIndex;
   fooAlarmModuleRow_oid[fooAlarmModuleRow_oid_len-1] = fooAlarmModuleErrorCause;

   register_oid_index(fooAlarmModuleRow_oid, fooAlarmModuleRow_oid_len,
fooAlarmModuleRow_oid + fooAlarmModuleTable_oid_len + 1, 3);

   tmprow = netsnmp_create_table_data_row(); 

   netsnmp_table_row_add_index(tmprow, ASN_INTEGER, (char*) &moduleIndex,
sizeof(moduleIndex));
   netsnmp_table_row_add_index(tmprow, ASN_INTEGER, (char*)
&fooAlarmModuleIndex, sizeof(fooAlarmModuleIndex));
   netsnmp_table_row_add_index(tmprow, ASN_INTEGER, (char*)
&fooAlarmModuleErrorCause, sizeof(fooAlarmModuleErrorCause));


   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEINDEX, ASN_INTEGER,
(char*) &fooAlarmModuleIndex, sizeof(unsigned long));
   netsnmp_mark_row_column_writable(tmprow, COLUMN_FOOALARMMODULEINDEX, 1);

   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEERRORCAUSE,
ASN_INTEGER, (char*) &fooAlarmModuleErrorCause, sizeof(unsigned long));
   netsnmp_mark_row_column_writable(tmprow, COLUMN_FOOALARMMODULEERRORCAUSE, 1);

   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEFUNCTIONALGROUP,
ASN_INTEGER, (char*) &fooAlarmModuleFunctionalGroup, sizeof(unsigned long));
   netsnmp_mark_row_column_writable(tmprow,
COLUMN_FOOALARMMODULEFUNCTIONALGROUP, 1);

   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEALARMSEVERITY,
ASN_INTEGER, (char*) &fooAlarmModuleAlarmSeverity, sizeof(unsigned long));
   netsnmp_mark_row_column_writable(tmprow,
COLUMN_FOOALARMMODULEALARMSEVERITY, 1);

   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEALARMCLASS,
ASN_INTEGER, (char*) &fooAlarmModuleAlarmClass, sizeof(unsigned long));
   netsnmp_mark_row_column_writable(tmprow, COLUMN_FOOALARMMODULEALARMCLASS, 1);

   netsnmp_set_row_column (tmprow, COLUMN_FOOALARMMODULEALARMTIME,
ASN_OCTET_STR, (char*) fooAlarmModuleAlarmTime, strlen(fooAlarmModuleAlarmTime) );
   netsnmp_mark_row_column_writable(tmprow, COLUMN_FOOALARMMODULEALARMTIME, 1);
   
   /* update row if exist */
   oldRow = netsnmp_table_data_get(fooAlarmModuleTable->table, tmprow->indexes);
   
   if (oldRow)
   {
      netsnmp_table_data_remove_and_delete_row(fooAlarmModuleTable->table,
oldRow);
   }

  netsnmp_table_dataset_add_row(fooAlarmModuleTable, tmprow); 
};

I don't check if it is master agent when I add oid_index yet. I just skip this
line when I am tracing master agent.

So what do I see? 
- AgentX communication works fine
- master agent adds the row correctly, when "event" happend on the master agent
- subagent seems to register an index correctly on master agent through AgentX
- subagent adds row localy (on subagent)

When GET request for the subagent row is received:
- I guess that master agent should check all registered indexes and forward
request to an appropriate subagent, but this doesn't happen. Master agent
returns "No Such Instance".
- I have seen some threads about netsnmp_register_mib_table_row() function.
But this function was moved to old_api long time ago. Should I still use this
one? And anyway it is not clear for me how it works. It seems to register a
handler? 

I am really stucked here for couple days and I can not make a step :o(. 

I would really appreciate your help guys. Any word or a line of code would
help me.

Thank you in advance!

Kind regards, 
         Peter.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
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.