[AGENT++] Different Ways to Send Traps (Notifications)

Jean Li-Kam-Tin jean.li-kam-tin at vega.co.uk
Mon Jul 17 11:45:12 CEST 2006



Hi everyone,

There seems to be a number of different ways to send traps and I would
be really grateful if someone could advise on the relative merits of
each ?


Method 1 : Snmp::trap()
-----------------------

This appears in the snmp++/consoleExamples/snmpTraps.cpp and uses the
method ...

Snmp::trap( Pdu& pdu, const SnmpTarget& target );

1.1 I assume this method is less flexible and now obsolete ?


Method 2 : NotificationOriginator
---------------------------------

In agent++/examples/atm_mib/src/agentpp_notifytest_mib.cpp there appear
to be two mechanisms

A cold start trap is sent at start up - a NotificationOriginator is used
with a call to Mib::notify() :

Vbx* vbs = 0;
coldStartOid coldOid;
UdpAddress dest( "127.0.0.1/162" );
NotificationOriginator no;
no.add_v1_trap_destination( dest );
mib->notify( "", coldOid, vbs, 0 );

2.1. However, the other trap mechanism use agentppNotifyTestAllTypes
which is a specialisation of NotificationOriginator (see code extract
below). Why ? It is it purely for the error checking and logging ?


Method 3 : NotificationType
---------------------------

Using the AgenPro2 code generator, I get NotificationType classes such
as below :

// MyMibElemAlert inherits from NotificationType
int MyMibElemAlert::notify( const NS_SNMP OctetStr& context, Vbx* vbs,
int sz )
{
    //--AgentGen BEGIN=elemAlert::notify
    //--AgentGen END
    return Mib::instance->notify( context, oidElemAlert, vbs, sz );
}

3.1. How or where is this method NotificationType::notify() called ? Or
how does this fit into the trap mechanism ?

3.2. In the help page ./agent++/doc/html/classNotificationType.html it
says, "Typically a NotificationType uses a NotificationSender to send a
notification, trap, or inform request." Does this mean that *I* should
use a NotificationSender or does this mean that the API does it for me ?

3.3. How do I control trap destinations here ? Should I still use a
global NotificationOriginator with calls to the, say,
NotificationOriginator.add_v1_trap_destination() method ?

Thanks & regards,

Jean (<-- it's a French name)



//
------------------------------------------------------------------------
----
// from agent++/examples/atm_mib/src/agentpp_notifytest_mib.cpp
// agentppNotifyTest is a MibLeaf
int agentppNotifyTest::set(const Vbx& vb)
{
    //--AgentGen BEGIN=agentppNotifyTest::set
    long v;
    vb.get_value(v);
    switch (v) {
    case e_agentppNotifyTestAllTypes:
        send_agentppNotifyTestAllTypes();
        break;
    }
    //--AgentGen END
    return MibLeaf::set(vb);
}

// this appears to be a user-defined class method
void agentppNotifyTest::send_agentppNotifyTestAllTypes()
{
    Vbx* vbs = new Vbx[9];
    // populate the Vbx array
    agentppNotifyTestAllTypes no;
    no.generate(vbs, 9, "");
    delete[] vbs;
}

// agentppNotifyTestAllTypes inherits from NotificationOriginator
void agentppNotifyTestAllTypes::generate(Vbx* vbs, int sz, const
OctetStr& context)
{
    //--AgentGen BEGIN=agentppNotifyTestAllTypes::generate
    //--AgentGen END
    // lots of error checking and logging
    Mib::instance->notify(context, oidAgentppNotifyTestAllTypes, vbs,
0);
}

//
------------------------------------------------------------------------
----



More information about the AGENTPP mailing list