Hello net-snmp users and fellows,
I would like to get an opnion about a doubt.
Im coding in C/C++ and using single session API … well doesn’t matter to the
core of my question…. just to inform.
I need each 30 seconds (as quickly the agent can do) to get a three distinct
MIB scalar variable value,
always the same variables, doing this inside loop.
Considering the well know and usual sequence code to do this:
sessionSingle = (void*) snmp_sess_open(session);
… error check …
puSession_p = snmp_sess_session((session_list *) sessionSingle);
… error check …
puPDU = snmp_pdu_create(SNMP_MSG_GET);
While() {
pdu = snmp_pdu_create(SNMP_MSG_GET);
snmp_add_null_var(pdu, theoid_1, theoid_1_len);
snmp_add_null_var(pdu, theoid_2, theoid_2_len);
snmp_add_null_var(pdu, theoid_3, theoid_3_len);
...
status = snmp_synch_response(ss, pdu, &response);
… Now read each variable in response
…
snmp_free_pdu(response);
}
We know that created pdu cannot be reused, otherwise it can be outside the loop.
also the response is not reusable to since snmp_synch_response alloc a new one
each time.
Taking these initial considerations,
trying to optimize the snmp_functions inside the loop I wrote:
puPDU = snmp_pdu_create(SNMP_MSG_GET);
While() {
netsnmp_pdu * cloned_pdu = snmp_clone_pdu(pdu);
snmp_add_null_var(cloned_pdu, theoid_1, theoid_1_len);
snmp_add_null_var(cloned_pdu, theoid_2, theoid_2_len);
snmp_add_null_var(cloned_pdu, theoid_3, theoid_3_len);
...
status = snmp_synch_response(session, cloned_pdu, &response);
… Now read each variable in response
…
snmp_free_pdu(response);
}
Finally my two doubts as questions for who that had the same problem or wish
to propose/discuss some alternatives:
1- I’m really optimizing something avoiding successive snmp_pdu_create() calls
inside with snmp_clone_pdu()?
2- What others/more changes optimizing same calls inside the loop can I do?
Any help or suggestions will be useful and surely appreciated!
Best regards for all!
JRFA
_______________________________________________
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