CommunityTarget target = new CommunityTarget(); PDUv1 pdu1 = new PDUv1(); transMap.listen();
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 = new CommunityTarget(); String community = context.getProperty(SNMP_COMMUNITY).getValue(); if(community != null) {
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); }
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);
private Target createCommunityTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(getReadCommunity()); return target; }
private Target createCommunityTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(getReadCommunity()); return target; }
private Target createCommunityTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(getReadCommunity()); return target; }
UdpAddress targetAddress = new UdpAddress("127.0.0.1/1985"); CommunityTarget target = new CommunityTarget(); //...Whatever target.setAddress(targetAddress);
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; }
private Target getTarget(String communityString) { if(version == V1 || version == V2C) { Address address = GenericAddress.parse("udp:" + ip + "/" + port); CommunityTarget target = new CommunityTarget(address, new OctetString(communityString)); target.setVersion(version); return target; } throw new RuntimeException("Snmpv3 is not supported"); } }
private Target getTargetForWrite() { CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public"));\\<--- target.setVersion(SnmpConstants.version2c); target.setAddress(GenericAddress.parse(address)); target.setRetries(2); target.setTimeout(1500); return target; }
/** * <p>getTarget.</p> * * @return a {@link org.snmp4j.Target} object. */ protected Target getTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString(snmpCommunity)); target.setAddress(this.udpAddress); target.setRetries(retries); target.setTimeout(timeout); target.setVersion(SnmpConstants.version1); return target; } /** {@inheritDoc} */
private Target getTarget() { Address targetAddress = GenericAddress.parse(address); CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); target.setAddress(targetAddress); target.setRetries(2); target.setTimeout(1500); target.setVersion(SnmpConstants.version2c); return target; }
/** * <p>getTarget.</p> * * @return a {@link org.snmp4j.Target} object. */ protected Target getTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString(snmpCommunity)); target.setAddress(this.tcpAddress); target.setRetries(retries); target.setTimeout(timeout); target.setVersion(SnmpConstants.version1); return target; } /** {@inheritDoc} */
private Target getTarget() { Address targetAddress = GenericAddress.parse(address); CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); target.setAddress(targetAddress); target.setRetries(2); target.setTimeout(1500); target.setVersion(SnmpConstants.version2c); return target; } }
private Target createTarget(Profile profile) { Target target; if (profile.version == SnmpConstants.version2c) { target = new CommunityTarget(); ((CommunityTarget) target).setCommunity(profile.community); } else { target = new UserTarget(); ((UserTarget) target).setAuthoritativeEngineID(profile.engineId.getValue()); target.setSecurityName(profile.username); target.setSecurityLevel(profile.securityLevel); } target.setVersion(profile.version); return target; }
/** * <p>getTarget.</p> * * @return a {@link org.snmp4j.Target} object. */ protected Target getTarget() { CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString(snmpCommunity)); target.setAddress(this.udpAddress); target.setRetries(retries); target.setMaxSizeRequestPDU(maxSizeRequestPDU); target.setTimeout(timeout); target.setVersion(SnmpConstants.version2c); return target; } /** {@inheritDoc} */
@Override protected void doStart() throws Exception { super.doStart(); this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); LOG.debug("targetAddress: {}", targetAddress); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(this.usm); // setting up target this.target = new CommunityTarget(); this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity())); this.target.setAddress(this.targetAddress); this.target.setRetries(this.endpoint.getRetries()); this.target.setTimeout(this.endpoint.getTimeout()); this.target.setVersion(this.endpoint.getSnmpVersion()); }
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()); }