[AGENT++] How to add trap IP addresses?

Mr. AWD mrawd at excite.com
Wed Oct 20 23:14:53 CEST 2004


Hi there!

Thanks a lot for the extended code example. I hope that you don’t mind me asking few more question regarding the code, since I can’t follow it in a few spots. Also, I will attempt to do all of the initialization in the main() function of the main.cpp file and I am hoping that is a good spot to do so.

> // Here is a code snippet that works for me:
> // (SnmpRow is just a helper class to produce a vblist.)
> // (removeTableRow sets RowStatus to "destroy".)
>
> Vbx vbs[8]; // construct a Vb object
> int status;
> OctetStr indexstr( "myNMS" ); // identify this row
> Oidx indexoid = Oidx::from_string( indexstr, FALSE );
> SnmpPdu pdu( _target );

Here you used SnmpPdu to create “pdu” object with “_target” as an argument. First of all, I can’t find SnmpPdu class object in the SNMP++ or Agent++ code. Where is this one coming from?

Secondly, you used “_target” as an argument, and I can’t figure out what is that? There are SnmpTarget (a base class for the rest), CTarget (V1 and V2), and UTarget (V3 framework) objects in SNMP++ and I am not sure which one (if so) of those is the one you used. Further more, I am guessing that “_target” has to be created somewhere already (couldn’t see it in the main.cpp tough), so that one that needs to be used here or I could create my own?

> // Use the same index in all tables
> SnmpRow row( indexoid );
>
> // remove entries if they exist
> removeTableRow( oidSnmpNotifyRowStatus, indexoid );
> removeTableRow( oidSnmpTargetParamsRowStatus, indexoid );
> removeTableRow( oidSnmpTargetAddrRowStatus, indexoid );
>
> // New row in snmpNotifyTable
> row.add( oidSnmpNotifyTag, OctetStr( indexstr ) );
> row.add( oidSnmpNotifyType, SnmpInt32( 1 ) ); // trap(1), inform(2)
> row.add( oidSnmpNotifyStorageType, SnmpInt32( 3 ) ); // nonVolatile(3)
> row.add( oidSnmpNotifyRowStatus, SnmpInt32( 4 ) ); // createAndGo(4)
>
> pdu.set_vblist( row.vbs(), row.size() );
> status = _snmp->set( pdu, *_target->getTarget() );

Here is also “_snmp” object that I am not sure where is it coming from. My guess is that should be Snmpx object created in the main(), and since it should be only one out there…

> // New row in snmpTargetAddrTable
> row.clear();
> row.add( oidSnmpTargetAddrTDomain, Oidx( "1.3.6.1.6.1.1" ) ); // snmpUDPDomain
> row.add( oidSnmpTargetAddrStorageType, SnmpInt32( 3 ) ); // nonVolatile(3)
> row.add( oidSnmpTargetAddrRowStatus, SnmpInt32( 5 ) ); // createAndWait(5)
>
> pdu.set_vblist( row.vbs(), row.size() );
> status = _snmp->set( pdu, *_target->getTarget() );

What is the reason for the snmpTargetAddrTable to be created in two passes instead of one?

> // Complete row in snmpTargetAddrTable
> row.clear();
> // convert string ip to binary
> IpAddress ipaddr( f_ip );
> unsigned char bin_addr[] = { ipaddr[0], 
>							 ipaddr[1],
>							 ipaddr[2],
>							 ipaddr[3],
>							 (f_port>>8) & 0xff,
>							 f_port & 0xff };
>
> row.add( oidSnmpTargetAddrTDomain, Oidx( "1.3.6.1.6.1.1" ) ); // snmpUDPDomain
> row.add( oidSnmpTargetAddrTAddress, OctetStr( bin_addr, 6 ) ); //
> row.add( oidSnmpTargetAddrTimeout, SnmpInt32( 1500 ) );
> row.add( oidSnmpTargetAddrRetryCount, SnmpInt32( 3 ) );
> row.add( oidSnmpTargetAddrTagList, OctetStr( indexstr ) ); // Refer to NotifyTable
> row.add( oidSnmpTargetAddrParams, OctetStr( indexstr ) ); // Refer to TargetParamsTable
> row.add( oidSnmpTargetAddrStorageType, SnmpInt32( 3 ) ); // nonVolatile(3)
> row.add( oidSnmpTargetAddrRowStatus, SnmpInt32( 1 ) ); // active(1)
>
> pdu.set_vblist( row.vbs(), row.size() );
> status = _snmp->set( pdu, *_target->getTarget() );
>
> row.clear();

Once again thanks a lot for your help!

Fedja



_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!



More information about the AGENTPP mailing list