How to initialise the contents of the table ?
"飞飞" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Hi ALL:
I got my mib file(a simple table constructure)rightly,I use mib2c.table_data.conf template generate the .c file,but I cannot get the right result use snmpwalk -v1 -c public localhost.
I also got no error when I used make ;make install reinstalled the net-snmp source code.
The FAQ:Coding 12 Why doesn't my new MIB module report anything? cannot help me much,It look like is something very conmused me.
Who can tell me where I am wrong,and how to fix it ?
Thank you very much!
Alex
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.table_data.conf 15999 2007-03-25 22:32:02Z 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 "uit.h"
#include <stdio.h>
#include <string.h>
#define NNN 8
int intp[1] = {0};
u_long uintp[4] = {5,5,5};
// u_char ucharp[8] = "sbsbsbs";
unsigned char *ucharp = "sbsbsbs";
/** Initializes the uit module */
void
init_uit(void)
{
/* here we initialize all the tables we're planning on supporting */
initialize_table_diskSystemTable();
}
/* # Determine the first/last column names */
/** Initialize the diskSystemTable table by defining its contents and how it's structured */
void
initialize_table_diskSystemTable(void)
{
static oid diskSystemTable_oid[] = {1,3,6,1,4,1,30901,2090,7000,1,1};
size_t diskSystemTable_oid_len = OID_LENGTH(diskSystemTable_oid);
netsnmp_handler_registration *reg;
netsnmp_tdata *table_data;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration(
"diskSystemTable", diskSystemTable_handler,
diskSystemTable_oid, diskSystemTable_oid_len,
HANDLER_CAN_RONLY
);
table_data = netsnmp_tdata_create_table( "diskSystemTable", 0 );
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info,
0);
table_info->min_column = COLUMN_PORTID;
table_info->max_column = COLUMN_SN;
netsnmp_tdata_register( reg, table_data, table_info );
/* Initialise the contents of the table here */ /* what am I do something here???*/
}
/* Typical data structure for a row entry */
struct diskSystemTable_entry {
/* Index values */
/* Column values */
u_long portID;
u_long encID;
u_long slotID;
u_long speed;
long status;
u_long revNew;
long smtStatus;
long bufStatus;
long dstype;
u_long uuID;
u_long size;
unsigned char diskID[NNN];
size_t diskID_len;
unsigned char vendor[NNN];
size_t vendor_len;
unsigned char revision[NNN];
size_t revision_len;
unsigned char product[NNN];
size_t product_len;
unsigned char sn[NNN];
size_t sn_len;
int valid;
};
/* create a new row in the table */
netsnmp_tdata_row *
diskSystemTable_createEntry(netsnmp_tdata *table_data
) {
struct diskSystemTable_entry *entry;
netsnmp_tdata_row *row;
entry = SNMP_MALLOC_TYPEDEF(struct diskSystemTable_entry);
if (!entry)
return NULL;
row = netsnmp_tdata_create_row();
if (!row) {
SNMP_FREE(entry);
return NULL;
}
row->data = entry;
netsnmp_tdata_add_row( table_data, row );
return row;
}
/* remove a row from the table */
void
diskSystemTable_removeEntry(netsnmp_tdata *table_data,
netsnmp_tdata_row *row) {
struct diskSystemTable_entry *entry;
if (!row)
return; /* Nothing to remove */
entry = (struct diskSystemTable_entry *)
netsnmp_tdata_remove_and_delete_row( table_data, row );
if (entry)
SNMP_FREE( entry ); /* XXX - release any other internal resources */
}
/** handles requests for the diskSystemTable table */
int
diskSystemTable_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;
netsnmp_tdata *table_data;
netsnmp_tdata_row *table_row;
struct diskSystemTable_entry *table_entry;
int ret;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request=requests; request; request=request->next) {
table_entry = (struct diskSystemTable_entry *)
netsnmp_tdata_extract_entry(request);
table_info = netsnmp_extract_table_info( request);
switch (table_info->colnum) {
case COLUMN_PORTID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->portID = 168;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->portID);
break;
case COLUMN_ENCID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->encID = 888;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->encID);
break;
case COLUMN_SLOTID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->slotID = 1;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->slotID);
break;
case COLUMN_SPEED:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->speed = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->speed);
break;
case COLUMN_STATUS:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->status = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->status);
break;
case COLUMN_REVNEW:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->revNew = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->revNew);
break;
case COLUMN_SMTSTATUS:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->smtStatus = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->smtStatus);
break;
case COLUMN_BUFSTATUS:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->bufStatus = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->bufStatus);
break;
case COLUMN_DSTYPE:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->dstype = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
table_entry->dstype);
break;
case COLUMN_UUID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->uuID = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->uuID);
break;
case COLUMN_SIZE:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
table_entry->size = 0;
snmp_set_var_typed_integer( request->requestvb, ASN_UNSIGNED,
table_entry->size);
break;
case COLUMN_DISKID:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
// table_entry->diskID = ucharp;
// memcpy();
memcpy(table_entry->diskID,ucharp,7);
table_entry->diskID_len = 8;
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
( u_char *)table_entry->diskID,
table_entry->diskID_len);
break;
case COLUMN_VENDOR:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
// table_entry->vendor = ucharp;
memcpy(table_entry->vendor,ucharp,7);
table_entry->vendor_len = 8;
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
( u_char * )table_entry->vendor,
table_entry->vendor_len);
break;
case COLUMN_REVISION:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
// table_entry->revision = ucharp;
memcpy(table_entry->revision,ucharp,7);
table_entry->revision_len = 8;
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
( u_char * )table_entry->revision,
table_entry->revision_len);
break;
case COLUMN_PRODUCT:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
// table_entry->product = ucharp;
memcpy(table_entry->product,ucharp,7);
table_entry->product_len = 8;
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
( u_char * )table_entry->product,
table_entry->product_len);
break;
case COLUMN_SN:
if ( !table_entry ) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//table_entry->sn = ucharp;
memcpy(table_entry->sn,ucharp,7);
table_entry->sn_len = 8;
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
( u_char * )table_entry->sn,
table_entry->sn_len);
break;
default:
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHOBJECT);
break;
}
}
break;
}
return SNMP_ERR_NOERROR;
}
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
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