Dear All
I am running net-snmp 5.4 on 64 bit RHEL 4.0.
I have split my subagent in to two subagents (netman and trapman) now.
One subagebt (netman) is just doing Get/Set operations.
The Other subagent (trapman) is doing only sending traps. I did not register
for any get/set variables in this process. But, I am calling
agent_check_and_process() to make connection with the snmpd in this process as
well in one thread which will probably just maintain the connection with the
snmpd as there is no registration for any get/set. The other thread will
receive IPC messages and will be sending traps. This looks to be wrong some
how. I still have the threads as I had to maintain connections with the snmpd
and receive internal messages on the IPC.
I am still using send_v2trap function to send the trap.
1. Can I get away with out calling the agent_check_and_process and just create
connection before I start the code in the other thread (not as a thread).
OR
2. Is there a way to directly send the traps to the Management device with out
going through the snmpd. I think that would be better for me as I am seeing
crashes of trapman in case high volume of traps. This (high volume) could
happen in our system in the real time.
With this idea I have created some code, but this does not work.
---------------------------------------------------------------------------------------------
a. Create snmp pdu
b. added sysuptime
c. added variables to the pdu
pdu->variables = varlist
d. called snmp_sess_send - Not sure whether this sends the pdu to the Manager
or to the snmpd?
----------------------------------
The code is as follows:
int sendTrapToNME(netsnmp_variable_list * vars)
{
netsnmp_pdu *template_v1pdu;
netsnmp_pdu *template_v2pdu;
netsnmp_variable_list *vblist = NULL;
netsnmp_variable_list *trap_vb;
netsnmp_variable_list *var;
in_addr_t *pdu_in_addr_t;
u_long uptime;
oid sysuptime_oid[] = { SNMP_OID_MIB2, 1, 3, 0 };
size_t sysuptime_oid_len = OID_LENGTH(sysuptime_oid);
oid snmptrap_oid[] = { SNMPV2_TRAP_OBJS_PREFIX, 1, 0 };
size_t snmptrap_oid_len = OID_LENGTH(snmptrap_oid);
oid snmptrapenterprise_oid[] = { SNMPV2_TRAP_OBJS_PREFIX, 3, 0 };
size_t snmptrapenterprise_oid_len = OID_LENGTH(snmptrapenterprise_oid);
oid trap_version_id[] = { SYSTEM_MIB };
oid trap_prefix[] = { SNMPV2_TRAPS_PREFIX };
if (vars == NULL)
{
printf("Can not send the trap\n");
return 0;
}
if (vars) {
vblist = snmp_clone_varbind( vars );
if (!vblist) {
snmp_log(LOG_WARNING,
"send_trap: failed to clone varbind list\n");
return -1;
}
}
template_v2pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
if (!template_v2pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to construct v2 template PDU\n");
snmp_free_varbind(vblist);
return -1;
}
/*
* Check the varbind list we've been given.
* If it starts with a 'sysUptime.0' varbind, then use that.
* Otherwise, prepend a suitable 'sysUptime.0' varbind.
*/
if (!snmp_oid_compare( vblist->name, vblist->name_length,
sysuptime_oid, sysuptime_oid_len )) {
template_v2pdu->variables = vblist;
trap_vb = vblist->next_variable;
} else {
uptime = netsnmp_get_agent_uptime();
var = NULL;
snmp_varlist_add_variable( &var,
sysuptime_oid, sysuptime_oid_len,
ASN_TIMETICKS, (u_char*)&uptime, sizeof(uptime));
if (!var) {
snmp_log(LOG_WARNING,
"send_trap: failed to insert sysUptime varbind\n");
snmp_free_pdu(template_v2pdu);
snmp_free_varbind(vblist);
return -1;
}
template_v2pdu->variables = var;
var->next_variable = vblist;
trap_vb = vblist;
}
/*
* 'trap_vb' should point to the snmpTrapOID.0 varbind,
* identifying the requested trap. If not then bomb out.
* If it's a 'standard' trap, then we need to append an
* snmpEnterprise varbind (if there isn't already one).
*/
if (!trap_vb ||
snmp_oid_compare(trap_vb->name, trap_vb->name_length,
snmptrap_oid, snmptrap_oid_len)) {
snmp_log(LOG_WARNING,
"send_trap: no v2 trapOID varbind provided\n");
snmp_free_pdu(template_v2pdu);
return -1;
}
if (!snmp_oid_compare(vblist->val.objid, OID_LENGTH(trap_prefix),
trap_prefix, OID_LENGTH(trap_prefix))) {
var = find_varbind_in_list( template_v2pdu->variables,
snmptrapenterprise_oid,
snmptrapenterprise_oid_len);
if (!var &&
!snmp_varlist_add_variable( &(template_v2pdu->variables),
snmptrapenterprise_oid, snmptrapenterprise_oid_len,
ASN_OBJECT_ID,
(u_char*)trap_version_id,
OID_LENGTH(trap_version_id)*sizeof(oid))) {
snmp_log(LOG_WARNING,
"send_trap: failed to add snmpEnterprise to v2 trap\n");
snmp_free_pdu(template_v2pdu);
return -1;
}
}
/*
* If everything's OK, convert the v2 template into an SNMPv1 trap PDU.
*/
template_v1pdu = convert_v2pdu_to_v1( template_v2pdu );
if (!template_v1pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to convert v2->v1 template PDU\n");
snmp_free_pdu(template_v2pdu);
return -1;
}
/*
* Ensure that the v1 trap PDU includes the local IP address
*/
pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;
*pdu_in_addr_t = get_myaddr();
/*
* Now loop through the list of trap sinks
* and call the trap callback routines,
* providing an appropriately formatted PDU in each case
*/
template_v2pdu->command = SNMP_MSG_TRAP2;
template_v2pdu->version = SNMP_VERSION_2c;
netsnmp_pdu *pdu = snmp_clone_pdu(template_v2pdu);
// Not sure of this pdu->sessid = sess->sessid; /* AgentX only ? */
// Not sure of this pdu->sessid = sess->sessid; /* AgentX only ? */
int result = snmp_sess_send(&gNetsnmpSession, pdu);
if (result == 0) {
snmp_sess_perror("snmpd: send_trap", &gNetsnmpSession);
snmp_free_pdu(pdu);
} else {
snmp_increment_statistic(STAT_SNMPOUTTRAPS);
snmp_increment_statistic(STAT_SNMPOUTPKTS);
}
// Not sure of the following
//snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
// SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
snmp_free_pdu(template_v2pdu);
return 0;
}
I have copied code from the
Any help is greatly appreciated.
Thanks
Reddy
Dave Shield <[EMAIL PROTECTED]> wrote: On 04/01/07, Venkata Guddeti wrote:
> 1. Can I create two subagent processes on the same machine. One for
> processing get/set and the other for sending the traps.
That is likely to be the safest approach.
As explained in README.thread, the agent code is not thread-safe, so
having two threads (one sending traps and one handling GET/SET requests)
is unlikely to work reliably. We've also had reports of problems with
high-volume subagent trap generation - though that's tended to be as a
result of deadlock with GET handling.
The bottom line is that multiple subagents should *not* be run as separate
threads of the same basic process. Separating the two tasks into two
completely separate processes feels much the safest approach.
> 2. Integrate my code that does get/set into snmpd and create another process
> to send traps based on the triggers received from outside.
That should work too.
Dave
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders