Refine search
TransportMapping transMap = new DefaultUdpTransportMapping(); snmp = new Snmp( transMap ); transMap.listen(); target.setCommunity( new OctetString( community ) ); target.setVersion( SnmpConstants.version1 ); target.setAddress( udpAddress ); pdu1.setSpecificTrap( PDUv1.ENTERPRISE_SPECIFIC ); pdu1.setEnterprise( new OID( Oid ) ); pdu1.add( new VariableBinding( new OID( Oid ), new OctetString( messageString ) ) ); response = snmp.send( pdu1, target ); new OctetString( passPhrase ) ); USM usm = snmp.getUSM();
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 (); }
/** * 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 static void set(String []oids){ PDU pdu = new PDU(); for (int i = 1; i < oids.length; i+=2){ pdu.add(new VariableBinding(new OID(oids[i]), new OctetString(oids[i+1]))); target.setCommunity(new OctetString("private")); target.setVersion(SnmpConstants.version2c); Address targetAddress = GenericAddress.parse("udp:127.0.0.1/1161"); target.setTimeout(1000); try{ DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); transport.listen(); Snmp snmp = new Snmp(transport); long t1 = System.currentTimeMillis(); System.out.println("SENDING: "+t1); System.out.println("PDU: " + pdu); ResponseEvent responseEvent = snmp.set(pdu, target); long t2=System.currentTimeMillis(); System.out.println("SENT: "+t2);
TransportMapping transport = new DefaultUdpTransportMapping(); transport.listen(); comtarget.setCommunity(new OctetString(community)); comtarget.setVersion(snmpVersion); comtarget.setAddress(new UdpAddress(ipAddress + "/" + port)); Variable var = new OctetString(hostName); VariableBinding varBind = new VariableBinding(oid, var); pdu.add(varBind); Snmp snmp = new Snmp(transport); ResponseEvent response = snmp.set(pdu, comtarget); LOG.info("Error: Agent Timeout... "); snmp.close(); return true;
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(); }
private Snmp createSnmpSession() throws IOException { AbstractTransportMapping transport; if (address instanceof TcpAddress) { transport = new DefaultTcpTransportMapping(); } else { transport = new DefaultUdpTransportMapping(); } // Could save some CPU cycles: // transport.setAsyncMsgProcessingSupported(false); Snmp snmp = new Snmp(transport); ((MPv3)snmp.getMessageProcessingModel(MPv3.ID)). setLocalEngineID(localEngineID.getValue()); if (version == SnmpConstants.version3) { USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, engineBootCount); SecurityModels.getInstance().addSecurityModel(usm); addUsmUser(snmp); } return snmp; }
transport = new DefaultUdpTransportMapping((UdpAddress) address); mtDispatcher.addMessageProcessingModel(new MPv3(localEngineID.getValue())); SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES()); Snmp snmp = new Snmp(mtDispatcher, transport); if (version == SnmpConstants.version3) { USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0); SecurityModels.getInstance().addSecurityModel(usm); if (authoritativeEngineID != null) { snmp.setLocalEngine(authoritativeEngineID.getValue(), 0, 0); snmp.addCommandResponder(this);
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); }
try { if (transport != null) { transport.close(); transport = null; snmp.close(); snmp = null; transport = new DefaultUdpTransportMapping(address); target.setCommunity(new OctetString(SnmpBinding.community)); snmp = new Snmp(transport); transport.listen(); logger.debug("SNMP binding is listening on " + address); } catch (IOException ioe) {
@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); } }
transport = new DefaultUdpTransportMapping(); if (version == SnmpConstants.version3) { snmp = new Snmp(transport); .getMessageProcessingModel(MessageProcessingModel.MPv3)) .createLocalEngineID(); USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(localEngineID), 0); SecurityModels.getInstance().addSecurityModel(usm); snmp.setLocalEngine(localEngineID, 0, 0); snmp.getUSM().addUser(new OctetString(username), user); trap_transport = new DefaultUdpTransportMapping(trapUdpAddress);
Snmp snmp; try { OctetString community1 = new OctetString(community); host = host + "/" + "161"; final Address tempHost = new UdpAddress(host); TransportMapping transport = new DefaultUdpTransportMapping(); transport.listen(); CommunityTarget comtarget = new CommunityTarget(); pdu.add(new VariableBinding(new OID(strOID))); pdu.setType(PDU.GET); snmp = new Snmp(transport); response = snmp.get(pdu, comtarget); if (response != null) { if (response.getResponse().getErrorStatusText().equalsIgnoreCase("Success")) { LOG.info("Looks like a TimeOut occured "); snmp.close(); } catch (Exception e) { throw new RuntimeException(e);
@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; }
transport = new DefaultTcpTransportMapping((TcpAddress) address); } else { transport = new DefaultUdpTransportMapping((UdpAddress) address); target.setCommunity(new OctetString("public")); Snmp snmp = new Snmp(mDispathcher, transport); snmp.addCommandResponder(this);
if (rsu.getRsuUsername() != null) { target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV); target.setSecurityName(new OctetString(rsu.getRsuUsername())); } else { target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); transport = new DefaultUdpTransportMapping(); } catch (IOException e) { throw new IOException("Failed to create UDP transport mapping: {}", e); snmp = new Snmp(transport); USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); if (rsu.getRsuUsername() != null) { snmp.getUSM().addUser(new OctetString(rsu.getRsuUsername()), new UsmUser(new OctetString(rsu.getRsuUsername()), AuthSHA.ID, new OctetString(rsu.getRsuPassword()), null, null));
final DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(udpAddress, true); transport.setReceiveBufferSize(Integer.MAX_VALUE); LOG.debug("Actual receive buffer size is {}", transport.getReceiveBufferSize()); Snmp snmp = new Snmp(transport); Snmp4JStrategy.trackSession(snmp); snmp.addCommandResponder(trapNotifier); snmp.getUSM().addUser(agentConfig.getSecurityName(), usmUser);
TransportMapping transport; if (listenAddress instanceof UdpAddress) { transport = new DefaultUdpTransportMapping( (UdpAddress) listenAddress); } else { target.setCommunity(new OctetString("public")); snmp.getUSM().addUser( new OctetString("MD5DES"), new UsmUser(new OctetString("saikrishna"), AuthMD5.ID, new OctetString("saikrishnapassword"), PrivDES.ID, new OctetString("PasswordUser"))); snmp.addCommandResponder(this);
public void run() { try { socket.setSoTimeout(getSocketTimeout()); if (receiveBufferSize > 0) { socket.setReceiveBufferSize(Math.max(receiveBufferSize, getAddress() + " is set to: " + socket.getReceiveBufferSize()); setSocketTimeout(0); packet.getPort()+ " with length "+packet.getLength()+": "+ new OctetString(packet.getData(), 0, packet.getLength()).toHexString()); if (isAsyncMsgProcessingSupported()) { byte[] bytes = new byte[packet.getLength()]; System.arraycopy(packet.getData(), 0, bytes, 0, bytes.length); bis = ByteBuffer.wrap(packet.getData()); fireProcessMessage(new UdpAddress(packet.getAddress(), packet.getPort()), bis);
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()); } }