target.setVersion( SnmpConstants.version1 ); target.setAddress( udpAddress ); if ( target.getAddress().isValid() ) {
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()); } }
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); }
/** * Default constructor. */ public CommunityTarget() { setVersion(SnmpConstants.version1); }
/** * Creates a fully specified communtity target. * @param address * the transport <code>Address</code> of the target. * @param community * the community to be used for the target. */ public CommunityTarget(Address address, OctetString community) { super(address); setVersion(SnmpConstants.version1); setCommunity(community); }
/** * Default constructor. */ public CommunityTarget() { setVersion(SnmpConstants.version1); setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); setSecurityModel(SecurityModel.SECURITY_MODEL_SNMPv1); }
/** * Default constructor. */ public CommunityTarget() { setVersion(SnmpConstants.version1); setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); setSecurityModel(SecurityModel.SECURITY_MODEL_SNMPv1); }
/** * Creates a fully specified community target. * @param address * the transport <code>Address</code> of the target. * @param community * the community to be used for the target. */ public CommunityTarget(Address address, OctetString community) { super(address, community); setVersion(SnmpConstants.version1); setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); setSecurityModel(SecurityModel.SECURITY_MODEL_SNMPv1); }
/** * Creates a fully specified community target. * @param address * the transport <code>Address</code> of the target. * @param community * the community to be used for the target. */ public CommunityTarget(Address address, OctetString community) { super(address, community); setVersion(SnmpConstants.version1); setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); setSecurityModel(SecurityModel.SECURITY_MODEL_SNMPv1); }
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"); } }
/** * <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} */
/** * <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} */
/** * <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.version2c); 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 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.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 boolean sendTrap() throws IOException{ //create PDU PDU trap = new PDU(); trap.setType(PDU.TRAP); OID oid = new OID(".1.3.6.1.3.1.1.1.36.0"); trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid)); Variable var = new OctetString("My system is in trouble"); trap.add(new VariableBinding(oid, var)); //create target Address targetaddress = new UdpAddress("localhost/162"); CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); target.setVersion(SnmpConstants.version2c); target.setAddress(targetaddress); //send trap Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); snmp.send(trap, target, null, null); return true; } }
@Override public synchronized void activate() throws Exception { super.activate(); this.targetAddress = GenericAddress.parse(this.address); this.transport = new DefaultUdpTransportMapping(); this.snmp = new Snmp(transport); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); // setting up target target = new CommunityTarget(); target.setCommunity(new OctetString(this.snmpCommunity)); target.setAddress(targetAddress); target.setRetries(this.retries); target.setTimeout(this.timeout); target.setVersion(this.snmpVersion); // creating PDU this.pdu = new PDU(); }
@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()); this.pdu = new PDU(); for (OID oid : this.endpoint.getOids()) { this.pdu.add(new VariableBinding(oid)); } this.pdu.setErrorIndex(0); this.pdu.setErrorStatus(0); this.pdu.setMaxRepetitions(0); this.pdu.setType(PDU.GET); }