/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
public SnmpHelper(String address, String community) { _target = new CommunityTarget(); _target.setCommunity(new OctetString(community)); _target.setVersion(SnmpConstants.version2c); _target.setAddress(new UdpAddress(address)); try { _snmp = new Snmp(new DefaultUdpTransportMapping()); } catch (IOException e) { _snmp = null; throw new CloudRuntimeException(" Error in crearting snmp object, " + e.getMessage()); } }
TransportMapping transMap = new DefaultUdpTransportMapping(); snmp = new Snmp( transMap );
public static void main(String[] args) throws Exception { // Create PDU 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))); // put your uptime here 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("10.101.21.32/162"); 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); }
/** {@inheritDoc} */ public TransportMapping createTransportMapping(TransportIpAddress transportIpAddress) throws IOException { return new DefaultUdpTransportMapping((UdpAddress) transportIpAddress); } }
private org.snmp4j.Snmp createSnmp() { try { // Create a new session and define it's transport. return new org.snmp4j.Snmp(new DefaultUdpTransportMapping()); } catch (IOException e) { throw new NotificationServiceException("error creating " + getClass().getName()); } }
@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; }
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; }
public SNMPProvider(String address) { try { this.address = address; TransportMapping transport = new DefaultUdpTransportMapping(); this.snmp = new Snmp(transport); transport.listen(); } catch (IOException e) { throw new RuntimeException(e); } }
private void initTransportMapping(){ this.transportMappings = new TransportMapping[1]; try{ this.transportMappings[0] = new DefaultUdpTransportMapping(new UdpAddress(this.bindAddress, this.port)); }catch(Exception e){ log.debug("Exception in initialization of Tranport Map!!"); } }
private void initTransportMapping(){ this.transportMappings = new TransportMapping[1]; try{ this.transportMappings[0] = new DefaultUdpTransportMapping(new UdpAddress(this.bindAddress, this.port)); }catch(Exception e){ log.debug("Exception in initialization of Tranport Map!!"); } }
import org.snmp4j.*; import org.snmp4j.event.*; ... CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); target.setAddress(targetAddress); target.setVersion(SnmpConstants.version2c); PDU request = new PDU(); request.setType(PDU.V2TRAP); request.setGenericTrap(PDUv2.COLDSTART); Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); snmp.listen(); snmp.sendPDU(request, target, null, listener);
@Override protected void initTransportMappings() throws IOException { this.transportMappings = new TransportMapping[1]; this.transportMappings[0] = new DefaultUdpTransportMapping( new UdpAddress(this.udpAddress)); }
/** * Initializes the transport mappings (ports) to be used by the agent. * * @throws IOException * if an IO exception occurs while initializing the default transport mapping on all local IP addresses on * port 161. */ protected void initTransportMappings() throws IOException { transportMappings = new DefaultUdpTransportMapping[]{ new DefaultUdpTransportMapping(new UdpAddress("0.0.0.0/161"))}; }
/** * Initializes the transport mappings (ports) to be used by the agent. * @throws IOException */ protected void initTransportMappings() throws IOException { transportMappings = new TransportMapping[1]; transportMappings[0] = new DefaultUdpTransportMapping(new UdpAddress("0.0.0.0/161")); }
TransportMapping transport = new DefaultUdpTransportMapping(); MessageDispatcher disp = new MessageDispatcherImpl(); disp.addMessageProcessingModel(new MPv2c()); snmp = new Snmp(disp, transport); ... snmp.listen();
@Override public synchronized void activate() throws Exception { super.activate(); // load connection data only if the endpoint is enabled if (isEnabled()) { logger.debug("Activating endpoint"); this.listenGenericAddress = GenericAddress.parse(this.address); this.transport = new DefaultUdpTransportMapping((UdpAddress) this.listenGenericAddress); this.snmp = new Snmp(transport); snmp.addCommandResponder(this); } }
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(); }
public MockProxy(int port) throws IOException { // Set socket option SO_REUSEADDR so that we can bind to the port even if it // has recently been closed by passing 'true' as the second argument here. m_transport = new DefaultUdpTransportMapping(new UdpAddress(InetAddress.getLocalHost(), port), true); m_snmp = new Snmp(m_transport); m_snmp.addCommandResponder(this); m_transport.listen(); }
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 (); }