Example of configuring trap recipients?

Frank Fock Frank.Fock____t-online.de
Wed Feb 9 02:12:01 CET 2000


Hi Jeff,

you are right. My example has had a little bug. You can find the corrected
and tested version attached, including the three missing ::add_entry(...)
methods. Sorry, that I was too late ;-)

Best regards,
Frank

Jeff Stewart wrote:

> Frank,
>     In the example code you sent me for sending a trap, there are two lines that
> confuse me.  Specifically, when encoding the target UDP address:
>
> >           OctetStr address;
> >           for (int i=0; i<4; i++) {
> >                 address += addr[i];
> >           }
> >           address += addr.get_port() >> 1;
> >           address += addr.get_port() & 0x0F;
>
> Should those last two lines read as follows?:
>
> address += addr.get_port() >> 8;
> address += addr.get_port() & 0xFF;
>
> ?
>
> The latter form seems to work for me.  That fix, and browsing the code for a bit to
> figure out that the TargetAddrEntry fields belonged in fields 0,1,4, and 5
> (skipping 2 and 3 for some reason) was enough to get traps working.  Thanks for
> your help.
>
>     Jeff
-------------- next part --------------

// notification_originator.cpp

boolean NotificationOriginator::add_v1_trap_destination(const UdpAddress& addr)
{
	OctetStr name("defaultV1Trap");
	OctetStr tag("v1trap");
	OctetStr address;
	IpAddress ip(addr);
	for (int i=0; i<4; i++) {
		address += (unsigned char)ip[i];
	}
	address += (addr.get_port() >> 8);
	address += (addr.get_port() & 0x00FF);

	if (snmpTargetParamsEntry::instance->add_entry(name, // row index
						       0,    // mpModel 
						       1,    // securityModel
						       "public", // secName
						       1)) { // secLevel
	  if (snmpTargetAddrEntry::instance->
	      add_entry(name,                     // row index
			Oidx("1.3.6.1.6.1.1"),    // UDP domain
			address,                  // target address
			tag,                      // tag
			name)) {                  // params entry
	    if (snmpNotifyEntry::instance->add_entry(name, // row index 
						     tag,  // tag
						     1))   // type (trap)
		return TRUE;
	  }
	}
	return FALSE;
}

// snmp_target_mib.cpp

MibTableRow* snmpTargetParamsEntry::add_entry(const OctetStr& name,
					      const int mpModel, 
					      const int secModel, 
					      const OctetStr& secName,
					      const int secLevel)
{
	start_synch();
	Oidx index = Oidx::from_string(name, false);
	MibTableRow* r = find_index(index);
	if (r) {
		end_synch();
		return 0;
	}
	r = add_row(index);
	r->get_nth(0)->replace_value(new SnmpInt32(mpModel));
	r->get_nth(1)->replace_value(new SnmpInt32(secModel));
	r->get_nth(2)->replace_value(new OctetStr(secName));
	r->get_nth(3)->replace_value(new SnmpInt32(secLevel));
	// leave default value untouched (storage type)
	r->get_nth(5)->replace_value(new SnmpInt32(rowActive));
	end_synch();
	return r;	
}

MibTableRow* snmpTargetAddrEntry::add_entry(const OctetStr& name,
					    const Oidx& tdomain,
					    const OctetStr& taddress,
					    const OctetStr& taglist,
					    const OctetStr& params)
{
	start_synch();
	Oidx index = Oidx::from_string(name, false);
	MibTableRow* r = find_index(index);
	if (r) {
		end_synch();
		return 0;
	}
	r = add_row(index);
	r->get_nth(0)->replace_value(new Oidx(tdomain));
	r->get_nth(1)->replace_value(new OctetStr(taddress));
	// leave default values untouched (timeout and retry count)
	r->get_nth(4)->replace_value(new OctetStr(taglist));
	r->get_nth(5)->replace_value(new OctetStr(params));
	// leave default values untouched (storage type)
	r->get_nth(7)->replace_value(new SnmpInt32(rowActive));
	end_synch();
	return r;
}

// snmp_notification_mib.cpp

MibTableRow* snmpNotifyEntry::add_entry(const OctetStr& name,
					const OctetStr& tag,
					const int type)
{
	start_synch();
	Oidx index = Oidx::from_string(name, false);
	MibTableRow* r = find_index(index);
	if (r) {
		end_synch();
		return 0;
	}
	r = add_row(index);
	r->get_nth(0)->replace_value(new OctetStr(tag));
	r->get_nth(1)->replace_value(new SnmpInt32(type));
	// leave default value untouched (storage type)
	r->get_nth(3)->replace_value(new SnmpInt32(rowActive));
	end_synch();
	return r;
}



More information about the AGENTPP mailing list