Refine search
transMap.listen(); target.setCommunity( new OctetString( community ) ); target.setVersion( SnmpConstants.version1 ); target.setAddress( udpAddress ); 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 ) );
/** * 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); } }
Variable var = null; if (splits.length == 2) { // no SMI syntax defined var = new OctetString(snmpPropValue); } else { int smiSyntax = Integer.valueOf(splits[2]); VariableBinding varBind = new VariableBinding(new OID(snmpPropName), var); pdu.add(varBind); result = true;
public void commit(SubRequest sreq) { super.commit(sreq); if (sreq.getStatus().getErrorStatus() == PDU.noError) { OID index = sreq.getVariableBinding().getOid(); index = new OID(index.getValue(), oidNlmConfigLogEntry.size() + 1, index.size() - oidNlmConfigLogEntry.size() + 1); OctetString profileName = new OctetString(); profileName.fromSubIndex(index, false); checkLimits(profileName); } } //--AgentGen END
final OID interfacesTable = new OID(".1.3.6.1.4.1.44.1"); MOTableBuilder builder = new MOTableBuilder(interfacesTable) .addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_READ_WRITE) //first row .addRowValue(new OctetString("loopback")) //next row .addRowValue(new Integer32(4)); agent.registerManagedObject(builder.build()); agent.listen();
/** * 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); }
public void rowStatusChanged(RowStatusEvent event) { if (event.getTable().equals(snmp4jLogLoggerEntry)) { if ((event.getNewStatus() == RowStatus.active) || (event.getNewStatus() == RowStatus.createAndGo)) { Snmp4jLogLoggerRow r = (Snmp4jLogLoggerRow) event.getRow(); LogAdapter logAdapter = r.getLogAdapter(); if (logAdapter == null) { OctetString loggerName = new OctetString(r.getIndex().toByteArray()); logAdapter = LogFactory.getLogger(loggerName.toString()); r.setLogAdapter(logAdapter); } logAdapter.setLogLevel( new LogLevel(r.getSnmp4jLogLoggerLevel().getValue())); } } }
private List<MOTableRow> getAccessEntries(OctetString groupName) { OctetString upperBound = new OctetString(groupName); byte last = -1; if (upperBound.length() > 0) { last = upperBound.get(upperBound.length() - 1); } if (last == -1) { upperBound.append((byte)0); } else { upperBound.set(upperBound.length()-1, (byte)(last+1)); } OID lowerOID = groupName.toSubIndex(false); OID upperOID = upperBound.toSubIndex(false); return vacmAccessTableModel.getRows(lowerOID, upperOID); }
/** * Initializes the message dispatcher ({@link MessageDispatcherImpl}) with * the transport mappings. */ protected void initMessageDispatcher() { dispatcher = new MessageDispatcherImpl(); mpv3 = new MPv3(agent.getContextEngineID().getValue()); usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots()); SecurityModels.getInstance().addSecurityModel(usm); SecurityProtocols.getInstance().addDefaultProtocols(); dispatcher.addMessageProcessingModel(new MPv1()); dispatcher.addMessageProcessingModel(new MPv2c()); dispatcher.addMessageProcessingModel(mpv3); initSnmpSession(); }
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)); }
private OctetString createOctetString(String s) { if (s == null) { return null; } OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
private void addString(PDU pdu, OID prefix, int suffix, String val, boolean allowEmpty) { if (allowEmpty || !StringUtils.isEmpty(val)) { pdu.add(new VariableBinding(new OID(prefix).append(suffix), new OctetString(val == null ? "" : val))); } }
public Snmp4jLogLoggerEntryRow createRow(OID index, Variable[] values) throws UnsupportedOperationException { // Snmp4jLogLoggerEntryRow row = new Snmp4jLogLoggerEntryRow(index, values); //--AgentGen BEGIN=snmp4jLogLoggerEntry::createRow int i = nextLoggerIndex++; Snmp4jLogLoggerEntryRow row = new Snmp4jLogLoggerRow(index, values, i, null); row.setSnmp4jLogLoggerIndex(new Integer32(i)); loggerNames2Index.put(new OctetString(index.toByteArray()).toString(),i); //--AgentGen END return row; }
/** {@inheritDoc} */ @Override protected void addCommunities(SnmpCommunityMIB communityMIB) { Variable[] com2sec = new Variable[] { new OctetString("public"), // community name new OctetString("public"), // security name getAgent().getContextEngineID(), // local engine ID new OctetString(), // default context name new OctetString(), // transport tag new Integer32(StorageType.nonVolatile), // storage type new Integer32(RowStatus.active) // row status }; SnmpCommunityEntryRow row = communityMIB.getSnmpCommunityEntry().createRow(new OctetString("public2public").toSubIndex(true), com2sec); communityMIB.getSnmpCommunityEntry().addRow(row); }
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 OID toSubIndex(boolean impliedLength) { int[] subIndex; int offset = 0; if (!impliedLength) { subIndex = new int[length()+1]; subIndex[offset++] = length(); } else { subIndex = new int[length()]; } for (int i=0; i<length(); i++) { subIndex[offset+i] = get(i) & 0xFF; } return new OID(subIndex); }
private int registerProxy(Snmp4jProxyEntryRow row) { OctetString proxyName = new OctetString(); proxyName.fromSubIndex(row.getIndex(), true); MOSubtreeProxy proxy = new MOSubtreeProxy(session, targetMIB, proxyName, row.getSnmp4jProxySubtree(), row.getSnmp4jProxyContextEngineID(), row.getSnmp4jProxyContextName(), row.getSnmp4jProxyTarget()); OID targetOID = row.getSnmp4jProxyTargetSubtree(); if ((targetOID != null) && (targetOID.size() > 0) && !SnmpConstants.zeroDotZero.equals(targetOID)) { proxy.setTargetSubtree(targetOID); } try { server.register(proxy, row.getSnmp4jProxyContextName()); } catch (DuplicateRegistrationException drex) { row.setSnmp4jProxyType(new Integer32(Snmp4jProxyTypeEnum.invalid)); return PDU.inconsistentValue; } row.setUserObject(proxy); return PDU.noError; }
private static OID createGroupIndex(int securityModel, OctetString securityName) { OID index = new OID(); index.append(securityModel); index.append(securityName.toSubIndex(false)); return index; }
/** * This is a convenience constructor which can be used to create a MPv3 which * is bound to a specific USM instance. A dedicated USM instance per * MPv3 is necessary if multiple {@link Snmp} instances are used within a VM. * @param usm * an USM instance. * @since 1.10 */ public MPv3(USM usm) { this(usm.getLocalEngineID().getValue(), null, SecurityProtocols.getInstance(), SecurityModels.getCollection(new SecurityModel[]{usm}), CounterSupport.getInstance()); }
static PDU snmpMessageToHumanReadable(String s) throws IOException { final OctetString message = OctetString.fromHexString(s, ':'); final Address address = new UdpAddress(); final TransportMapping transportMapping = (address instanceof UdpAddress) ? new DefaultUdpTransportMapping((UdpAddress) address) : new DefaultTcpTransportMapping((TcpAddress) address); final MessageDispatcher messageDispatcher = new MessageDispatcherImpl(); SecurityProtocols.getInstance().addDefaultProtocols(); final SnmpMessageAnalyzer snmpMessageAnalyzer = new SnmpMessageAnalyzer(); final CommandResponder commandResponder = snmpMessageAnalyzer; messageDispatcher.addCommandResponder(commandResponder); messageDispatcher.addMessageProcessingModel(new MPv1()); messageDispatcher.addMessageProcessingModel(new MPv2c()); messageDispatcher.addMessageProcessingModel(new MPv3()); messageDispatcher.processMessage(transportMapping, address, ByteBuffer.wrap(message.getValue())); PDU result = snmpMessageAnalyzer.msg; snmpMessageAnalyzer.msg = null; return result; }