本文整理了Java中org.snmp4j.Snmp.listen()
方法的一些代码示例,展示了Snmp.listen()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snmp.listen()
方法的具体详情如下:
包路径:org.snmp4j.Snmp
类名称:Snmp
方法名:listen
[英]Puts all associated transport mappings into listen mode.
[中]将所有关联的传输映射置于侦听模式。
代码示例来源:origin: com.rogueai/snmp2bean
public void initSnmp4J(TransportMapping transportMapping) throws IOException {
if (target == null) return; // no execution.. maybe throw exception
snmp4J = new Snmp(transportMapping);
snmp4J.listen();
}
代码示例来源:origin: fbacchella/jrds
@Override
public final boolean start() {
try {
snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
} catch (IOException e) {
log(Level.ERROR, e, "Discovery SNMP listener failed to start: %s", e.getMessage());
}
return true;
}
代码示例来源:origin: org.snmp4j/snmp4j-agent
/**
* Starts the agent by let it listen on the configured SNMP agent ports
* (transpot mappings).
*/
public void run() {
if (agentState < STATE_INIT_FINISHED) {
logger.fatal("Agent is run uninitialized, current state is " + agentState);
}
if (agentState == STATE_STOPPED) {
initSnmpSession();
}
try {
session.listen();
agentState = STATE_RUNNING;
} catch (IOException iox) {
logger.error(iox);
}
}
代码示例来源:origin: org.kaazing/snmp4j-agent
/**
* Starts the agent by let it listen on the configured SNMP agent ports
* (transpot mappings).
*/
public void run() {
if (agentState < STATE_INIT_FINISHED) {
logger.fatal("Agent is run uninitialized, current state is "+agentState);
}
if (agentState == STATE_STOPPED) {
initSnmpSession();
}
try {
session.listen();
agentState = STATE_RUNNING;
}
catch (IOException iox) {
logger.error(iox);
}
}
代码示例来源:origin: fbacchella/jrds
public boolean start() {
boolean started = false;
try {
snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
started = true;
} catch (IOException e) {
log(Level.ERROR, e, "SNMP UDP Transport Mapping not started: %s", e);
snmp = null;
}
return started;
}
代码示例来源:origin: org.jboss.jbossas/jboss-snmp
/**
* Start the embedded agent
*/
private void startAgent()
throws Exception
{
initRequestHandler();
initResponder();
initMessageDispatcher();
initTransportMapping();
initSession();
addUsmUsers();
session.listen();
}
代码示例来源:origin: org.mobicents.tools.snmp.adaptor/core
/**
* Start the embedded agent
*/
private void startAgent()
throws Exception
{
initRequestHandler();
initResponder();
initMessageDispatcher();
initTransportMapping();
initSession();
addUsmUsers();
session.listen();
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
public void registerForTraps(TrapNotificationListener listener, TrapProcessorFactory processorFactory, int snmpTrapPort) throws IOException {
RegistrationInfo info = new RegistrationInfo(listener, snmpTrapPort);
Snmp4JTrapNotifier m_trapHandler = new Snmp4JTrapNotifier(listener, processorFactory);
info.setHandler(m_trapHandler);
TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress(snmpTrapPort));
info.setTransportMapping(transport);
Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(m_trapHandler);
info.setSession(snmp);
s_registrations.put(listener, info);
snmp.listen();
}
代码示例来源:origin: OpenNMS/opennms
@Override
protected void sendNextPdu(WalkerPduBuilder pduBuilder) throws SnmpException {
Snmp4JPduBuilder snmp4JPduBuilder = (Snmp4JPduBuilder)pduBuilder;
try {
if (m_session == null) {
m_session = m_agentConfig.createSnmpSession();
Snmp4JStrategy.trackSession(m_session);
m_session.listen();
}
} catch (final IOException e) {
close();
throw new SnmpException(e);
}
LOG.debug("Sending tracker pdu of size {}", snmp4JPduBuilder.getPdu().size());
try {
m_session.send(snmp4JPduBuilder.getPdu(), m_tgt, null, m_listener);
} catch (final IOException e) {
LOG.debug("Failed to send pdu of size {}", snmp4JPduBuilder.getPdu().size(), e);
close();
throw new SnmpException(e);
}
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
@Override
protected void sendNextPdu(WalkerPduBuilder pduBuilder) throws SnmpException {
Snmp4JPduBuilder snmp4JPduBuilder = (Snmp4JPduBuilder)pduBuilder;
try {
if (m_session == null) {
m_session = m_agentConfig.createSnmpSession();
Snmp4JStrategy.trackSession(m_session);
m_session.listen();
}
} catch (final IOException e) {
close();
throw new SnmpException(e);
}
LOG.debug("Sending tracker pdu of size {}", snmp4JPduBuilder.getPdu().size());
try {
m_session.send(snmp4JPduBuilder.getPdu(), m_tgt, null, m_listener);
} catch (final IOException e) {
LOG.debug("Failed to send pdu of size {}", snmp4JPduBuilder.getPdu().size(), e);
close();
throw new SnmpException(e);
}
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
protected void sendNextPdu(WalkerPduBuilder pduBuilder) throws IOException {
Snmp4JPduBuilder snmp4JPduBuilder = (Snmp4JPduBuilder)pduBuilder;
if (m_session == null) {
m_session = m_agentConfig.createSnmpSession();
m_session.listen();
}
if (log().isDebugEnabled()) {
log().debug("Sending tracker pdu of size "+snmp4JPduBuilder.getPdu().size());
}
m_session.send(snmp4JPduBuilder.getPdu(), m_tgt, null, m_listener);
}
代码示例来源:origin: org.jboss.jbossas/jboss-snmp
snmp.listen();
log.debug("listening on: "+address);
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
public void start () throws IOException
{
this.address = GenericAddress.parse ( this.connectionInformation.getAddress () );
this.transport = new DefaultUdpTransportMapping ();
this.snmp = new Snmp ( this.transport );
//MPv3 mpv3 = (MPv3)_snmp.getMessageProcessingModel ( MessageProcessingModel.MPv3 );
final USM usm = new USM ( SecurityProtocols.getInstance (), new OctetString ( MPv3.createLocalEngineID () ), 0 );
SecurityModels.getInstance ().addSecurityModel ( usm );
this.snmp.listen ();
}
代码示例来源:origin: org.jboss.jbossas/jboss-snmp
private Snmp createSnmpSession(Address address) throws IOException {
AbstractTransportMapping transport;
if (address instanceof TcpAddress) {
transport = new DefaultTcpTransportMapping();
} else {
transport = new DefaultUdpTransportMapping();
}
// Could save some CPU cycles:
// transport.setAsyncMsgProcessingSupported(false);
MessageDispatcherImpl dispatcher = new MessageDispatcherImpl();
Snmp snmp = new Snmp(dispatcher, transport);
OctetString localEngineID= new OctetString(MPv3.createLocalEngineID());
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
MPv3 mpv3 = new MPv3(usm);
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
snmp.listen();
return snmp;
}
代码示例来源:origin: org.mobicents.tools.snmp.adaptor/core
private Snmp createSnmpSession(Address address) throws IOException {
AbstractTransportMapping transport;
if (address instanceof TcpAddress) {
transport = new DefaultTcpTransportMapping();
} else {
transport = new DefaultUdpTransportMapping();
}
// Could save some CPU cycles:
// transport.setAsyncMsgProcessingSupported(false);
MessageDispatcherImpl dispatcher = new MessageDispatcherImpl();
Snmp snmp = new Snmp(dispatcher, transport);
OctetString localEngineID= new OctetString(MPv3.createLocalEngineID());
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
MPv3 mpv3 = new MPv3(usm);
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
snmp.listen();
return snmp;
}
代码示例来源:origin: OpenNMS/opennms
public void testWalkSystem() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
TableUtils walker = new TableUtils(snmp, new DefaultPDUFactory());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
// Implements snmp4j API
@SuppressWarnings("rawtypes")
List results = walker.getTable(target, new OID[] {new OID("1.3.6.1.2.1.1")}, null, null);
assertNotNull(results);
assertFalse(results.isEmpty());
assertTrue(results.get(results.size()-1) instanceof TableEvent);
TableEvent lastEvent = (TableEvent)results.get(results.size()-1);
MockUtil.println("Status of lastEvent is "+lastEvent.getStatus());
assertEquals(TableEvent.STATUS_OK, lastEvent.getStatus());
}
代码示例来源:origin: org.kaazing/snmp4j
private void init() throws UnknownHostException, IOException {
threadPool = ThreadPool.create("Trap", 2);
dispatcher =
new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
listenAddress =
GenericAddress.parse(System.getProperty("snmp4j.listenAddress",
"udp:0.0.0.0/162"));
TransportMapping transport;
if (listenAddress instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
}
else {
transport = new DefaultTcpTransportMapping((TcpAddress)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();
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j
private void init() throws IOException {
threadPool = ThreadPool.create("Trap", 2);
dispatcher =
new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
listenAddress =
GenericAddress.parse(System.getProperty("snmp4j.listenAddress",
"udp:0.0.0.0/162"));
TransportMapping<? extends Address> transport;
if (listenAddress instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
}
else {
transport = new DefaultTcpTransportMapping((TcpAddress)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();
}
代码示例来源:origin: OpenNMS/opennms
public void testGetSysName() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
PDUv1 getRequest = new PDUv1();
getRequest.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
ResponseEvent e = snmp.get(getRequest, target);
PDU response = e.getResponse();
assertEquals(new OctetString("mockhost"), response.get(0).getVariable());
}
代码示例来源:origin: com.rogueai/snmp2bean
private void init() throws UnknownHostException, IOException {
//create thread pool
threadPool = ThreadPool.create("Trap Receiver ThreadPool", poolSize);
//create dispatcher
dispatcher = new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
//create transport
Address address = GenericAddress.parse(this.listenAddress);
TransportMapping transport = null;
if (address instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping((UdpAddress) address);
} else {
transport = new DefaultTcpTransportMapping((TcpAddress) address);
}
//create snmp
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();
}
内容来源于网络,如有侵权,请联系作者删除!