const char *app_name = "snmpd";
/* master agent */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 0);//MASTER_AGENT);
/* initialize the agent library */
if (0 != init_agent(app_name))
{
printf("\nsnmp: init_agent fail.\n\n");
}
/* initialize your mib code here */
add_mibdir("/usr/local/share/snmp/mibs");
netsnmp_init_mib();
/* Test will be used to read Test.conf files. */
init_snmp("snmpd");
if (0 != init_master_agent())
{
printf("\nsnmp: init_master_agent fail.\n\n");
}
int keep_running = 1;
while (keep_running)
{
agent_check_and_process(1);/* block every 1 second */
}
/* at shutdown time */
snmp_shutdown(app_name);
shutdown_master_agent();
/* shutdown the agent library */
shutdown_agent();
snmpget -v2c -c adminhaha 192.168.130.101 system.sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = No Such Object available on this agent at this OID
编译net-snmp库,生成三个lib,加入链接,然后通过C Api实现Agent。
问题:使用查询命令获取不到值,提示Snmp No Such Object。加入-d可以看到数据是通的
snmpget -v2c -c adminhaha 192.168.130.101 system.sysUpTime.0 -d
Sending 46 bytes to UDP: [192.168.130.101]:161->[0.0.0.0]:0
0000: 30 2C 02 01 01 04 09 61 64 6D 69 6E 68 61 68 61 0,.....adminhaha
0016: A0 1C 02 04 2B 13 8A 83 02 01 00 02 01 00 30 0E ....+.........0.
0032: 30 0C 06 08 2B 06 01 02 01 01 03 00 05 00 0...+.........
Received 46 byte packet from UDP: [192.168.130.101]:161->[0.0.0.0]:48076
0000: 30 2C 02 01 01 04 09 61 64 6D 69 6E 68 61 68 61 0,.....adminhaha
0016: A2 1C 02 04 2B 13 8A 83 02 01 00 02 01 00 30 0E ....+.........0.
0032: 30 0C 06 08 2B 06 01 02 01 01 03 00 80 00 0...+.........
DISMAN-EVENT-MIB::sysUpTimeInstance = No Such Object available on this agent at this OID