[AGENT++] How can I add multi trap report address?

Jochen Katz katz at agentpp.com
Mon Jan 22 23:21:12 CET 2007


Hi,

> I have a question about supporting multi TRAP report address.
> It means , when the agent invoked a TRAP it is sent to multiple server.
>  
> I tried below , but it failed.
>  
> no.add_v2_trap_destination(dest1);
> no.add_v2_trap_destination(dest2);
>  
> then after I invoked a trap but only the first server received trap.

both entries will be added using the same name and tags, so only one
entry survives. Apply the patch below and provide unique values for name
and tag, then it will work.

For easy downloading of the patch: http://nopaste.biz/?11801

Regards,
  Jochen

Index: include/agent_pp/notification_originator.h
===================================================================
--- include/agent_pp/notification_originator.h  (Revision 119)
+++ include/agent_pp/notification_originator.h  (Arbeitskopie)
@@ -182,17 +182,33 @@
        /**
         * Make all necessary entries in snmpTargetAddressTable,
         * snmpTargetParamsTable, and snmpNotifyTable for the given
-        * v1 trap destination. All rows added will be named defaultV1Trap.
-        * The community used for generated traps will be public.
+        * v1, v2 or v3 trap destination.
         *
-        * @param targetAddress
-        *    an UDP address.
+        * @param addr
+        *    an UDP target address.
+        * @param name
+        *    unique name for the entries.
+        * @param tag
+        *    unique tag for the entries.
+        * @param community / secName
+        *    community / security name to use when sending traps.
         * @return
         *    TRUE if the operation has been successful, FALSE otherwise.
         */
-       virtual boolean add_v1_trap_destination(const NS_SNMP
UdpAddress& dest);
-       virtual boolean add_v2_trap_destination(const NS_SNMP
UdpAddress& addr);
-       virtual boolean add_v3_trap_destination(const NS_SNMP
UdpAddress& addr);
+       /**@{ */
+       virtual boolean add_v1_trap_destination(const NS_SNMP
UdpAddress& addr,
+                                               const NS_SNMP OctetStr
&name,
+                                               const NS_SNMP OctetStr &tag,
+                                               const NS_SNMP OctetStr
&community);
+       virtual boolean add_v2_trap_destination(const NS_SNMP
UdpAddress& addr,
+                                               const NS_SNMP OctetStr
&name,
+                                               const NS_SNMP OctetStr &tag,
+                                               const NS_SNMP OctetStr
&community);
+       virtual boolean add_v3_trap_destination(const NS_SNMP
UdpAddress& addr,
+                                               const NS_SNMP OctetStr
&name,
+                                               const NS_SNMP OctetStr &tag,
+                                               const NS_SNMP OctetStr
&secName);
+       /**@} */

 #ifdef _SNMPv3
        /**
Index: src/notification_originator.cpp
===================================================================
--- src/notification_originator.cpp     (Revision 119)
+++ src/notification_originator.cpp     (Arbeitskopie)
@@ -477,10 +477,12 @@
 }


-boolean NotificationOriginator::add_v1_trap_destination(const
UdpAddress& addr)
+boolean NotificationOriginator::add_v1_trap_destination(const
UdpAddress& addr,
+    const OctetStr &name, const OctetStr &tag, const OctetStr &community)
 {
-       OctetStr name("defaultV1Trap");
-       OctetStr tag("v1trap");
+//     OctetStr name("defaultV1Trap");
+//     OctetStr tag("v1trap");
+//      OctetStr community("public");
        OctetStr address;
        IpAddress ip(addr);
        for (int i=0; i<addr.get_length()-2; i++) {
@@ -496,7 +498,7 @@
        if (snmpTargetParamsEntry::instance->add_entry(name, // row index
                                                       0,    // mpModel
                                                       1,    //
securityModel
-                                                      "public", // secName
+                                                      community, // secName
                                                       1)) { // secLevel
            snmpNotifyEntry::instance->add_entry(name, // row index
                                                 tag,  // tag
@@ -513,10 +515,12 @@
 }


-boolean NotificationOriginator::add_v2_trap_destination(const
UdpAddress& addr)
+boolean NotificationOriginator::add_v2_trap_destination(const
UdpAddress& addr,
+    const OctetStr &name, const OctetStr &tag, const OctetStr &community)
 {
-       OctetStr name("defaultV2Trap");
-       OctetStr tag("v2trap");
+//     OctetStr name("defaultV2Trap");
+//     OctetStr tag("v2trap");
+//      OctetStr community("public");
        OctetStr address;
        IpAddress ip(addr);
        for (int i=0; i<addr.get_length()-2; i++) {
@@ -532,7 +536,7 @@
        if (snmpTargetParamsEntry::instance->add_entry(name, // row index
                                                       mpV2c,    // mpModel
                                                       SecurityModel_v2,
// securityModel
-                                                      "public", // secName
+                                                      community, // secName
                                                       1)) { // secLevel
            snmpNotifyEntry::instance->add_entry(name, // row index
                                                 tag,  // tag
@@ -548,10 +552,12 @@
        return FALSE;
 }

-boolean NotificationOriginator::add_v3_trap_destination(const
UdpAddress& addr)
+boolean NotificationOriginator::add_v3_trap_destination(const
UdpAddress& addr,
+    const OctetStr &name, const OctetStr &tag, const OctetStr &secName)
 {
-       OctetStr name("defaultV3Trap");
-       OctetStr tag("v3trap");
+//     OctetStr name("defaultV3Trap");
+//     OctetStr tag("v3trap");
+//      OctetStr secName("MD5DES");
        OctetStr address;
        IpAddress ip(addr);
        for (int i=0; i<addr.get_length()-2; i++) {
@@ -567,7 +573,7 @@
        if (snmpTargetParamsEntry::instance->add_entry(name, // row index
                                                       mpV3,    // mpModel

SecurityModel_USM, // securityModel
-                                                      "MD5DES", // secName
+                                                      secName, // secName
                                                       1)) { // secLevel
            snmpNotifyEntry::instance->add_entry(name, // row index
                                                 tag,  // tag



More information about the AGENTPP mailing list