本文整理汇总了Java中org.snmp4j.smi.UdpAddress类的典型用法代码示例。如果您正苦于以下问题:Java UdpAddress类的具体用法?Java UdpAddress怎么用?Java UdpAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UdpAddress类属于org.snmp4j.smi包,在下文中一共展示了UdpAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpTarget
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
/**
* Helper method that initializes the snmp target to listening mode. This
* method is explicitly for V1 and V2 messages. This method will create and
* set up the TransportMapping and target for SNMP V1 and V2. It creates a
* TransportMapping and puts it in the listening mode. Also Creates
* CommunityTarget object and sets SNMP target properties.
*
* @param communityName
* Community name of the target
* @param targetIP
* IP address of Target machine
* @param portNumber
* Port number
* @return The Target created
* @throws IOException
* IOException
*/
private Target setUpTarget( final String communityName, final String targetIP, final int portNumber )
throws IOException
{
final InetAddress inetAddress = InetAddress.getByName( targetIP );
final Address address = new UdpAddress( inetAddress, portNumber );
final OctetString community = new OctetString( communityName );
final TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp( transport );
snmp.listen();
// Creating the communityTarget object and setting its properties
final CommunityTarget communityTarget = new CommunityTarget();
communityTarget.setCommunity( community );
// TODO Needs to check also for v2 messages
communityTarget.setVersion( SnmpConstants.version1 );
communityTarget.setAddress( address );
// TODO Need to confirm, whether this value needs to be configures
communityTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
// TODO Need to confirm, whether this value needs to be configures
communityTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
return communityTarget;
}
示例2: main
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(new UdpAddress("23.23.52.11/161"));
target.setTimeout(3000); //3s
target.setRetries(1);
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(1);
pdu.setNonRepeaters(0);
VariableBinding[] array = {new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.7")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.10")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.19"))};
pdu.addAll(array);
//pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")));
ResponseEvent responseEvent = snmp.send(pdu, target);
PDU response = responseEvent.getResponse();
if (response == null) {
System.out.println("TimeOut...");
} else {
if (response.getErrorStatus() == PDU.noError) {
Vector<? extends VariableBinding> vbs = response.getVariableBindings();
for (VariableBinding vb : vbs) {
System.out.println(vb.getVariable().toString());
}
} else {
System.out.println("Error:" + response.getErrorStatusText());
}
}
}
示例3: newListener
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
@Override
public SnmpListener newListener(String address, int port, Mib mib) {
lock.lock();
try {
Address listenAddress = address == null ?
new UdpAddress(port) : createAddress(address, port);
Snmp4jListener listener = new Snmp4jListener(getSnmp(),
listenAddress, new Snmp4jNotificationEventFactory(
new SimpleVarbindFactory(mib)), this);
listener.open();
refs.put(listener, listener);
return listener;
}
finally {
lock.unlock();
}
}
示例4: snmpMessageToHumanReadable
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
static PDU snmpMessageToHumanReadable(String s) throws IOException {
final OctetString message = OctetString.fromHexString(s, ':');
final Address address = new UdpAddress();
final TransportMapping transportMapping = (address instanceof UdpAddress) ?
new DefaultUdpTransportMapping((UdpAddress) address)
: new DefaultTcpTransportMapping((TcpAddress) address);
final MessageDispatcher messageDispatcher = new
MessageDispatcherImpl();
SecurityProtocols.getInstance().addDefaultProtocols();
final SnmpMessageAnalyzer snmpMessageAnalyzer = new SnmpMessageAnalyzer();
final CommandResponder commandResponder = snmpMessageAnalyzer;
messageDispatcher.addCommandResponder(commandResponder);
messageDispatcher.addMessageProcessingModel(new MPv1());
messageDispatcher.addMessageProcessingModel(new MPv2c());
messageDispatcher.addMessageProcessingModel(new MPv3());
messageDispatcher.processMessage(transportMapping, address, ByteBuffer.wrap(message.getValue()));
PDU result = snmpMessageAnalyzer.msg;
snmpMessageAnalyzer.msg = null;
return result;
}
示例5: start
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
@Override
public void start() {
// Initialize the connection to the external client
try {
snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(new UdpAddress(bindAddress + "/" + bindPort));
target.setTimeout(3000); //3s
target.setRetries(1);
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(1);
pdu.setNonRepeaters(0);
} catch (IOException ex) {
//
}
super.start();
}
示例6: sendTrap
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
protected void sendTrap(String message) throws Exception {
PDU pdu = new PDU();
pdu.setType(PDU.TRAP);
add(pdu, alertName, message);
add(pdu, alertSeverity, Severity.medium);
add(pdu, alertSource, "rhq.org");
CommunityTarget target = new CommunityTarget();
target.setCommunity(community);
target.setVersion(SnmpConstants.version2c);
target.setAddress(new UdpAddress(address, port));
target.setTimeout(1000);
target.setRetries(2);
try {
snmp.send(pdu, target);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
示例7: addNotificationTargets
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
targetMIB.addDefaultTDomains();
targetMIB.addTargetAddress(new OctetString("notification"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("127.0.0.1/162").getValue()),
200, 1,
new OctetString("notify"),
new OctetString("v2c"),
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v2c"),
MessageProcessingModel.MPv2c,
SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("public"),
SecurityLevel.NOAUTH_NOPRIV,
StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("default"),
new OctetString("notify"),
SnmpNotificationMIB.SnmpNotifyTypeEnum.trap,
StorageType.permanent);
}
示例8: sendTrapV2
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
public static void sendTrapV2(String port) throws IOException {
PDU trap = new PDU();
trap.setType(PDU.TRAP);
OID oid = new OID("1.2.3.4.5");
trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));
// Add Payload
Variable var = new OctetString("some string");
trap.add(new VariableBinding(oid, var));
// Specify receiver
Address targetaddress = new UdpAddress("127.0.0.1/" + port);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(targetaddress);
// Send
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.send(trap, target, null, null);
snmp.close();
}
示例9: startUp
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
@Override
public void startUp() throws IOException {
log.info("Snmp Trap Receiver Start");
log.info("listened on " + Configure.getInstance().getUdpTrapIpPort());
ThreadPool pool = ThreadPool.create(Const.THREAD_POOL_NAME, Const.AGENT_THREAD_NUM);
MultiThreadedMessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(pool, new MessageDispatcherImpl());
Address listenAddress = GenericAddress.parse(Configure.getInstance().getUdpTrapIpPort());
TransportMapping transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
// ����SNMP������ʹ�俪ʼ����
Snmp snmp = new Snmp(dispatcher, transport);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
snmp.listen();
snmp.addCommandResponder(new CommandResponderImpl());
}
示例10: sendMessage
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
@Override
public void sendMessage(
UdpAddress address, byte[] message, TransportStateReference tmStateReference
) throws IOException {
if (!(address instanceof UdpAddress)) {
throw new IllegalArgumentException();
}
try {
node.sendSnmpMessage(
((UdpAddress)address).getInetAddress(),
((UdpAddress)address).getPort(),
message
);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
示例11: init
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
private void init() throws UnknownHostException, IOException {
threadPool = ThreadPool.create("Trap", 4);
dispatcher = new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
listenAddress = GenericAddress.parse("udp:0.0.0.0/"
+ SnmpPref.getTrapsPort());
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(
(UdpAddress) listenAddress);
snmp = new Snmp(dispatcher, transport);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.listen();
logger.debug("Listening for traps on "
+ transport.getListenAddress().toString());
}
示例12: testTrapReceiverWithoutOpenNMS
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
public void testTrapReceiverWithoutOpenNMS() throws Exception {
System.out.println("SNMP4J: Register for Traps");
trapCount = 0;
Snmp snmp = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(9162)));
snmp.addCommandResponder(this);
snmp.getUSM().addUser(
new OctetString("opennmsUser"),
new UsmUser(new OctetString("opennmsUser"), AuthMD5.ID, new OctetString("0p3nNMSv3"), PrivDES.ID, new OctetString("0p3nNMSv3")));
snmp.listen();
sendTraps();
System.out.println("SNMP4J: Unregister for Traps");
snmp.close();
System.out.println("SNMP4J: Checking Trap status");
assertEquals(2, trapCount);
}
示例13: doStart
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
super.doStart();
// load connection data only if the endpoint is enabled
if (LOG.isInfoEnabled()) {
LOG.info("Starting trap consumer on {}", this.endpoint.getAddress());
}
this.listenGenericAddress = GenericAddress.parse(this.endpoint.getAddress());
// either tcp or udp
if ("tcp".equals(endpoint.getProtocol())) {
this.transport = new DefaultTcpTransportMapping((TcpAddress)this.listenGenericAddress);
} else if ("udp".equals(endpoint.getProtocol())) {
this.transport = new DefaultUdpTransportMapping((UdpAddress)this.listenGenericAddress);
} else {
throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
}
this.snmp = new Snmp(transport);
this.snmp.addCommandResponder(this);
// listen to the transport
if (LOG.isDebugEnabled()) {
LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
this.transport.listen();
if (LOG.isInfoEnabled()) {
LOG.info("Started trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
}
示例14: prepareTarget
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
/**
* Prepares object which implements {@link org.snmp4j.Target}
*
* @param routerAddress router's IPv4 address
* @param snmpCommunity SNMP community
* @return {@link org.snmp4j.Target} object
*/
public Target prepareTarget(String routerAddress, String snmpCommunity) {
final CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(snmpCommunity));
if(!routerAddress.contains("/")) {
routerAddress += "/161";
}
target.setAddress(new UdpAddress(routerAddress));
target.setRetries(SBoxProperties.CONNECTION_RETRIES);
target.setTimeout(SBoxProperties.CONNECTION_TIMEOUT);
target.setVersion(SNMP_VERSION);
return target;
}
示例15: send
import org.snmp4j.smi.UdpAddress; //导入依赖的package包/类
public void send() throws IOException {
// Create PDU
PDU trap = new PDU();
trap.setType(PDU.TRAP);
if (this.varBinds.size() == 0) {
addDefaultTrap();
}
// Add the varbinds to the trap
for (VariableBinding vb : this.varBinds) {
trap.add(vb);
}
// Set our target
Address targetaddress = new UdpAddress(getTargetAddress());
CommunityTarget target = new CommunityTarget();
// Set the community read string
target.setCommunity(new OctetString(this.community));
// Set the version of the trap
target.setVersion(version.version);
target.setAddress(targetaddress);
LOG.info("trap: {}",trap);
// Send the trap
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.send(trap, target, null, null);
}