2

I'm looking for an example implementation of a mib module with a custom callback that deals with some of the structures in Netsnmp_node_handler:

test_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)

I'd like to see an example of checking what request it is, i.e get/set/monitor request. Checking if the oid matches the one in the class, getting the oid value, etc. Currently I'm having problems doing this.

Also when I do a snmpset my module is called twice, not sure why.

shwick
  • 4,277
  • 6
  • 21
  • 28

1 Answers1

-1

You are asking for the complete implementation. Isn't that too much to ask. Just for the benefit, putting some basic code:

void init_InterfaceCountTable(void)
{
    oid my_registration_oid[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //Give complete OID of your table
    table_set = netsnmp_create_table_data_set("InterfaceCountTable");

    table_set->allow_creation = 1;
    if(FLAG != 1)
    {
        netsnmp_table_dataset_add_index(table_set, ASN_INTEGER);

        netsnmp_table_set_multi_add_default_row(table_set,
                COLUMN_INTERFACECOUNTRX, ASN_INTEGER, 1, NULL, 0,
                COLUMN_INTERFACECOUNTTX, ASN_INTEGER, 1, NULL, 0,
                0);

        int i =0;
        long int idx = 0;
        long int col2 = 0;
        long int col3 = 0;
        for (i=0; i<MAX_NUM_ROW; i++)
        {
            row[i] = netsnmp_create_table_data_row();
            idx = i;
            netsnmp_table_row_add_index(row[i], ASN_INTEGER, &idx, sizeof(idx));
            col2 = interfaceCountStruct[i].Rx;
            netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTRX,
                    ASN_INTEGER, &col2, sizeof(col2));
            //netsnmp_mark_row_column_writable(row[i], 2, 1);
            col3 = interfaceCountStruct[i].Tx;
            netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTTX,
                    ASN_INTEGER, &col3, sizeof(col3));
            //netsnmp_mark_row_column_writable(row[i], 3, 1);
            netsnmp_table_dataset_add_row(table_set, row[i]);
        }

        netsnmp_register_table_data_set(netsnmp_create_handler_registration
                ("InterfaceCountTable", netsnmp_table_array_helper_handler,
                 my_registration_oid,
                 OID_LENGTH(my_registration_oid),
                 HANDLER_CAN_RWRITE), table_set, NULL);
    }
}


netsnmp_table_array_helper_handler(netsnmp_mib_handler *handler,
                                   netsnmp_handler_registration *reginfo,
                                   netsnmp_agent_request_info *agtreq_info,
                                   netsnmp_request_info *requests)
{
    int rc = SNMP_ERR_NOERROR;
    int i =0;

    switch (agtreq_info->mode) {
        case MODE_GET:
        case MODE_GETBULK:
        case MODE_GETNEXT:
        {
            for (i=0; i<MAX_NUM_ROW; i++)
            {
                netsnmp_table_dataset_remove_and_delete_row(table_set, row[i]);
            }

            long int idx = 0;
            long int col2 = 0;
            long int col3 = 0;

            for (i=0; i<MAX_NUM_ROW; i++)
            {
                row[i] = netsnmp_create_table_data_row();
                idx = interfaceCountStruct[i].idx;
                netsnmp_table_row_add_index(row[i], ASN_INTEGER, &idx, sizeof(idx));
                col2 = interfaceCountStruct[i].Rx;
                netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTRX,
                    ASN_INTEGER, &col2, sizeof(col2));
        //netsnmp_mark_row_column_writable(row[i], 2, 1);
                col3 = interfaceCountStruct[i].Tx;
                netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTTX,
                    ASN_INTEGER, &col3, sizeof(col3));
        //netsnmp_mark_row_column_writable(row[i], 3, 1);
                netsnmp_table_dataset_add_row(table_set, row[i]);
            }

        }
        break;

        default:
            return SNMP_ERR_GENERR;
    }

    return rc;
}

Please let me know if you can make this better.

Pawan
  • 1,537
  • 1
  • 15
  • 19