Thanks for your fast answer. I attach all source files and the whole MIB-file. Please only compile the files indusol.c, network_data.c and module_param.c at the moment. The full implemented module needs all file objects.
How it is possible to reference to other table indexes and the specific OID? You see my implementation within the sources, but i think this is not the regular way to get the index in this way. Maybe this could be the possible error. Norman -------- Original-Nachricht -------- > Datum: Sat, 19 Mar 2011 09:59:08 +0000 > Von: Dave Shield <d.t.shi...@liverpool.ac.uk> > An: normanrae...@gmx.de > CC: net-snmp-users@lists.sourceforge.net > Betreff: Re: multiple snmpget on tables > On 18 March 2011 15:39, <normanrae...@gmx.de> wrote: > > I update to NET-SNMP version 5.6.1 but i get the same behavior. > > OK - so it's probably related to the module code, > rather than the agent framework. That's not really > a great surprise. > > > I use the generated code from with mib2c tool and i use > > the table handler with specific 'iteration hook' routines > > generated by mib2c -c mib2c.iterate.conf. I also implemented > > the same table with a row-data storage table handler and > > i get the same behavior. > > The next step is probably for one of us to see if we can > reproduce the problem. Can you please post the full code > files for either/both of these implementations. > > > > > I hope this helps for further discussion. I coud give you also > > the part of the MIB - file and the associated code. > > It might be useful to have the MIB as well - yes. > But please post the *WHOLE* of the MIB file and the code > file(s). We'd need a properly formed MIB in order to make > use of it, and it's important that we can be sure that we're > using exactly the same code as you are. > > Dave -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
INDUSOL-MODULAR-INSPEKTOR-MIB DEFINITIONS ::= BEGIN -- A Comment! -- IMPORTS: Include definitions from other mibs here, which is always -- the first item in a MIB file. IMPORTS enterprises, MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, Counter32, Gauge32, Integer32 FROM SNMPv2-SMI MODULE-COMPLIANCE, OBJECT-GROUP FROM SNMPv2-CONF; -- -- A brief description and update information about this mib. -- indusol MODULE-IDENTITY DESCRIPTION "" ::= { enterprises 26958 } inspektor MODULE-IDENTITY DESCRIPTION "" ::= { indusol 25 } -- ============================================================================ -- inspector specific management objects from indusol -- ============================================================================ systemGroup OBJECT IDENTIFIER ::= { inspektor 1 } moduleInfoGroup OBJECT IDENTIFIER ::= { inspektor 3 } channelTypeDataGroup OBJECT IDENTIFIER ::= { moduleInfoGroup 5 } -- ============================================================================ -- here input all the entries of system informations from the isNetLite product -- ============================================================================ sysInfo OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "A descriptive string displays the firmware information from the main module." ::= { systemGroup 1 } -- ============================================================================ -- here input all the entries of module informations from the isNetLite product -- ============================================================================ moduleCount OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "The count of all plugged modules on the isNetLine product." ::= { moduleInfoGroup 1 } -- ================== -- moduleEntryIDTable -- ================== moduleEntryIDTable OBJECT-TYPE SYNTAX SEQUENCE OF ModuleEntryIDEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A table of module id's. The number of entries is given by the value of moduleCount." ::= { moduleInfoGroup 2 } -- moduleIDEntry (row) within the table moduleEntryIDEntry OBJECT-TYPE SYNTAX ModuleEntryIDEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "Entry containing information about one module in a slot of the chassis." INDEX { moduleEntryIDIndex } ::= { moduleEntryIDTable 1 } -- moduleEntryID within the table ModuleEntryIDEntry ::= SEQUENCE { moduleEntryIDIndex INTEGER, moduleEntryID INTEGER } moduleEntryIDIndex OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS not-accessible STATUS current DESCRIPTION "A unique table index" ::= { moduleEntryIDEntry 1 } moduleEntryID OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "A unique value for each module. e.g. 0x8101" ::= { moduleEntryIDEntry 2 } -- ================ -- moduleParamTable -- ================ moduleParamTable OBJECT-TYPE SYNTAX SEQUENCE OF ModuleParamEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "The count of all plugged modules on the isNetLine product." ::= { moduleInfoGroup 3 } -- moduleParamEntry (row) within the table moduleParamEntry OBJECT-TYPE SYNTAX ModuleParamEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A unique value for each module." INDEX { moduleEntryID } ::= { moduleParamTable 1 } -- moduleParamEntry within the table ModuleParamEntry ::= SEQUENCE { sysModInfo DisplayString, modIndex INTEGER, modDescr DisplayString, modID DisplayString, modOperStatus INTEGER, modLastChange TimeTicks, modName DisplayString, chNumber INTEGER } sysModInfo OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "A unique value for each module." ::= { moduleParamEntry 1 } modIndex OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "Identification number of the module" ::= { moduleParamEntry 2 } modDescr OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "Module description" ::= { moduleParamEntry 3 } modID OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "Identification number of module" ::= { moduleParamEntry 4 } modOperStatus OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "module status" ::= { moduleParamEntry 5 } modLastChange OBJECT-TYPE SYNTAX TimeTicks MAX-ACCESS read-only STATUS current DESCRIPTION "time since last change of module status" ::= { moduleParamEntry 6 } modName OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "name of the module" ::= { moduleParamEntry 7 } chNumber OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "count of channels" ::= { moduleParamEntry 8 } -- ================= -- channelParamTable -- ================= channelParamTable OBJECT-TYPE SYNTAX SEQUENCE OF ChannelParamEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A list of channel entries from a module. The number of entries is given by the value chNumber." ::= { moduleInfoGroup 4 } -- channelEntry (row) within the table channelParamEntry OBJECT-TYPE SYNTAX ChannelParamEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A unique value for each module." INDEX { moduleEntryID, chIndex } ::= { channelParamTable 1 } -- channelParamEntry within the table ChannelParamEntry ::= SEQUENCE { chIndex INTEGER, chDescr DisplayString, chID DisplayString, chOperStatus INTEGER, chLastChange TimeTicks, chName DisplayString, chNumber INTEGER } chIndex OBJECT-TYPE SYNTAX INTEGER (0..1) MAX-ACCESS read-only STATUS current DESCRIPTION "index of channel" ::= { channelParamEntry 1 } chDescr OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-write STATUS current DESCRIPTION "channel description" ::= { channelParamEntry 2 } chID OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "identification number channel" ::= { channelParamEntry 3 } chOperStatus OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "index of channel" ::= { channelParamEntry 4 } chLastChange OBJECT-TYPE SYNTAX TimeTicks MAX-ACCESS read-only STATUS current DESCRIPTION "time since last change of module status" ::= { channelParamEntry 5 } chName OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-write STATUS current DESCRIPTION "name of the channel" ::= { channelParamEntry 6 } chType OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "type of channel" ::= { channelParamEntry 7 } -- ====================== -- globalChannelDataTable -- ====================== globalChannelDataTable OBJECT-TYPE SYNTAX SEQUENCE OF GlobalChannelDataEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A global data channel entries from a module its channel and specific type." ::= { channelTypeDataGroup 1 } -- globalChannelDataEntry (row) within the table globalChannelDataEntry OBJECT-TYPE SYNTAX GlobalChannelDataEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A unique value for each module." INDEX { moduleEntryID, chIndex, chType} ::= { globalChannelDataTable 1 } -- globalChannelDataEntry sequence within the table GlobalChannelDataEntry ::= SEQUENCE { healthCounter INTEGER, extDiag INTEGER, intDiag INTEGER, restartDev INTEGER, errTelgr INTEGER, repTelgr INTEGER, cycleTimeMin Unsigned32, cycleTimeMax Unsigned32, cycleTimeAv Unsigned32, baudRate INTEGER, masterCount INTEGER, temperature INTEGER, repTelgrPerCycle INTEGER, networkName DisplayString } healthCounter OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "counter of the health, after call of this counter all data will be reset" ::= { globalChannelDataEntry 1 } extDiag OBJECT-TYPE SYNTAX INTEGER(0..65535) MAX-ACCESS read-only STATUS current DESCRIPTION "External Diagnosis counter from all devices." ::= { globalChannelDataEntry 2 } intDiag OBJECT-TYPE SYNTAX INTEGER(0..65535) MAX-ACCESS read-only STATUS current DESCRIPTION "Internal Diagnosis counter from all devices." ::= { globalChannelDataEntry 3 } restartDev OBJECT-TYPE SYNTAX INTEGER(0..65535) MAX-ACCESS read-only STATUS current DESCRIPTION "Count of a restart from all devices." ::= { globalChannelDataEntry 4 } errTelgr OBJECT-TYPE SYNTAX INTEGER(0..65535) MAX-ACCESS read-only STATUS current DESCRIPTION "Count of error telegrams from all devices." ::= { globalChannelDataEntry 5 } repTelgr OBJECT-TYPE SYNTAX INTEGER(0..65535) MAX-ACCESS read-only STATUS current DESCRIPTION "Count repetition telegrams from all devices." ::= { globalChannelDataEntry 6 } cycleTimeMin OBJECT-TYPE SYNTAX Unsigned32 MAX-ACCESS read-only STATUS current DESCRIPTION "Minimal cycle time of from each device." ::= { globalChannelDataEntry 7 } cycleTimeMax OBJECT-TYPE SYNTAX Unsigned32 MAX-ACCESS read-only STATUS current DESCRIPTION "Maximal cycle time of from each device." ::= { globalChannelDataEntry 8 } cycleTimeAv OBJECT-TYPE SYNTAX Unsigned32 MAX-ACCESS read-only STATUS current DESCRIPTION "Avarage cycle time of from each device." ::= { globalChannelDataEntry 9 } baudRate OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "Count repetition telegrams from all devices." ::= { globalChannelDataEntry 10 } masterCount OBJECT-TYPE SYNTAX INTEGER(0..126) MAX-ACCESS read-only STATUS current DESCRIPTION "Count of master devices." ::= { globalChannelDataEntry 11 } temperature OBJECT-TYPE SYNTAX INTEGER(-128..127) MAX-ACCESS read-only STATUS current DESCRIPTION "Temperature of isNetLite main module." ::= { globalChannelDataEntry 12 } repTelgrPerCycle OBJECT-TYPE SYNTAX INTEGER(0..255) MAX-ACCESS read-only STATUS current DESCRIPTION "Repetition of telegrams within one profibus cycle." ::= { globalChannelDataEntry 13 } networkName OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-write STATUS current DESCRIPTION "Name of the profibus segment" ::= { globalChannelDataEntry 14 } -- =============== -- deviceDataTable -- =============== deviceDataTable OBJECT-TYPE SYNTAX SEQUENCE OF DeviceDataEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A global data channel entries from a module its channel and specific type." ::= { channelTypeDataGroup 2 } -- deviceDataEntry (row) within the table deviceDataEntry OBJECT-TYPE SYNTAX DeviceDataEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A unique value for each module." INDEX { moduleEntryID, chIndex, chType, stationAddress} ::= { deviceDataTable 1 } -- deviceDataEntry sequence within the table DeviceDataEntry ::= SEQUENCE { stationAddress INTEGER, readCtrlCnt Counter32, devEvent Unsigned32, devName DisplayString, devLocation DisplayString } stationAddress OBJECT-TYPE SYNTAX INTEGER(0..127) MAX-ACCESS read-only STATUS current DESCRIPTION "Device number." ::= { deviceDataEntry 1 } readCtrlCnt OBJECT-TYPE SYNTAX Counter32 MAX-ACCESS read-only STATUS current DESCRIPTION "Read control counter (Nummer)." ::= { deviceDataEntry 2 } devEvent OBJECT-TYPE SYNTAX Unsigned32 MAX-ACCESS read-only STATUS current DESCRIPTION "Bit mask signals the specific events." ::= { deviceDataEntry 3 } devName OBJECT-TYPE SYNTAX DisplayString(SIZE(0..20)) MAX-ACCESS read-only STATUS current DESCRIPTION "Name of the device" ::= { deviceDataEntry 4 } devLocation OBJECT-TYPE SYNTAX DisplayString(SIZE(0..20)) MAX-ACCESS read-only STATUS current DESCRIPTION "Location of the device" ::= { deviceDataEntry 5 } -- END: Don't forget this! END
/* * Note: this file originally auto-generated by mib2c using * : mib2c.iterate.conf 15999 2007-03-25 22:32:02Z dts12 $ */ // C stdlib #include <pthread.h> #include <string.h> #include <errno.h> #include <sys/time.h> // other libs #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> // own libs //#include "isMutex.h" // own #include "indusolinsp.h" #include "network_data.h" //#include "module_param_table.h" //#include "channel_param_table.h" //#include "global_channel_data_table.h" //#include "device_data_table.h" /** Initializes the indusolinsp module */ //void* updateData(void); //pthread_t updatethread; //pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; //pthread_cond_t cond = PTHREAD_COND_INITIALIZER; char running = 0; void init_indusolinsp(void) { int retv = 0; /* here we initialize all the tables we're planning on supporting */ DEBUGMSG(("init_indusolinsp", "Init indusolinsp\n")); initialize_networkData(); initialize_table_moduleParamTable(); // initialize_table_channelParamTable(); // initialize_table_globalChannelDataTable(); // initialize_table_deviceDataTable(); running = 1; // /* create the update thread */ // retv=pthread_create( &updatethread, NULL, &updateData, NULL); // if (0 != retv) // snmp_log(LOG_DEBUG, "init_indusolinsp - Thread creation failed ...\n"); } void deinit_indusolinsp(void) { int retv = 0; running = 0; DEBUGMSG(("deinit_indusolinsp", "Deinit indusolinsp\n")); // pthread_cond_signal(&cond); deinitialize_networkData(); deinitialize_table_moduleParamTable(); // deinitialize_table_channelParamTable(); // deinitialize_table_globalChannelDataTable(); // deinitialize_table_deviceDataTable(); } //void* updateData(void) //{ // struct timeval now; // struct timespec timeout; // int retcode = 0; // // /* on first loop also we can sleep, because the initialization routine init_indusolinsp // * do the first data call */ // while (running) // { // gettimeofday(&now, NULL); // timeout.tv_sec = now.tv_sec + SNMP_UPDATE_DATA_SEC; // timeout.tv_nsec = now.tv_usec * 1000; // // pthread_mutex_lock(&mut); // retcode = pthread_cond_timedwait(&cond, &mut, &timeout); // pthread_mutex_unlock(&mut); // // if (retcode == ETIMEDOUT) // { // update_moduleParamTable(); // update_channelParamTable(); // update_globalChannelDataTable(); // update_deviceDataTable(); // snmp_log(LOG_DEBUG, "updateData successful ...\n"); // } // else // { // /* catch condition signal, e.g pthread_cond_broadcast() ctrl-c */ // break; // } // } //}
indusolinsp.h
Description: Binary data
/* * Note: this file originally auto-generated by mib2c using * : mib2c.iterate.conf 15999 2007-03-25 22:32:02Z dts12 $ */ // C stdlib // other libs #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> // own libs //#include "connect_req_handler.h" //#include "pbmon_debug_func.h" // own #include "network_data.h" Netsnmp_Node_Handler handle_sysInfo; Netsnmp_Node_Handler handle_moduleCount; Netsnmp_Node_Handler moduleIDTable_handler; Netsnmp_First_Data_Point moduleIDTable_get_first_data_point; Netsnmp_Next_Data_Point moduleIDTable_get_next_data_point; /* column number definitions for table moduleIDTable */ #define COLUMN_MODULEINDEX 1 #define COLUMN_MODULEENTRYID 2 /* * struct definition and declaration */ /* Typical data structure for a row entry */ struct moduleIDTable_entry { /* Index values */ long moduleEntryIDIndex; /* Column values */ long moduleEntryID; /* Illustrate using a simple linked list */ int valid; struct moduleIDTable_entry *next; }; /* global data definition */ struct moduleIDTable_entry *moduleIDTable_head = NULL; static main_network_data network_data; static char init = 0; /* function definitions */ struct moduleIDTable_entry *moduleIDTable_createEntry(long index); void moduleIDTable_removeEntry(struct moduleIDTable_entry *entry); void initialize_table_moduleIDTable(void); main_network_data* get_main_network_data(void) { return init ? &network_data : NULL; } void initialize_networkData(void) { static oid sysInfo_oid[] = { 1, 3, 6, 1, 4, 1, 26958, 25, 1, 1 }; static oid moduleCount_oid[] = { 1, 3, 6, 1, 4, 1, 26958, 25, 3, 1 }; // enum mod_pba_error retval = ERROR_MODPBA_NONE; bzero(&network_data, sizeof(main_network_data)); // retval = get_network_data(&network_data, UNIX_DOMAIN_SOCKET_PATH_SNMP); /* default initialisation for net-snmp test */ snprintf(network_data.firmware, sizeof(network_data.firmware), "v1.35"); network_data.modCount = 2; network_data.modEntryIDList[0] = 0x8801; network_data.modEntryIDList[1] = 0x9102; snmp_log(LOG_DEBUG, "Initializing networkData\n"); /* register the handler for oid sysInfo */ netsnmp_register_scalar(netsnmp_create_handler_registration("sysInfo", handle_sysInfo, sysInfo_oid, OID_LENGTH(sysInfo_oid), HANDLER_CAN_RONLY )); /* register the handler for oid moduleCount */ netsnmp_register_scalar(netsnmp_create_handler_registration("moduleCount", handle_moduleCount, moduleCount_oid, OID_LENGTH(moduleCount_oid), HANDLER_CAN_RONLY )); /* initialize the table moduleIDTable */ initialize_table_moduleIDTable(); init = 1; } void deinitialize_networkData(void) { while(moduleIDTable_head) moduleIDTable_removeEntry(moduleIDTable_head); init = 0; snmp_log(LOG_DEBUG, "deinitialize_networkData\n"); } /** Initialize the moduleIDTable table by defining its contents and how it's structured */ void initialize_table_moduleIDTable(void) { static oid moduleIDTable_oid[] = {1,3,6,1,4,1,26958,25,3,2}; size_t moduleIDTable_oid_len = OID_LENGTH(moduleIDTable_oid); netsnmp_handler_registration *reg; netsnmp_iterator_info *iinfo; netsnmp_table_registration_info *table_info; int i = 0; reg = netsnmp_create_handler_registration( "moduleEntryIDTable", moduleIDTable_handler, moduleIDTable_oid, moduleIDTable_oid_len, HANDLER_CAN_RONLY ); table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info ); iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info ); if (!reg || !table_info || !iinfo) { snmp_log(LOG_ERR, "malloc failed in initialize_table_moduleIDTable"); return; } /*************************************************** * Setting up the table's definition */ netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: moduleEntryIDIndex */ 0); table_info->min_column = COLUMN_MODULEINDEX; table_info->max_column = COLUMN_MODULEENTRYID; iinfo->get_first_data_point = moduleIDTable_get_first_data_point; iinfo->get_next_data_point = moduleIDTable_get_next_data_point; iinfo->table_reginfo = table_info; /*************************************************** * registering the table with the master agent */ netsnmp_register_table_iterator( reg, iinfo ); /* Initialise the contents of the table here */ for (i = 0; i < sizeof(network_data.modEntryIDList) / sizeof(network_data.modEntryIDList[0]); i++) { struct moduleIDTable_entry* entry = NULL; if (0 == network_data.modEntryIDList[i]) break; entry = (struct moduleIDTable_entry*) moduleIDTable_createEntry(i+1); entry->moduleEntryID = network_data.modEntryIDList[i]; if (entry) entry->valid = 0; } } /* create a new row in the (unsorted) table */ struct moduleIDTable_entry * moduleIDTable_createEntry(long index) { struct moduleIDTable_entry *entry; entry = SNMP_MALLOC_TYPEDEF(struct moduleIDTable_entry); if (!entry) return NULL; entry->moduleEntryIDIndex = index; entry->next = moduleIDTable_head; moduleIDTable_head = entry; return entry; } /* remove a row from the table */ void moduleIDTable_removeEntry( struct moduleIDTable_entry *entry ) { struct moduleIDTable_entry *ptr, *prev; if (!entry) return; /* Nothing to remove */ for ( ptr = moduleIDTable_head, prev = NULL; ptr != NULL; prev = ptr, ptr = ptr->next ) { if ( ptr == entry ) break; } if ( !ptr ) return; /* Can't find it */ if ( prev == NULL ) moduleIDTable_head = ptr->next; else prev->next = ptr->next; SNMP_FREE( entry ); /* XXX - release any other internal resources */ } /* Example iterator hook routines - using 'get_next' to do most of the work */ netsnmp_variable_list * moduleIDTable_get_first_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { *my_loop_context = moduleIDTable_head; return moduleIDTable_get_next_data_point(my_loop_context, my_data_context, put_index_data, mydata ); } netsnmp_variable_list * moduleIDTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { struct moduleIDTable_entry *entry = (struct moduleIDTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; if (entry) { snmp_set_var_typed_integer(idx, ASN_INTEGER, entry->moduleEntryIDIndex); idx = idx->next_variable; *my_data_context = (void *) entry; *my_loop_context = (void *) entry->next; return put_index_data; } else { return NULL; } } /** handles requests for the sysInfo information */ int handle_sysInfo(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, network_data.firmware, strlen(network_data.firmware)); break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_sysInfo\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; } /** handles requests for the moduleCount information */ int handle_moduleCount(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, network_data.modCount); break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_moduleCount\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; } /** handles requests for the moduleIDTable table */ int moduleIDTable_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 moduleIDTable_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { table_entry = (struct moduleIDTable_entry *) netsnmp_extract_iterator_context( request); table_info = netsnmp_extract_table_info(request); if (table_info) { // if (!table_info) // { // netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); // continue; // } switch (table_info->colnum) { case COLUMN_MODULEENTRYID: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->moduleEntryID); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } else { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); } break; } } return SNMP_ERR_NOERROR; }
network_data.h
Description: Binary data
/* * Note: this file originally auto-generated by mib2c using * : mib2c.iterate.conf 15999 2007-03-25 22:32:02Z dts12 $ */ // C stdlib #include <time.h> // other libs #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> // own libs //#include "connect_req_handler.h" //#include "command_telegram.h" // own #include "network_data.h" #include "module_param_table.h" /* function definitions */ struct moduleParamTable_entry *moduleParamTable_createEntry(long moduleIDIndex); void moduleParamTable_removeEntry(struct moduleParamTable_entry *entry); struct moduleParamTable_entry * moduleParamTable_createEntry(long moduleIDIndex); /* global data definition */ //Mutex m_lock_moduleparam; struct moduleParamTable_entry *moduleParamTable_head = NULL; int moduleParamTable_actual_entry(long modID, struct moduleParamTable_entry *entry) { // enum mod_pba_error error = ERROR_MODPBA_NONE; int error = 0; if (entry) { // error = pbmon_get_modul_param_data(&entry->mod_param, modID & 0xFF, modID // >> 8, UNIX_DOMAIN_SOCKET_PATH_SNMP); snprintf(entry->mod_param.modID, sizeof(entry->mod_param.modID), "0x%04X", modID); entry->mod_param.modLastChange = netsnmp_get_agent_uptime(); entry->mod_param.modOperStatusCounter = 0; entry->mod_param.modindex = modID & 0xFF; snprintf(entry->mod_param.writable_param.modName, sizeof(entry->mod_param.writable_param.modName), "Modul 0x%04X", modID); snprintf(entry->mod_param.writable_param.moddescr, sizeof(entry->mod_param.writable_param.moddescr), "Description Modul 0x%04X", modID); switch (modID >> 8) { case 0x88: entry->mod_param.channelCount = 1; snprintf(entry->mod_param.firmware, sizeof(entry->mod_param.firmware), "v1.35"); break; case 0x91: entry->mod_param.channelCount = 2; snprintf(entry->mod_param.firmware, sizeof(entry->mod_param.firmware), "v1.65"); break; default: break; } } return error; } //void update_moduleParamTable(void) //{ //// lock(&m_lock_moduleparam); //// { // struct moduleParamTable_entry *table_entry = moduleParamTable_head; //// enum mod_pba_error error = ERROR_MODPBA_NONE; // int error = 0; // while (table_entry) // { // error = moduleParamTable_actual_entry(table_entry->moduleEntryID, // table_entry); // // if (error != 0) // break; // // table_entry = table_entry->next; // if (table_entry == moduleParamTable_head) // break; // } //// } //// unlock(&m_lock_moduleparam); //} //struct moduleParamTable_entry *get_next_moduleParamTable_entry( // struct moduleParamTable_entry * table_entry) //{ // struct moduleParamTable_entry *tmp_entry = moduleParamTable_head; // if (tmp_entry) // { // if (NULL != table_entry) // { // struct moduleParamTable_entry *ptr, *prev; // for (ptr = tmp_entry, prev = NULL; ptr != NULL; prev = ptr, ptr // = ptr->next) // { // if (ptr == table_entry) // break; // } // if (!ptr) // return NULL; /* Can't find it */ // // if (prev == NULL) // tmp_entry = ptr->next; // else // prev->next = ptr->next; // } // } // return tmp_entry; //} struct moduleParamTable_entry *get_moduleParamTable_entry(void) { return moduleParamTable_head; } /** Initialize the moduleParamTable table by defining its contents and how it's structured */ void initialize_table_moduleParamTable(void) { static oid moduleParamTable_oid[] = {1,3,6,1,4,1,26958,25,3,3}; size_t moduleParamTable_oid_len = OID_LENGTH(moduleParamTable_oid); netsnmp_handler_registration *reg; netsnmp_iterator_info *iinfo; netsnmp_table_registration_info *table_info; main_network_data* network_data = NULL; int i = 0; reg = netsnmp_create_handler_registration( "moduleParamTable", moduleParamTable_handler, moduleParamTable_oid, moduleParamTable_oid_len, HANDLER_CAN_RONLY ); table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info ); netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: moduleEntryID */ 0); table_info->min_column = COLUMN_SYSINFO; table_info->max_column = COLUMN_CHCOUNT; iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info ); iinfo->get_first_data_point = moduleParamTable_get_first_data_point; iinfo->get_next_data_point = moduleParamTable_get_next_data_point; iinfo->table_reginfo = table_info; netsnmp_register_table_iterator( reg, iinfo ); /* Initialise the contents of the table here */ network_data = get_main_network_data(); if (network_data) { for (i = 0; i < sizeof(network_data->modEntryIDList) / sizeof(network_data->modEntryIDList[0]); i++) { struct moduleParamTable_entry* entry = NULL; if (0 == network_data->modEntryIDList[i]) break; entry = moduleParamTable_createEntry(network_data->modEntryIDList[i]); if (entry) { // enum mod_pba_error error = moduleParamTable_actual_entry( // entry->moduleEntryID, entry); int error = moduleParamTable_actual_entry( entry->moduleEntryID, entry); if (0 == error) { if (entry) entry->valid = 0; } else { snmp_log(LOG_DEBUG, "initialize_table_moduleParamTable - remove entry\n"); moduleParamTable_removeEntry(entry); } } } } else { snmp_log(LOG_DEBUG, "no data availabe initialize_table_moduleParamTable\n"); } snmp_log(LOG_DEBUG, "initialize_table_moduleParamTable\n"); } void deinitialize_table_moduleParamTable(void) { while(moduleParamTable_head) moduleParamTable_removeEntry(moduleParamTable_head); snmp_log(LOG_DEBUG, "deinitialize_table_moduleParamTable\n"); } /* create a new row in the (unsorted) table */ struct moduleParamTable_entry * moduleParamTable_createEntry( long moduleIDIndex ) { struct moduleParamTable_entry *entry; entry = SNMP_MALLOC_TYPEDEF(struct moduleParamTable_entry); if (!entry) return NULL; bzero((void*) entry, sizeof(struct moduleParamTable_entry)); entry->moduleEntryID = moduleIDIndex; entry->next = moduleParamTable_head; moduleParamTable_head = entry; return entry; } /* remove a row from the table */ void moduleParamTable_removeEntry( struct moduleParamTable_entry *entry ) { struct moduleParamTable_entry *ptr, *prev; if (!entry) return; /* Nothing to remove */ for ( ptr = moduleParamTable_head, prev = NULL; ptr != NULL; prev = ptr, ptr = ptr->next ) { if ( ptr == entry ) break; } if ( !ptr ) return; /* Can't find it */ if ( prev == NULL ) moduleParamTable_head = ptr->next; else prev->next = ptr->next; SNMP_FREE( entry ); /* XXX - release any other internal resources */ } /* Example iterator hook routines - using 'get_next' to do most of the work */ netsnmp_variable_list * moduleParamTable_get_first_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { *my_loop_context = moduleParamTable_head; return moduleParamTable_get_next_data_point(my_loop_context, my_data_context, put_index_data, mydata ); } netsnmp_variable_list * moduleParamTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { struct moduleParamTable_entry *entry = (struct moduleParamTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; if ( entry ) { snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->moduleEntryID ); idx = idx->next_variable; *my_data_context = (void *)entry; *my_loop_context = (void *)entry->next; return put_index_data; } else { return NULL; } } /** handles requests for the moduleParamTable table */ int moduleParamTable_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 moduleParamTable_entry *table_entry; // bool get_data = false; // lock(&m_lock_moduleparam); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request=requests; request; request=request->next) { table_entry = (struct moduleParamTable_entry *) netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info( request); // if (table_entry && !get_data) // { // enum mod_pba_error error = moduleParamTable_actual_entry( // table_entry->moduleEntryID, table_entry); // // if (error != ERROR_MODPBA_NONE) // table_entry = NULL; // get_data = true; // } if (table_info) { switch (table_info->colnum) { case COLUMN_SYSINFO: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, table_entry->mod_param.firmware, strlen(table_entry->mod_param.firmware)); break; case COLUMN_MODINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->mod_param.modindex); break; case COLUMN_MODDESCR: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value( requests->requestvb, ASN_OCTET_STR, table_entry->mod_param.writable_param.moddescr, strlen( table_entry->mod_param.writable_param.moddescr)); break; case COLUMN_MODID: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, table_entry->mod_param.modID, strlen(table_entry->mod_param.modID)); break; case COLUMN_MODOPERSTATUS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->mod_param.modOperStatusCounter); break; case COLUMN_MODLASTCHANGE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, (u_long) table_entry->mod_param.modLastChange); break; case COLUMN_MODNAME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value( requests->requestvb, ASN_OCTET_STR, table_entry->mod_param.writable_param.modName, strlen( table_entry->mod_param.writable_param.modName)); break; case COLUMN_CHCOUNT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->mod_param.channelCount); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } else { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); } break; } } // unlock(&m_lock_moduleparam); return SNMP_ERR_NOERROR; }
module_param_table.h
Description: Binary data
------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d
_______________________________________________ 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