private void test() { boolean testOK = false; String errMsg = null; String hostname = transMeta.environmentSubstitute( wServerName.getText() ); int nrPort = Const.toInt( transMeta.environmentSubstitute( "" + wPort.getText() ), SyslogDefs.DEFAULT_PORT ); try { UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort ); UserTarget usertarget = new UserTarget(); usertarget.setAddress( udpAddress ); testOK = usertarget.getAddress().isValid(); if ( !testOK ) { errMsg = BaseMessages.getString( PKG, "SyslogMessageDialog.CanNotGetAddress", hostname ); } } catch ( Exception e ) { errMsg = e.getMessage(); } if ( testOK ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION ); mb.setMessage( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.OK", hostname ) + Const.CR ); mb.setText( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.Title.Ok" ) ); mb.open(); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.NOK.ConnectionBad", hostname ) + Const.CR + errMsg + Const.CR ); mb.setText( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.Title.Bad" ) ); mb.open(); } }
private void test() { boolean testOK = false; String errMsg = null; String hostname = jobMeta.environmentSubstitute( wServerName.getText() ); int nrPort = Const.toInt( jobMeta.environmentSubstitute( "" + wPort.getText() ), SyslogDefs.DEFAULT_PORT ); try { UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort ); UserTarget usertarget = new UserTarget(); usertarget.setAddress( udpAddress ); testOK = usertarget.getAddress().isValid(); if ( !testOK ) { errMsg = BaseMessages.getString( PKG, "JobEntrySyslog.CanNotGetAddress", hostname ); } } catch ( Exception e ) { errMsg = e.getMessage(); } if ( testOK ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION ); mb.setMessage( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.OK", hostname ) + Const.CR ); mb.setText( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.Title.Ok" ) ); mb.open(); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.NOK.ConnectionBad", hostname ) + Const.CR + errMsg + Const.CR ); mb.setText( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.Title.Bad" ) ); mb.open(); } }
private void test() { boolean testOK = false; String errMsg = null; String hostname = jobMeta.environmentSubstitute( wServerName.getText() ); int nrPort = Const.toInt( jobMeta.environmentSubstitute( "" + wPort.getText() ), JobEntrySNMPTrap.DEFAULT_PORT ); try { UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort ); UserTarget usertarget = new UserTarget(); usertarget.setAddress( udpAddress ); testOK = usertarget.getAddress().isValid(); if ( !testOK ) { errMsg = BaseMessages.getString( PKG, "JobSNMPTrap.CanNotGetAddress", hostname ); } } catch ( Exception e ) { errMsg = e.getMessage(); } if ( testOK ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION ); mb.setMessage( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.OK", hostname ) + Const.CR ); mb.setText( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.Title.Ok" ) ); mb.open(); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.NOK.ConnectionBad", hostname ) + Const.CR + errMsg + Const.CR ); mb.setText( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.Title.Bad" ) ); mb.open(); } }
snmp = new Snmp( transMap ); UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( servername ), nrPort ); ResponseEvent response = null; if ( targettype.equals( target_type_Code[0] ) ) {
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()); } }
result.setAddress(new UdpAddress(context.getProperty(HOST).getValue() + "/" + context.getProperty(PORT).getValue())); result.setRetries(context.getProperty(SNMP_RETRIES).asInteger()); result.setTimeout(context.getProperty(SNMP_TIMEOUT).asInteger());
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); }
/** * This method converts an InetAddress to an implementation of an SNMP4J Address * (UdpAddress or TcpAddress) * * TODO: This needs to be updated when the protocol flag is added to the SNMP Config * so that UDP or TCP can be used in v3 operations. */ public static Address convertAddress(InetAddress address, int port) { String transportAddress = address.getHostAddress(); transportAddress += "/" + port; return new UdpAddress(transportAddress); }
/** * Creates a UDP transport with an arbitrary local port on all local * interfaces. * * @throws IOException * if socket binding fails. */ public DefaultUdpTransportMapping() throws IOException { super(new UdpAddress("0.0.0.0/0")); socket = new DatagramSocket(udpAddress.getPort()); }
public static Address parse(String address) { UdpAddress a = new UdpAddress(); if (a.parseAddress(address)) { return a; } return null; }
public static Address parse(String address) { try { UdpAddress a = new UdpAddress(); if (a.parseAddress(address)) { return a; } } catch (Exception ex) { } return null; }
public static Address parse(String address) { try { UdpAddress a = new UdpAddress(); if (a.parseAddress(address)) { return a; } } catch (Exception ex) { } return null; }
public static Address parse(String address) { UdpAddress a = new UdpAddress(); if (a.parseAddress(address)) { return a; } return null; }
/** * Creates a UDP transport with an arbitrary local port on all local * interfaces. * * @throws IOException * if socket binding fails. */ public DefaultUdpTransportMapping() throws IOException { super(new UdpAddress(InetAddress.getLocalHost(), 0)); socket = new DatagramSocket(udpAddress.getPort()); }
/** {@inheritDoc} */ @Override public void doSetParameters(Map<String, String> conParams) { int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161); this.udpAddress = new UdpAddress(conParams.get("ipAddress")+"/"+destinationPort); this.ver3Username = conParams.get("ver3Username"); this.ver3AuthPasscode = conParams.get("ver3AuthPasscode"); this.authenticationProtocol = conParams.get("authenticationProtocol"); this.privacyProtocol = conParams.get("privacyProtocol"); this.privacyProtocolPassShare = conParams.get("privacyProtocolPassShare"); setVer3Mode(conParams.get("ver3mode")); }
/** * Creates a default UDP transport mapping with the server for incoming * messages disabled. * * @throws UnknownHostException if the local host cannot be determined. */ public DTLSTM() throws IOException { super(new UdpAddress(InetAddress.getLocalHost(), 0)); this.counterSupport = CounterSupport.getInstance(); super.maxInboundMessageSize = MAX_TLS_PAYLOAD_SIZE; setSocketTimeout(DEFAULT_SOCKET_TIMEOUT); }
@Override public UdpAddress getListenAddress() { UdpAddress actualListenAddress = null; DatagramSocket socketCopy = socket; if (socketCopy != null) { actualListenAddress = new UdpAddress(socketCopy.getLocalAddress(), socketCopy.getLocalPort()); } return actualListenAddress; }
@Override public UdpAddress getListenAddress() { UdpAddress actualListenAddress = null; DatagramSocket socketCopy = socket; if (socketCopy != null) { actualListenAddress = new UdpAddress(socketCopy.getLocalAddress(), socketCopy.getLocalPort()); } return actualListenAddress; }
private Target makeSnmpTarget(HttpServletRequest request) throws UnknownHostException { String hostname = request.getParameter("host"); String community = request.getParameter("discoverSnmpCommunity"); if(community == null) { community = "public"; } int port = jrds.Util.parseStringNumber(request.getParameter("discoverSnmpPort"), 161); IpAddress addr = new UdpAddress(InetAddress.getByName(hostname), port); Target hosttarget = new CommunityTarget(addr, new OctetString(community)); hosttarget.setVersion(SnmpConstants.version2c); return hosttarget; }
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(); }