Variable var = null; if (splits.length == 2) { // no SMI syntax defined var = new OctetString(snmpPropValue); } else { int smiSyntax = Integer.valueOf(splits[2]);
/** * 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); } }
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 ) ) ); usertarget.setVersion( SnmpConstants.version3 ); usertarget.setSecurityLevel( SecurityLevel.AUTH_PRIV ); usertarget.setSecurityName( new OctetString( "MD5DES" ) ); new OctetString( userName ), AuthMD5.ID, new OctetString( passPhrase ), PrivDES.ID, new OctetString( passPhrase ) ); throw new KettleException( "Null Usm" ); } else { usm = new USM( SecurityProtocols.getInstance(), new OctetString( MPv3.createLocalEngineID() ), 0 ); usm.addUser( new OctetString( userName ), uu ); if ( log.isDebug() ) { logDebug( "Valid Usm" ); pdu.add( new VariableBinding( new OID( Oid ), new OctetString( messageString ) ) ); pdu.setType( PDU.TRAP ); if ( !Utils.isEmpty( engineID ) ) { pdu.setContextEngineID( new OctetString( engineID ) );
final String authProtocol = context.getProperty(SNMP_AUTH_PROTOCOL).getValue(); final String privProtocol = context.getProperty(SNMP_PRIV_PROTOCOL).getValue(); OctetString aPwd = authPassword != null ? new OctetString(authPassword) : null; OctetString pPwd = privPassword != null ? new OctetString(privPassword) : null; this.snmp.getUSM().addUser(new OctetString(username), new UsmUser(new OctetString(username), SNMPUtils.getAuth(authProtocol), aPwd, SNMPUtils.getPriv(privProtocol), pPwd)); final String securityName = context.getProperty(SNMP_SECURITY_NAME).getValue(); if(securityName != null) { ((UserTarget) result).setSecurityName(new OctetString(securityName)); String community = context.getProperty(SNMP_COMMUNITY).getValue(); if(community != null) { ((CommunityTarget) result).setCommunity(new OctetString(community));
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); }
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()); } }
/** * Adapts the OpenNMS SNMPv3 community name to an SNMP4J compatible * community name (String -> OctetString) * * @param agentConfig * @return */ private static OctetString convertCommunity(String community) { return new OctetString(community); }
public SynapseMOScalar(OID id, ObjectName objectName, String attribute, int snmpVersion) { super(id, MOAccessImpl.ACCESS_READ_ONLY, new OctetString()); this.objectName = objectName; this.attribute = attribute; this.snmpVersion = snmpVersion; }
private void setEngineID(OctetString engineID) { if (engineID == null) { this.engineID = new OctetString(); } else { this.engineID = engineID; } }
trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage()))); } else { throw new CloudRuntimeException(" What is the use of alert without message "); trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME), new OctetString(snmpTrapInfo.getGenerationTime().toString()))); } else { trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
private static OctetString createOctetString(String s) { if (StringUtils.isBlank(s)) { return null; } OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
public MockSnmpAgent(final File confFile, final URL moFile) { super(BOOT_COUNT_FILE, confFile, new CommandProcessor(new OctetString(MPv3.createLocalEngineID(new OctetString("MOCKAGENT"))))); m_moLoader.set(new PropertiesBackedManagedObject()); m_moFile.set(moFile); agent.setWorkerPool(ThreadPool.create("RequestPool", 4)); }
protected String getSecurityNamePrefix(byte[] securityName) { OctetString secName = new OctetString(securityName); String prefix = new String(secName.getValue()); int colonPos = prefix.indexOf(':'); if ((colonPos <= 0) || (colonPos > MAX_PREFIX_LENGTH)) { return null; } return prefix.substring(0, colonPos); }
/** * Turns array of bytes into string * * @param buf Array of bytes to convert to hex string * @return Generated hex string */ public static String asHex(byte buf[]) { return new OctetString(buf).toHexString(); }
public Variable createInitialValue() { Variable v = new OctetString(); if (v instanceof AssignableFromLong) { ((AssignableFromLong)v).setValue(0L); } // further modify value to comply with TC constraints here: //--AgentGen BEGIN=SnmpAdminString::createInitialValue //--AgentGen END return v; }
@Override public void sendMessage(A address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int retries) throws IOException { synchronized (requests) { if (logger.isDebugEnabled()) { logger.debug("Send request message to '" + address + "': " + new OctetString(message).toHexString()); } requests.add(new MessageContainer(address, new OctetString(message))); } }
public void processMessage(TransportMapping<?> sourceTransport, Address destAddress, byte[] message) { out.println("Packet sent to " + destAddress + " on " + sourceTransport.getListenAddress() + ":"); out.println(new OctetString(message).toHexString()); }
/** * Adds an USM user to the internal user name table. * The user's security name is used as userName. * * @param user * the {@code UsmUser} to add. * * @since 2.0 */ public void addUser(UsmUser user) { addUser(user.getSecurityName(), new OctetString(), user); }
public OctetString getAddress(Address address) { if (address instanceof TransportIpAddress) { TransportIpAddress tipaddr = (TransportIpAddress) address; byte[] addrBytes = tipaddr.getInetAddress().getAddress(); OctetString addr = new OctetString(addrBytes); addr.append((byte) (tipaddr.getPort() >> 8)); addr.append((byte) (tipaddr.getPort() & 0xFF)); return addr; } return null; }
/** * Default constructor with random engine ID with the default enterprise ID and a zero engineBoots counter. * The security protocols instance defined by {@link org.snmp4j.security.SecurityProtocols#getInstance()} with the * default protocols is used. * * @since 2.2.4 */ public USM() { this(SecurityProtocols.getInstance().addDefaultProtocols(), new OctetString(MPv3.createLocalEngineID(randomID())), 0); }