Regular snmpget works perfectly with my SNMP AgentX, but I'm having some
problems with snmpwalk. I have searched through the mailing list, nothing so
far. Will try to refine my search there, but in the mean time I wanted to ask
here.
The following code is my handler function and my alarm callback function.My
scalars are for now just read-only, so I have not made a switch for different
modes.
A simple explanation on how it works:
1. Query the device for its information on this OID if not done so on a
previous request.
2. Checking my cache if it has the information for this request. Set the
value it if is has, or register an alarm to wait for the information.
3. Callback checks the cache for the information. Set the value if found,
or set an error.
Snmpwalk for OID: 1.3.6.1.4.1.49463.2.1.9.1
After it is finished with all scalars under this OID it continues to the next
subtree, which is 1.3.6.1.4.1.49463.2.1.10 and beyond......to the end.
The command snmpwalk returns "Timeout: No Response from localhost" while my
agent still continues walking. My logging from SNMP pours out messages of
"registering pdu failed: ###!"
After a while it settles down and I can begin query the agent again. What am I
missing from my code to make it stop the snmpwalk?
int
handle_snmp(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
const oid* request_oid = (*reginfo).rootoid;
const size_t request_oid_length = (*reginfo).rootoid_len - 1; //removes the
trailing .0
netsnmp_delegated_cache *cache = netsnmp_create_delegated_cache(handler,
reginfo, reqinfo, requests, NULL);
oid_wrapper request_oid_wrapper(request_oid, request_oid_length);
//This single line of code is not important for SNMP. Queries the device for
information.
device.getInformationForThisScalarAndAddtoCache();
try {
void* datapointer;
char buffer[2048];
int length = 0;
u_char type;
status* _status = available_status.at(request_oid_wrapper);
const std::string value = _status->getValue();
const std::string value_type = _status->getType();
strcpy(buffer, value.c_str());
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
snmp_set_var_typed_value(cache->requests->requestvb,
type,
datapointer,
length);
} catch (std::out_of_range& e) {
//Value not found in cache. Register alarm with 2 seconds delay.
requests->delegated = 1;
snmp_alarm_register(delay_time,
0,
delayed_response,
(void *) cache);
}
return SNMP_ERR_NOERROR;
}
void
delayed_response(unsigned int clientreg, void *clientarg) {
netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) clientarg;
netsnmp_request_info *requests;
netsnmp_agent_request_info *reqinfo;
netsnmp_handler_registration *reginfo;
cache = netsnmp_handler_check_cache(cache);
if (!cache) {
LOG4CPLUS_ERROR(logger, LOG4CPLUS_TEXT("illegal call to return delayed
response"));
return;
}
//re-establish the previous pointers we are used to having
reqinfo = cache->reqinfo;
reginfo = cache->reginfo;
requests = cache->requests;
const oid* request_oid = (*reginfo).rootoid;
const size_t request_oid_length = (*reginfo).rootoid_len; //Not sure why this
doesn't have a trailing .0
oid_wrapper request_oid_wrapper(request_oid, request_oid_length);
try {
void* datapointer;
char buffer[2048];
int length = 0;
u_char type;
status* _status = available_status.at(request_oid_wrapper);
const std::string value = _status->getValue();
const std::string value_type = _status->getType();
strcpy(buffer, value.c_str());
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
requests->delegated = 0;
snmp_set_var_typed_value(cache->requests->requestvb,
type,
datapointer,
length);
} catch (std::out_of_range& e) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
}
//free the information cache
netsnmp_free_delegated_cache(cache);
}
CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly.
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
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