[AGENT++] Multiple SNMP agents in single application
Claus Klein
claus.klein at arcormail.de
Fri Mar 15 20:23:18 CET 2013
Hi Frank,
Thank for feedback. I will try to use it.
For snmp StorageTable's, I changed the templates to generate code like
that:
class NET_SNMP_EXAMPLES_MIB_DECL netSnmpHostsEntry: public StorageTable
{
public:
netSnmpHostsEntry(const NS_SNMP OctetStr& context);
virtual ~netSnmpHostsEntry();
static netSnmpHostsEntry* instance;
typedef std::map<std::string, netSnmpHostsEntry*>
netSnmpHostsEntryMap_t;
static netSnmpHostsEntryMap_t contextmap;
private:
std::string mycontext;
public:
virtual void get_request(Request*, int);
virtual int commit_set_request(Request*, int);
virtual int prepare_set_request(Request*, int&);
virtual void cleanup_set_request(Request*, int&);
virtual int undo_set_request(Request*, int&);
virtual void row_added(MibTableRow*, const Oidx&, MibTable*);
virtual void row_delete(MibTableRow*, const Oidx&, MibTable*);
virtual void row_init(MibTableRow*, const Oidx&, MibTable*);
virtual void row_activated(MibTableRow*, const Oidx&,
MibTable*);
virtual void row_deactivated(MibTableRow*, const Oidx&,
MibTable*);
virtual void update(Request*);
virtual int is_transition_ok(MibTable*, MibTableRow*, const
Oidx&, int, int);
virtual void set_row(MibTableRow* r,
long p1,
const NS_SNMP OctetStr& p2,
long p3,
long p4);
//--AgentGen BEGIN=netSnmpHostsEntry
void change_notification(const Oidx& id, mib_change what);
//--AgentGen END
};
/**
* netSnmpHostsEntry
*
* "A host name mapped to an ip address"
*/
netSnmpHostsEntry* netSnmpHostsEntry::instance = 0;
netSnmpHostsEntry::netSnmpHostsEntryMap_t netSnmpHostsEntry::contextmap;
const index_info indNetSnmpHostsEntry[1] = {
{ sNMP_SYNTAX_OCTETS, FALSE, 0, 64 }
};
netSnmpHostsEntry::netSnmpHostsEntry(const NS_SNMP OctetStr& context):
StorageTable(oidNetSnmpHostsEntry, indNetSnmpHostsEntry, 1)
{
// This table object is a singleton. In order to access it use
// the static pointer netSnmpHostsEntry::instance.
instance = this;
mycontext = context.get_printable();
// add this context to the context map
contextmap[context.get_printable()] = this;
add_col(new netSnmpHostAddressType(colNetSnmpHostAddressType));
add_col(new netSnmpHostAddress(colNetSnmpHostAddress));
add_storage_col(new netSnmpHostStorage(colNetSnmpHostStorage));
add_col(new netSnmpHostRowStatus(colNetSnmpHostRowStatus));
//--AgentGen BEGIN=netSnmpHostsEntry::netSnmpHostsEntry
//NOTE: this mib supports to be instantiated multiple times with
different context
//--AgentGen END
}
netSnmpHostsEntry::~netSnmpHostsEntry()
{
//--AgentGen BEGIN=netSnmpHostsEntry::~netSnmpHostsEntry
//--AgentGen END
// clear singleton reference
netSnmpHostsEntry::instance = 0;
// erase this context from context map
contextmap.erase(mycontext);
}
#################################################
I use a static contextmap instead the static instance ptr. where I
need more than instance of that table with different context values.
What do you mean about that idea?
Regards,
Claus
On 12.03.2013, at 19:55, Frank Fock wrote:
> Hi Claus,
>
> Within the standard constructor, you cannot know the context. This
> is a limitation of
> the AGENT++ design (I solved that better with SNMP4J-Agent).
>
> Nevertheless, there is a workaround. Subclass MibLeaf with your own
> class.
> That class can be generic and with the AgenPro 'leafSuperClass'
> property
> you can then generate each class to use that super class instead of
> MibLeaf.
> The constructor of that super class then takes the context as
> additional parameter.
>
> If your code can be reorganized to use context information only at
> "runtime"
> when Requests are processed, then it would be easy to get the context
> information from the Request.
>
> Best regards,
> Frank
>
> Am 12.03.2013 06:10, schrieb Claus Klein:
>> Hi,
>>
>> there are 2 little unresolved problems with the same mib under
>> different context values.
>> How to get the context value and how to work with this static
>> instance variable:
>>
>> netSnmpExampleInteger::netSnmpExampleInteger():
>> MibLeaf(oidNetSnmpExampleInteger, READWRITE, new NS_SNMP
>> SnmpInt32(42), (VMODE_LOCKED | VMODE_DEFAULT)) {
>> // This leaf object is a singleton. In order to access it use
>> // the static pointer netSnmpExampleInteger::instance.
>> instance = this;
>> //--AgentGen BEGIN=netSnmpExampleInteger::netSnmpExampleInteger
>> //FIXME how to get mycontext?
>> //XXX if (netSnmpHostsEntry::contextmap[mycontext])
>> if (netSnmpHostsEntry::instance) {
>> // NOTE register a call of
>> netSnmpExampleInteger::change_notification()
>> netSnmpHostsEntry::instance->register_for_notifications(this);
>> }
>> //--AgentGen END
>> }
>>
>> On 08.03.2013, at 21:14, Jochen Katz wrote:
>>
>>> Hi,
>>>
>>>> I need to host the same MIB at multiple ports within a single
>>>> application.
>>>> Each hosted MIB (at a different port) will end up accessing
>>>> different data
>>>> within the application.
>>>>
>>>> Can I do this within agent++/snmp++? If so, how? I see that
>>>> instances are
>>>> used for each MIB object, so I am unsure how I can have a single
>>>> MIB that
>>>> is hosted multiple times access different data within a single
>>>> application.
>>>
>>> there can only be one instance of agent++ Mib class in an
>>> application
>>> and the same is true for other classes of agent++/snmp++.
>>>
>>> You can add your MIB objects for several contexts and then either
>>> use
>>> SNMPv3 with different contextEngineIDs or map several SNMPv1/v2c
>>> communities to the different contexts.
>>>
>>> Regards,
>>> Jochen
>>> _______________________________________________
>>> AGENTPP mailing list
>>> AGENTPP at agentpp.org
>>> http://lists.agentpp.org/mailman/listinfo/agentpp
>>
>> _______________________________________________
>> AGENTPP mailing list
>> AGENTPP at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/agentpp
>
> --
> ---
> AGENT++
> Maximilian-Kolbe-Str. 10
> 73257 Koengen, Germany
> https://agentpp.com
> Phone: +49 7024 8688230
> Fax: +49 7024 8688231
>
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp
More information about the AGENTPP
mailing list