gpt4 book ai didi

c - net-snmp mib 模块处理程序/回调示例?

转载 作者:太空宇宙 更新时间:2023-11-04 04:59:47 25 4
gpt4 key购买 nike

我正在寻找一个带有自定义回调的 mib 模块的示例实现,该回调处理 Netsnmp_node_handler 中的某些结构:

test_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)

我想看一个检查它是什么请求的示例,即获取/设置/监视请求。检查 oid 是否与类中的 oid 匹配,获取 oid 值等。目前我在执行此操作时遇到问题。

另外,当我执行 snmpset 时,我的模块被调用了两次,不知道为什么。

最佳答案

您要求的是完整的实现。是不是太过分了。只是为了方便,放一些基本代码:

void init_InterfaceCountTable(void)
{
oid my_registration_oid[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //Give complete OID of your table
table_set = netsnmp_create_table_data_set("InterfaceCountTable");

table_set->allow_creation = 1;
if(FLAG != 1)
{
netsnmp_table_dataset_add_index(table_set, ASN_INTEGER);

netsnmp_table_set_multi_add_default_row(table_set,
COLUMN_INTERFACECOUNTRX, ASN_INTEGER, 1, NULL, 0,
COLUMN_INTERFACECOUNTTX, ASN_INTEGER, 1, NULL, 0,
0);

int i =0;
long int idx = 0;
long int col2 = 0;
long int col3 = 0;
for (i=0; i<MAX_NUM_ROW; i++)
{
row[i] = netsnmp_create_table_data_row();
idx = i;
netsnmp_table_row_add_index(row[i], ASN_INTEGER, &idx, sizeof(idx));
col2 = interfaceCountStruct[i].Rx;
netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTRX,
ASN_INTEGER, &col2, sizeof(col2));
//netsnmp_mark_row_column_writable(row[i], 2, 1);
col3 = interfaceCountStruct[i].Tx;
netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTTX,
ASN_INTEGER, &col3, sizeof(col3));
//netsnmp_mark_row_column_writable(row[i], 3, 1);
netsnmp_table_dataset_add_row(table_set, row[i]);
}

netsnmp_register_table_data_set(netsnmp_create_handler_registration
("InterfaceCountTable", netsnmp_table_array_helper_handler,
my_registration_oid,
OID_LENGTH(my_registration_oid),
HANDLER_CAN_RWRITE), table_set, NULL);
}
}


netsnmp_table_array_helper_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *agtreq_info,
netsnmp_request_info *requests)
{
int rc = SNMP_ERR_NOERROR;
int i =0;

switch (agtreq_info->mode) {
case MODE_GET:
case MODE_GETBULK:
case MODE_GETNEXT:
{
for (i=0; i<MAX_NUM_ROW; i++)
{
netsnmp_table_dataset_remove_and_delete_row(table_set, row[i]);
}

long int idx = 0;
long int col2 = 0;
long int col3 = 0;

for (i=0; i<MAX_NUM_ROW; i++)
{
row[i] = netsnmp_create_table_data_row();
idx = interfaceCountStruct[i].idx;
netsnmp_table_row_add_index(row[i], ASN_INTEGER, &idx, sizeof(idx));
col2 = interfaceCountStruct[i].Rx;
netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTRX,
ASN_INTEGER, &col2, sizeof(col2));
//netsnmp_mark_row_column_writable(row[i], 2, 1);
col3 = interfaceCountStruct[i].Tx;
netsnmp_set_row_column(row[i], COLUMN_INTERFACECOUNTTX,
ASN_INTEGER, &col3, sizeof(col3));
//netsnmp_mark_row_column_writable(row[i], 3, 1);
netsnmp_table_dataset_add_row(table_set, row[i]);
}

}
break;

default:
return SNMP_ERR_GENERR;
}

return rc;
}

请让我知道您是否可以改进它。

关于c - net-snmp mib 模块处理程序/回调示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30246502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com