Dears,
I can get table information that I need by using mib browser, but I find two
questions when I do it.
Q1: If I use the command to get Table A, the agent will ask the inforation A
and information B.
If I use the command to get Table B, the agent will ask the
inforation B and information C.
If I use the command to get Table C, the agent will ask the
inforation B and information D.
...
How can I do that let it only gets the needed information?
Q2: If I get a table Information only ONE time, but the agent will ask the
information more than one time.
Why?
****************************************************************************************************************************
The structure of my system:
User snmp agent
(Net-SNMP-5.4) My-Kernel
snmp command ---- request ----> receive command and ask the info. ---->
ask ----> get info. and return it
****************************************************************************************************************************
My code that about table:
/* ****************************** Table A ****************************** */
void
initialize_table_fanTable(void)
{
static oid tableA_oid[] = {1,3,6,1,4,1,3064,2,162,101,105};
netsnmp_table_data_set *table_set;
netsnmp_table_registration_info *table_info;
netsnmp_iterator_info *it_info;
netsnmp_handler_registration *A_handler;
/* create the table structure itself */
table_set = netsnmp_create_table_data_set("tableA");
/* comment this out or delete if you don't support creation of new rows
*/
table_set->allow_creation = 1;
/***************************************************
* Adding indexes
*/
netsnmp_table_set_add_indexes(table_set,ASN_OCTET_STR,0);
netsnmp_table_set_multi_add_default_row(table_set,
COLUMN_NAME, ASN_OCTET_STR, 0,
NULL, 0,
COLUMN_STATUS, ASN_OCTET_STR, 0,
NULL, 0,
0);
/** create the table registration information structures */
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
it_info = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
/** register emsFanTable handler */
fan_handler = netsnmp_create_handler_registration(
"tableA",
A_handler,
tableA_oid,
OID_LENGTH(tableA_oid),
HANDLER_CAN_RONLY);
if (!fan_handler || !table_info || !it_info) {
//snmp_log(LOG_ERR, "malloc failed in
initialize_table_emsFanTable");
return; /** Serious error. */
}
/***************************************************
* Setting up the table's definition
*/
netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR,0);
/** Define the minimum and maximum accessible columns. This
optimizes retrival. */
table_info->min_column = COLUMN_NAME;
table_info->max_column = COLUMN_STATUS;
/** iterator access routines */
it_info->get_first_data_point = tableA_get_first_data_point;
it_info->get_next_data_point = tableA_get_next_data_point;
it_info->free_data_context = tableA_data_free;
it_info->free_loop_context = tableA_loop_free;
it_info->free_loop_context_at_end = tableA_loop_free;
/** tie the two structures together */
it_info->table_reginfo = table_info;
/***************************************************
* registering the table with the master agent
*/
netsnmp_register_table_iterator(A_handler, it_info);
}
/** handles requests for the emsFanTable table, if anything else needs to be
done */
int
A_handler(
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
switch (reqinfo->mode)
{
case MODE_GET:
//DEBUGMSGTL(("emsFanTable", "MODE_GET CALLED\n"));
handle_a_table_get(requests);
break;
case MODE_SET_ACTION:
case MODE_GETNEXT:
default:
//
break;
}
return SNMP_ERR_NOERROR;
}
void handle_a_table_get(netsnmp_request_info * requests)
{
netsnmp_request_info *request;
netsnmp_variable_list *requestvb;
netsnmp_table_request_info *table_info;
llist_stats_fan* entry = NULL;
oid subid;
for (request=requests; request; request=request->next)
{
requestvb = request->requestvb;
entry = (llist_stats_fan*)netsnmp_extract_iterator_context(request);
if (entry == NULL) {
continue;
}
table_info = netsnmp_extract_table_info(request);
subid = table_info->colnum;
switch (subid)
{
case COLUMN_NAME:
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->aName,
strlen(entry->aName));
break;
case COLUMN_FAN_STATUS:
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->aStatus,
strlen(entry->aStatus));
break;
default:
//
break;
}
}
}
netsnmp_variable_list *
tableA_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
static llist_stats * tlist = NULL;
llist_stats * row;
int i, curNum=0;
memset(&snmpReq,0,sizeof(SNMPREQUEST));
snmpReq.mibtype = SNMPAGENT_REQUEST_IOC_GET_NUM_A;
getQuantaTableInfo(&snmpReq);
//------------------------------------------------------> call this
command will get info. from kernel
curNum = snmpReq.integer;
if(curNum > 0) {
if(tlist== NULL)
{
tlist = SNMP_MALLOC_TYPEDEF(llist_stats);
if (!tlist)
return NULL;
tlist->next = NULL;
}
row = tlist;
for (i=0; i<curNum; i++) {
memset(&snmpReq,0,sizeof(SNMPREQUEST));
snmpReq.mibtype = SNMPAGENT_REQUEST_IOC_GET_INFO_A;
snmpReq.integer = i;
getQuantaTableInfo(&snmpReq);
strncpy(row->Name, snmpReq.tableInfo1, sizeof(row->aName));
strncpy(row->Status, snmpReq.tableInfo2, sizeof(row->aStatus));
if(i==curNum-1) {
while(row->next != NULL) {
llist_stats *nextPtr = row->next;
while(nextPtr->next != NULL) {
nextPtr = nextPtr->next;
}
free(nextPtr);
nextPtr = NULL;
}
row->next = NULL;
} else {
if(row->next == NULL) {
row->next = SNMP_MALLOC_TYPEDEF(llist_stats);
}
row = row->next;
}
}
} else {
if(tlist != NULL) {
while(tlist->next != NULL) {
llist_stats *nextPtr = tlist->next;
while(nextPtr->next != NULL) {
nextPtr = nextPtr->next;
}
free(nextPtr);
nextPtr = NULL;
}
free(tlist_fan);
tlist_fan = NULL;
}
}
*my_loop_context = tlist;
return fanTable_get_next_data_point(my_loop_context,
my_data_context,
put_index_data,
mydata);
}
netsnmp_variable_list *
fanTable_get_next_data_point(void **loop_context,
void **data_context,
netsnmp_variable_list * index,
netsnmp_iterator_info *data)
{
llist_stats* list = (llist_stats*)*loop_context;
if(list == NULL)
{
return NULL;
}
/*set table indexes*/
snmp_set_var_value(index, (u_char *) list->aName, strlen(list->aName));
*data_context = (void*)list;
*loop_context = (void*)list->next;
return index;
}
void
fanTable_data_free(void *data, netsnmp_iterator_info *iinfo)
{
//
}
void
fanTable_loop_free(void *loopctx, netsnmp_iterator_info *iinfo)
{
//
}
******************************************************************************************************************
The table B, C, D,etc are the same as table A.
Best regards,
Bluce
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
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