Hi,

I am writing my first code for SNMP. I am trying to extend the MIB-2
standard interface table. During this process table iterator registration
function    netsnmp_register_table_iterator(reg, iinfo)   is failing.

Here is my code:

void init_myCustomIfTable(void) {

    static oid ifTable_oid[] = {1, 3, 6, 1, 2, 1, 2, 99};  // Base OID for
custom table extension

    size_t ifTable_oid_len = OID_LENGTH(ifTable_oid);



    netsnmp_handler_registration *reg;

    netsnmp_table_registration_info *table_info;

    netsnmp_iterator_info *iinfo;



    AIM_LOG_INFO("init_myCustomIfTable \n");

    // Register the table with the SNMP agent

    reg = netsnmp_create_handler_registration("myCustomIfTable",

                                              get_custom_metric_data,
ifTable_oid,

                                              ifTable_oid_len,

                                              HANDLER_CAN_RONLY);



    // Error checking for handler registration

    if (!reg) {



        AIM_LOG_INFO("Failed to create handler registration for
myCustomIfTable \n");

        return;

    }



    // Define table structure and columns (e.g., index for ifIndex and
custom metrics)

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);

    if (!table_info) {

        AIM_LOG_INFO("Failed to allocate memory for table registration info
\n");

        return;

    }



    netsnmp_table_helper_add_index(table_info, ASN_INTEGER, 0);  // Index
for ifIndex

    table_info->min_column = COLUMN_CUSTOM_METRIC1;           // Starting
column for custom data

    table_info->max_column = COLUMN_CUSTOM_METRIC2;           // Ending
column for custom data



    // Define iterator information for table walking

    iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);

    if (!iinfo) {

        AIM_LOG_INFO("Failed to allocate memory for iterator info \n");

        free(table_info);  // Free memory before returning

        return;

    }

iinfo->get_first_data_point = get_first_data_point;

    iinfo->get_next_data_point = get_next_data_point;

    iinfo->table_reginfo = table_info;



    // Register the table iterator handler

    if (!netsnmp_register_table_iterator(reg, iinfo)) {

        AIM_LOG_INFO("Failed to register table iterator handler for
myCustomIfTable \n");

        free(iinfo);  // Clean up allocated memory

        free(table_info);  // Clean up allocated memory

        return;

    }

I am attaching my MIB file also.

Any help in this regard would be highly appreciated.

Thanks & Regards,
Bhashkar
MY-INTERFACE-MIB DEFINITIONS ::= BEGIN

IMPORTS
    MODULE-IDENTITY, OBJECT-TYPE, Integer32, Gauge32
        FROM SNMPv2-SMI
    TEXTUAL-CONVENTION
        FROM SNMPv2-TC
    ifIndex, interfaces
        FROM RFC1213-MIB;

myIfExtensions MODULE-IDENTITY
    LAST-UPDATED "202411070000Z"
    ORGANIZATION "Your Organization"
    CONTACT-INFO "Contact information here"
    DESCRIPTION "An extension to the standard MIB-2 ifTable with additional 
columns."
    ::= { interfaces 99 }

-- Define the table that extends ifTable
myCustomIfTable OBJECT-TYPE
    SYNTAX      SEQUENCE OF MyCustomIfEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Table containing additional interface information."
    ::= { myIfExtensions 1 }

myCustomIfEntry OBJECT-TYPE
    SYNTAX      MyCustomIfEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "An entry containing additional interface information."
    INDEX       { ifIndex }  -- Use ifIndex as the index for this table
    ::= { myCustomIfTable 1 }

MyCustomIfEntry ::= SEQUENCE {
    customMetric1  Integer32,
    customMetric2  Gauge32
}

-- Define the new columns in the table
customMetric1 OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "A custom metric specific to this interface."
    ::= { myCustomIfEntry 1 }

customMetric2 OBJECT-TYPE
    SYNTAX      Gauge32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Another custom metric for the interface."
    ::= { myCustomIfEntry 2 }

END
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to