private CompletableFuture<SnmpResponseDTO> get(SnmpRequestDTO request, SnmpGetRequestDTO get) { final SnmpObjId[] oids = get.getOids().toArray(new SnmpObjId[get.getOids().size()]); final CompletableFuture<SnmpValue[]> future = SnmpUtils.getAsync(request.getAgent(), oids); return future.thenApply(values -> { final List<SnmpResult> results = new ArrayList<>(oids.length); for (int i = 0; i < oids.length; i++) { final SnmpResult result = new SnmpResult(oids[i], null, values[i]); results.add(result); } final SnmpResponseDTO responseDTO = new SnmpResponseDTO(); responseDTO.setCorrelationId(get.getCorrelationId()); responseDTO.setResults(results); return responseDTO; }); }
@Override public void processResponse(SnmpObjId responseObjId, SnmpValue val) { LOG.debug("Processing varBind: {} = {}", responseObjId, val); if (val.isEndOfMib()) { receivedEndOfMib(); } if (m_oid.equals(responseObjId)) { storeResult(new SnmpResult(m_base, m_inst, val)); } setFinished(true); }
private CompletableFuture<SnmpResponseDTO> get(SnmpRequestDTO request, SnmpGetRequestDTO get) { final SnmpObjId[] oids = get.getOids().toArray(new SnmpObjId[get.getOids().size()]); final CompletableFuture<SnmpValue[]> future = SnmpUtils.getAsync(request.getAgent(), oids); return future.thenApply(values -> { final List<SnmpResult> results = new ArrayList<>(oids.length); for (int i = 0; i < oids.length; i++) { final SnmpResult result = new SnmpResult(oids[i], null, values[i]); results.add(result); } final SnmpResponseDTO responseDTO = new SnmpResponseDTO(); responseDTO.setCorrelationId(get.getCorrelationId()); responseDTO.setResults(results); return responseDTO; }); }
public void processResponse(SnmpObjId responseObjId, SnmpValue val) { log().debug("Processing varBind: "+responseObjId+" = "+val); if (val.isEndOfMib()) { receivedEndOfMib(); } if (m_oid.equals(responseObjId)) { storeResult(new SnmpResult(m_base, m_inst, val)); } setFinished(true); }
@Override public void processResponse(SnmpObjId responseObjId, SnmpValue val) { if (val.isEndOfMib()) { receivedEndOfMib(); return; } LOG.debug("Processing varBind: {} = {}", responseObjId, val); m_last = responseObjId; if (m_base.isPrefixOf(responseObjId) && !m_base.equals(responseObjId)) { SnmpInstId inst = responseObjId.getInstance(m_base); if (inst != null) { storeResult(new SnmpResult(m_base, inst, val)); } } if (!m_base.isPrefixOf(m_last)) { setFinished(true); } }
public void processResponse(SnmpObjId responseObjId, SnmpValue val) { if (val.isEndOfMib()) { receivedEndOfMib(); } m_last = responseObjId; if (m_base.isPrefixOf(responseObjId) && !m_base.equals(responseObjId)) { SnmpInstId inst = responseObjId.getInstance(m_base); if (inst != null) { storeResult(new SnmpResult(m_base, inst, val)); } } if (!m_base.isPrefixOf(m_last)) { setFinished(true); } }
public void testStoreResultWithValueThenEndOfMibView() { String baseOid = ".1.3.6.1.2.1.31.1.1.1.18"; String ifAliasName = "ifAlias"; String ifAliasValue = "Foo!"; SnmpStore store = new SnmpStore(new NamedSnmpVar[] { new NamedSnmpVar(NamedSnmpVar.SNMPOCTETSTRING, ifAliasName, baseOid, 18) }); SnmpObjId base = SnmpObjId.get(baseOid); SnmpInstId inst = new SnmpInstId("1"); store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getOctetString(ifAliasValue.getBytes()))); store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getValue(SnmpValue.SNMP_END_OF_MIB, null))); assertEquals("ifAlias value", ifAliasValue, store.getDisplayString(ifAliasName)); } }
public TrapDTO(TrapInformation trapInfo) { setAgentAddress(trapInfo.getAgentAddress()); setCommunity(trapInfo.getCommunity()); setVersion(trapInfo.getVersion()); setTimestamp(trapInfo.getTimeStamp()); setPduLength(trapInfo.getPduLength()); setCreationTime(trapInfo.getCreationTime()); setTrapIdentity(new TrapIdentityDTO(trapInfo.getTrapIdentity())); // Map variable bindings final List<SnmpResult> results = new ArrayList<>(); for (int i = 0; i < trapInfo.getPduLength(); i++) { final SnmpVarBindDTO varBindDTO = trapInfo.getSnmpVarBindDTO(i); if (varBindDTO != null) { final SnmpResult snmpResult = new SnmpResult(varBindDTO.getSnmpObjectId(), null, varBindDTO.getSnmpValue()); results.add(snmpResult); } } setResults(results); }
public TrapDTO(TrapInformation trapInfo) { setAgentAddress(trapInfo.getAgentAddress()); setCommunity(trapInfo.getCommunity()); setVersion(trapInfo.getVersion()); setTimestamp(trapInfo.getTimeStamp()); setPduLength(trapInfo.getPduLength()); setCreationTime(trapInfo.getCreationTime()); setTrapIdentity(new TrapIdentityDTO(trapInfo.getTrapIdentity())); // Map variable bindings final List<SnmpResult> results = new ArrayList<>(); for (int i = 0; i < trapInfo.getPduLength(); i++) { final SnmpVarBindDTO varBindDTO = trapInfo.getSnmpVarBindDTO(i); if (varBindDTO != null) { final SnmpResult snmpResult = new SnmpResult(varBindDTO.getSnmpObjectId(), null, varBindDTO.getSnmpValue()); results.add(snmpResult); } } setResults(results); }
attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
@Test public void testCommitWithDeclaredAttributeAndNullValue() throws Exception { RrdRepository repository = createRrdRepository(); SnmpCollectionAgent agent = getCollectionAgent(); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); CollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("string"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes()))); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.declareAttribute(attributeType); builder.setAttributeValue(attributeType, null); builder.commit(); }
@Test public void testCommitWithDeclaredAttribute() throws Exception { File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension()); m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta"); RrdRepository repository = createRrdRepository(); SnmpCollectionAgent agent = getCollectionAgent(); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); CollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("counter"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes()))); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.declareAttribute(attributeType); builder.commit(); }
@Test public void testCommitWithDeclaredAttributeAndValue() throws Exception { File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension()); m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta"); RrdRepository repository = createRrdRepository(); SnmpCollectionAgent agent = getCollectionAgent(); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); CollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("counter"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes()))); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.declareAttribute(attributeType); builder.setAttributeValue(attributeType, 6.022E23d); builder.commit(); }