Dear sir(s),
I made a table for getting mibs information.
The structure is as following,
Table.c
/* ****************************** table ****************************** */
/** Initialize the table by defining its contents and how it's structured */
void
initialize_table(void)
{
static oid encTable_oid[] = {1,3,6,1,4,1,3064,2,162,101,100};
netsnmp_table_data_set *table_set;
netsnmp_table_registration_info *table_info;
netsnmp_iterator_info *it_info;
netsnmp_handler_registration *enc_handler;
//DEBUGMSGTL(("emsTable", "initialize_table_emsEncTable\n"));
/* create the table structure itself */
table_set = netsnmp_create_table_data_set("emsEncTable");
/* comment this out or delete if you don't support creation of new rows
*/
table_set->allow_creation = 1;
/***************************************************
* Adding indexes
*/
//DEBUGMSGTL(("emsTable", "adding indexes to table emsEncTable\n"));
netsnmp_table_set_add_indexes(table_set,ASN_OCTET_STR,0);
//DEBUGMSGTL(("emsTable", "adding column types to table
emsEncTable\n"));
netsnmp_table_set_multi_add_default_row(table_set,
COLUMN_ENC_NAME, ASN_OCTET_STR,
0, NULL, 0,
COLUMN_ENC_TYPE, ASN_OCTET_STR,
0, NULL, 0,
COLUMN_ENC_STATUS,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_WWN, ASN_OCTET_STR,
0, NULL, 0,
COLUMN_ENC_MAX_CTLR_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MAX_PS_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MAX_BAT_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MAX_FAN_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MAX_DISK_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_CUR_CTLR_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_CUR_PS_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_CUR_BAT_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_CUR_FAN_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_CUR_DISK_NUM,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MIDPLANE_TEMP_A,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_MIDPLANE_TEMP_B,
ASN_OCTET_STR, 0, NULL, 0,
COLUMN_ENC_SERIAL_NO,
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 emsEncTable handler */
enc_handler = netsnmp_create_handler_registration(
"emsEncTable",
encTable_handler,
encTable_oid,
OID_LENGTH(encTable_oid),
HANDLER_CAN_RONLY);
if (!enc_handler || !table_info || !it_info) {
//snmp_log(LOG_ERR, "malloc failed in
initialize_table_emsEncTable");
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_ENC_NAME;
table_info->max_column = COLUMN_ENC_SERIAL_NO;
/** iterator access routines */
it_info->get_first_data_point = encTable_get_first_data_point;
it_info->get_next_data_point = encTable_get_next_data_point;
it_info->free_data_context = encTable_data_free;
it_info->free_loop_context = encTable_loop_free;
it_info->free_loop_context_at_end = encTable_loop_free;
/** tie the two structures together */
it_info->table_reginfo = table_info;
/***************************************************
* registering the table with the master agent
*/
//DEBUGMSGTL(("emsTable", "Registering table emsEncTable as a table
iterator\n"));
netsnmp_register_table_iterator(enc_handler, it_info);
}
/** handles requests for the emsEncTable table, if anything else needs to be
done */
int
encTable_handler(
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
//DEBUGMSGTL(("emsEncTable", "Handler - mode %s\n",
se_find_label_in_slist("agent_mode", reqinfo->mode)));
switch (reqinfo->mode)
{
case MODE_GET:
//DEBUGMSGTL(("emsEncTable", "MODE_GET CALLED\n"));
handle_enc_table_get(requests);
break;
case MODE_SET_ACTION:
case MODE_GETNEXT:
default:
//DEBUGMSGTL(("emsEncTable", "unhandled mode %d\n", reqinfo->mode));
break;
}
return SNMP_ERR_NOERROR;
}
void handle_enc_table_get(netsnmp_request_info * requests)
{
netsnmp_request_info *request;
netsnmp_variable_list *requestvb;
netsnmp_table_request_info *table_info;
llist_stats_enc* entry = NULL;
oid subid;
for (request=requests; request; request=request->next)
{
requestvb = request->requestvb;
entry = (llist_stats_enc*)netsnmp_extract_iterator_context(request);
if (entry == NULL) {
//DEBUGMSGTL(( "emsEncTable", "No iterator context\n"));
continue;
}
table_info = netsnmp_extract_table_info(request);
subid = table_info->colnum;
//DEBUGMSGTL(( "emsEncTable", "context %s @%p / %d\n", entry->encName,
entry, subid));
switch (subid)
{
case COLUMN_ENC_NAME:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encName));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encName,
strlen(entry->encName));
break;
case COLUMN_ENC_TYPE:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encType));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encType,
strlen(entry->encType));
break;
case COLUMN_ENC_STATUS:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encStatus));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encStatus,
strlen(entry->encStatus));
break;
case COLUMN_ENC_WWN:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encWwn));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encWwn,
strlen(entry->encWwn));
break;
case COLUMN_ENC_MAX_CTLR_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMaxControllerNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encMaxControllerNum, strlen(entry->encMaxControllerNum));
break;
case COLUMN_ENC_MAX_PS_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMaxPowerSupplyNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encMaxPowerSupplyNum, strlen(entry->encMaxPowerSupplyNum));
break;
case COLUMN_ENC_MAX_BAT_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMaxBatteryNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encMaxBatteryNum, strlen(entry->encMaxBatteryNum));
break;
case COLUMN_ENC_MAX_FAN_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMaxFanNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encMaxFanNum,
strlen(entry->encMaxFanNum));
break;
case COLUMN_ENC_MAX_DISK_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMaxDiskNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encMaxDiskNum,
strlen(entry->encMaxDiskNum));
break;
case COLUMN_ENC_CUR_CTLR_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encCurControllerNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encCurControllerNum, strlen(entry->encCurControllerNum));
break;
case COLUMN_ENC_CUR_PS_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encCurPowerSupplyNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encCurPowerSupplyNum, strlen(entry->encCurPowerSupplyNum));
break;
case COLUMN_ENC_CUR_BAT_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encCurBatteryNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encCurBatteryNum, strlen(entry->encCurBatteryNum));
break;
case COLUMN_ENC_CUR_FAN_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encCurFanNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encCurFanNum,
strlen(entry->encCurFanNum));
break;
case COLUMN_ENC_CUR_DISK_NUM:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encCurDiskNum));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encCurDiskNum,
strlen(entry->encCurDiskNum));
break;
case COLUMN_ENC_MIDPLANE_TEMP_A:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMidplandTempA));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encMidplandTempA, strlen(entry->encMidplandTempA));
break;
case COLUMN_ENC_MIDPLANE_TEMP_B:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encMidplandTempB));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR,
entry->encMidplandTempB, strlen(entry->encMidplandTempB));
break;
case COLUMN_ENC_SERIAL_NO:
//DEBUGMSGTL(( "emsEncTable", "setting %d to %s\n", subid,
entry->encSerialNo));
snmp_set_var_typed_value(requestvb, ASN_OCTET_STR, entry->encSerialNo,
strlen(entry->encSerialNo));
break;
default:
//DEBUGMSGTL(( "emsEncTable", "no such column %d\n", subid));
break;
}
}
}
netsnmp_variable_list *
encTable_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_enc * tlist = NULL;
llist_stats_enc * row;
int curEncNum = 0, i;
//DEBUGMSGTL(( "emsEncTable", "get_first_data_point() *my_loop_context =
%p\n", *my_loop_context ));
if(tlist == NULL)
{
tlist = SNMP_MALLOC_TYPEDEF(llist_stats_enc);
if (!tlist)
return NULL;
memset(&snmpReq,0,sizeof(SNMPREQUEST));
snmpReq.mibtype = SNMPAGENT_REQUEST_IOC_GET_EMS_CURENCNUM;
getQuantaTableInfo(&snmpReq);
curEncNum = snmpReq.integer;
row = tlist;
for (i=0; i<curEncNum; i++) {
memset(&snmpReq,0,sizeof(SNMPREQUEST));
snmpReq.mibtype = SNMPAGENT_REQUEST_IOC_GET_EMS_CURENCINFO;
snmpReq.integer = i;
getQuantaTableInfo(&snmpReq);
strncpy(row->encName, snmpReq.tableInfo1, sizeof(row->encName));
strncpy(row->encType, snmpReq.tableInfo2, sizeof(row->encType));
strncpy(row->encStatus, snmpReq.tableInfo3, sizeof(row->encStatus));
strncpy(row->encWwn, snmpReq.tableInfo4, sizeof(row->encWwn));
strncpy(row->encMaxControllerNum, snmpReq.tableInfo5,
sizeof(row->encMaxControllerNum));
strncpy(row->encMaxPowerSupplyNum, snmpReq.tableInfo6,
sizeof(row->encMaxPowerSupplyNum));
strncpy(row->encMaxBatteryNum, snmpReq.tableInfo7,
sizeof(row->encMaxBatteryNum));
strncpy(row->encMaxFanNum, snmpReq.tableInfo8,
sizeof(row->encMaxFanNum));
strncpy(row->encMaxDiskNum, snmpReq.tableInfo9,
sizeof(row->encMaxDiskNum));
strncpy(row->encCurControllerNum, snmpReq.tableInfo10,
sizeof(row->encCurControllerNum));
strncpy(row->encCurPowerSupplyNum, snmpReq.tableInfo11,
sizeof(row->encCurPowerSupplyNum));
strncpy(row->encCurBatteryNum, snmpReq.tableInfo12,
sizeof(row->encCurBatteryNum));
strncpy(row->encCurFanNum, snmpReq.tableInfo13,
sizeof(row->encCurFanNum));
strncpy(row->encCurDiskNum, snmpReq.tableInfo14,
sizeof(row->encCurDiskNum));
strncpy(row->encMidplandTempA, snmpReq.tableInfo15,
sizeof(row->encMidplandTempA));
strncpy(row->encMidplandTempB, snmpReq.tableInfo16,
sizeof(row->encMidplandTempB));
strncpy(row->encSerialNo, snmpReq.tableInfo17, sizeof(row->encSerialNo));
if(i==curEncNum-1) {
row->next = NULL;
} else {
row->next = SNMP_MALLOC_TYPEDEF(llist_stats_enc);
row = row->next;
}
}
}
*my_loop_context = tlist;
//DEBUGMSGTL(( "emsEncTable", "get_first_data_point() setting
*my_loop_context = %p %s\n", tlist, tlist->encName));
return encTable_get_next_data_point(my_loop_context,
my_data_context,
put_index_data,
mydata);
}
netsnmp_variable_list *
encTable_get_next_data_point(void **loop_context,
void **data_context,
netsnmp_variable_list * index,
netsnmp_iterator_info *data)
{
llist_stats_enc* list = (llist_stats_enc*)*loop_context;
if(list == NULL)
{
return NULL;
}
/*set table indexes*/
//DEBUGMSGTL(( "emsEncTable", "get_next_data_point() *my_loop_context = %p
%s\n",list, list->encName));
snmp_set_var_value(index, (u_char *) list->encName, strlen(list->encName));
/*if (!index->next_variable)
{
index->next_variable = SNMP_MALLOC_STRUCT(variable_list);
index->next_variable->type = ASN_OCTET_STR;
}
snmp_set_var_value(index->next_variable, (u_char *) list->encType,
strlen(list->encType));*/
*data_context = (void*)list;
*loop_context = (void*)list->next;
return index;
}
void
encTable_data_free(void *data, netsnmp_iterator_info *iinfo)
{
//DEBUGMSGTL(( "emsEncTable", "encTable_data_free() %p\n", data));
}
void
encTable_loop_free(void *loopctx, netsnmp_iterator_info *iinfo)
{
//DEBUGMSGTL(( "emsEncTable", "encTable_loop_free() %p\n", loopctx));
}
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
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