Re: Forwarding traps from snmptrapd

Dave Shield <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
On Wed, 2006-01-11 at 11:42 +0530, [email protected] wrote:

> Can any one pls clarify whether snmptrapd can forward traps to master
> agent. 

Not currently, no.

It shouldn't be too difficult to implement.
Please find attached a suitable patch (*completely* untested!)
This should be triggered using an snmptrapd.conf entry such as:

	forward  default   agentx
or
	forward  OID       agentx

Let me know whether it works OK, and I'll look at adding this
(or something similar) to the suite.

Dave
trapd.diff (text/x-patch, 1.9 KB)
--- snmptrapd_handlers.h.cln	2006-01-11 10:02:22.093810688 +0000
+++ snmptrapd_handlers.h	2006-01-11 10:02:30.613515496 +0000
@@ -29,6 +29,7 @@
 Netsnmp_Trap_Handler   command_handler;
 Netsnmp_Trap_Handler   event_handler;
 Netsnmp_Trap_Handler   forward_handler;
+Netsnmp_Trap_Handler   axforward_handler;
 Netsnmp_Trap_Handler   notification_handler;
 
 void free_trap1_fmt(void);
--- snmptrapd_handlers.c.cln	2006-01-11 09:52:23.439819928 +0000
+++ snmptrapd_handlers.c	2006-01-11 10:04:09.739446064 +0000
@@ -122,7 +122,10 @@
     DEBUGMSGTL(("read_config:forward", "registering forward for: "));
     if (!strcmp(buf, "default")) {
         DEBUGMSG(("read_config:forward", "default"));
-        traph = netsnmp_add_default_traphandler( forward_handler );
+        if ( !strcmp( cptr, "agentx" ))
+            traph = netsnmp_add_default_traphandler( axforward_handler );
+        else
+            traph = netsnmp_add_default_traphandler( forward_handler );
     } else {
 
         if (!read_objid(buf, obuf, &olen)) {
@@ -134,7 +137,10 @@
             return;
         }
         DEBUGMSGOID(("read_config:forward", obuf, olen));
-        traph = netsnmp_add_traphandler( forward_handler, obuf, olen );
+        if ( !strcmp( cptr, "agentx" ))
+            traph = netsnmp_add_traphandler( axforward_handler, obuf, olen );
+        else
+            traph = netsnmp_add_traphandler( forward_handler, obuf, olen );
     }
 
     DEBUGMSG(("read_config:forward", "\n"));
@@ -890,6 +896,17 @@
 
 
 /*
+ *  Trap handler for forwarding to the AgentX master agent
+ */
+int axforward_handler( netsnmp_pdu           *pdu,
+                       netsnmp_transport     *transport,
+                       netsnmp_trapd_handler *handler)
+{
+    send_v2trap( pdu->variables );
+    return NETSNMPTRAPD_HANDLER_OK;
+}
+
+/*
  *  Trap handler for forwarding to another destination
  */
 int   forward_handler( netsnmp_pdu           *pdu,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.