Update: 

Running: snmpget -v2c -c public localhost 1.3.6.1.4.1.49463.1.3.40.0 


This is the frequency my handle_snmp and delayed_response gets called. 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
delayed_response 
handle_snmp 
handle_snmp 
handle_snmp 
delayed_response 
delayed_response 
handle_snmp 
delayed_response 
delayed_response 
delayed_response 
handle_snmp 
delayed_response 
delayed_response 
delayed_response 
delayed_response 
delayed_response 



The response are sent to the requester(snmpget) at line 7(the first 
delayed_response). Why does both the handler method and my delayed callback get 
called so many times. Delayed time is set to 3 seconds. If I also sends two 
snmpget at the same time, this output gets jumbled for each call. Is there a 
way to have some sort of synchronization on the handler. Can I have new calls 
to wait until the current one has been dispatched? 




/Sverre 

----- Original Message -----

Fra: "Sverre Moe" <[email protected]> 
Til: [email protected] 
Sendt: 30. oktober 2012 15:01:19 
Emne: Delayed response 



Is registering an Net-SNMP alarm the only way to delay a response? 



I don't need to delay for a given amount of time, but until a signal is 
received (sigc signal). Anyway I could do that? 


If not, the only possible way I see to get around this is to use an alarm with 
a timeout delay. Wait for 5-10 seconds, check if signal is received and data 
ready and then send it to the requester, if not send error 
SNMP_ERR_RESOURCEUNAVAILABLE . 




My code for the delayed handler. I doesn't work if I keep the 
snmp_alarm_register inside the for-loop. Why is that? It will fail on the line 
with " if (!cache) { ". 
Also, somehow handle_snmp gets called 4 times when delayed 1 second, 9 times 
for 2 seconds, 14 times for 3 seconds. I can't have that. Inside my 
if-statement in the for-loop I call my device to get the information for the 
request, I cannot call this so many times for one only request. 



[CODE] 

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; 
map<oid_wrapper, scalar>::iterator scalar_iterator; 
for (scalar_iterator = scalars.begin(); 
scalar_iterator != scalars.end(); 
scalar_iterator++) { 
const oid_wrapper oid_wrapper = (*scalar_iterator).first; 
const scalar _scalar = (*scalar_iterator).second; 

const oid* oid_value = oid_wrapper.get_oid(); 
const int oid_length = oid_wrapper.get_length(); 
if (netsnmp_oid_equals(oid_value, oid_length, request_oid, oid_length) == 0) { 
cout << "We got here..." << endl; 

requests->delegated = 1; 
snmp_alarm_register(1, 
0, 
delayed_response, 
(void *) 
netsnmp_create_delegated_cache(handler, 
reginfo, 
reqinfo, 
requests, 
NULL)); 
} else { 
netsnmp_set_request_error(reqinfo, 
requests, 
SNMP_ERR_RESOURCEUNAVAILABLE); 
} 
} 

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; 
cache = netsnmp_handler_check_cache(cache); 

if (!cache) { 
snmp_log(LOG_ERR, "illegal call to return delayed response\n"); 
return; 
} 

reqinfo = cache->reqinfo; 
requests = cache->requests; 

void* datapointer; 
char buffer[2048]; 
int dataint; 
int length = 0; 
u_char type; 

strcpy(buffer, "Testing delayed SNMP"); 
datapointer = buffer; 
length = strlen(buffer); 
type = ASN_OCTET_STR; 

requests->delegated = 0; 
switch(reqinfo->mode) { 
case MODE_GET: 
snmp_set_var_typed_value(requests->requestvb, 
type, 
datapointer, 
length); 
break; 

default: 
snmp_log(LOG_ERR, "unknown mode (%d) in delayed_response\n", reqinfo->mode ); 
} 

netsnmp_free_delegated_cache(cache); 
} 

[/CODE] 


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. 



------------------------------------------------------------------------------ 
Everyone hates slow websites. So do we. 
Make your web apps faster with AppDynamics 
Download AppDynamics Lite for free today: 
http://p.sf.net/sfu/appdyn_sfd2d_oct 
_______________________________________________ 
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 



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.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
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

Reply via email to