/** * Return a read only instance of the parameters, which consists of the overall service parameters, * plus various other Collection specific parameters (e.g. storeByNodeID etc) * * @return A read only Map instance */ public ServiceParameters getServiceParameters() { return new ServiceParameters(Collections.unmodifiableMap(m_parameters)); }
/** * Return a read only instance of the parameters, which consists of the overall service parameters, * plus various other Collection specific parameters (e.g. storeByNodeID etc) * * @return A read only Map instance */ public ServiceParameters getServiceParameters() { return new ServiceParameters(Collections.unmodifiableMap(m_parameters)); }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final ServiceParameters serviceParams = new ServiceParameters(parameters); final String collectionName = serviceParams.getCollectionName(); final NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); if (collection == null) { throw new IllegalArgumentException(String.format("NSClientCollector: No collection found with name '%s'.", collectionName)); } runtimeAttributes.put(NSCLIENT_COLLECTION_KEY, collection); final NSClientAgentConfig agentConfig = NSClientPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(NSCLIENT_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final ServiceParameters serviceParams = new ServiceParameters(parameters); final String collectionName = serviceParams.getCollectionName(); final NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); if (collection == null) { throw new IllegalArgumentException(String.format("NSClientCollector: No collection found with name '%s'.", collectionName)); } runtimeAttributes.put(NSCLIENT_COLLECTION_KEY, collection); final NSClientAgentConfig agentConfig = NSClientPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(NSCLIENT_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
private IfResourceType createInterfaceResourceType(SnmpCollectionAgent agent) { MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); return new IfResourceType(agent, collection); }
private NodeResourceType createNodeResourceType(SnmpCollectionAgent agent) { MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); return new NodeResourceType(agent, collection); }
private SnmpCollectionResource createNodeResource(SnmpCollectionAgent agent) { MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); return new NodeInfo(resourceType, agent); }
private GenericIndexResourceType createGenericIndexResourceType(SnmpCollectionAgent agent, String resourceTypeName) { org.opennms.netmgt.config.datacollection.ResourceType type = createIndexResourceType(agent, resourceTypeName); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); return new GenericIndexResourceType(agent, collection, type); }
protected void initializeAgent() throws CollectionInitializationException { ServiceParameters params = new ServiceParameters(new HashMap<String, Object>()); OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(m_agent, params, m_config, m_locationAwareSnmpClient); m_collectionSet = snmpCollection.createCollectionSet(m_agent); m_agent.validateAgent(); }
private void createCollectableService() throws CollectionInitializationException, IOException { // Mock it all! OnmsIpInterface iface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); spec = mock(CollectionSpecification.class); scheduler = mock(Scheduler.class); SchedulingCompletedFlag schedulingCompletedFlag = mock(SchedulingCompletedFlag.class); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); RrdPersisterFactory persisterFactory = new RrdPersisterFactory(); persisterFactory.setRrdStrategy(rrdStrategy); ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class); // Disable thresholding Map<String, Object> paramsMap = new HashMap<>(); paramsMap.put("thresholding-enabled", Boolean.FALSE.toString()); ServiceParameters params = new ServiceParameters(paramsMap); when(iface.getNode().getId()).thenReturn(1); when(spec.getServiceParameters()).thenReturn(params); when(spec.getRrdRepository(any())).thenReturn(createRrdRepository()); when(ifaceDao.load(any())).thenReturn(iface); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); service = new CollectableService(iface, ifaceDao, spec, scheduler, schedulingCompletedFlag, transMgr, persisterFactory, resourceStorageDao); }
/** * Test override of read community string and max repetitions in Collectd configuration parameters */ @Test public void testOverrides() { Map<String, Object> map = new HashMap<String, Object>(); map.put("max-repetitions", "11"); map.put("read-community", "notPublic"); ServiceParameters params = new ServiceParameters(map); int reps = params.getSnmpMaxRepetitions(6); assertEquals("Overriding max repetitions failed.", 11, reps); params = new ServiceParameters(map); map.remove("max-repetitions"); map.put("maxRepetitions", "11"); assertEquals("Overriding max repetitions failed.", 11, reps); String s = params.getSnmpReadCommunity("public"); assertEquals("Overriding read community failed.", "notPublic", s); map.remove("read-community"); map.put("readCommunity", "notPublic"); params = new ServiceParameters(map); s = params.getSnmpReadCommunity("public"); assertEquals("Overriding read community failed.", "notPublic", s); }
@Test public void testCommitWithNoDeclaredAttributes() 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); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.commit(); }
private ThresholdingVisitor createVisitor(Map<String,Object> params) throws ThresholdInitializationException { ServiceParameters svcParams = new ServiceParameters(params); ThresholdingVisitor visitor = ThresholdingVisitor.create(1, "127.0.0.1", "SNMP", getRepository(), svcParams, m_resourceStorageDao); assertNotNull(visitor); return visitor; }
/** * Executes collector test. * * @param nodeId the node id * @param ipAddress the IP address * @param xmlSampleFileName the XML sample file name * @param parameters the parameters * @param expectedFiles the expected amount of JRB files * @throws Exception the exception */ public void executeCollectorTest(int nodeId, String ipAddress, String xmlSampleFileName, Map<String, Object> parameters, int expectedFiles) throws Exception { MockDocumentBuilder.setXmlFileName(xmlSampleFileName); CollectionAgent collectionAgent = new MockCollectionAgent(nodeId, "mynode", InetAddrUtils.addr(ipAddress)); CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_collector, collectionAgent, parameters); Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); ServiceParameters serviceParams = new ServiceParameters(new HashMap<String,Object>()); CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String)parameters.get("collection")), false, false); collectionSet.visit(persister); Assert.assertEquals(expectedFiles, FileUtils.listFiles(new File(getSnmpRoot(), Integer.toString(nodeId)), new String[] { getRrdExtension() }, true).size()); }
/** * Executes collector test. * * @param parameters the parameters * @param expectedFiles the expected amount of JRB files * @return the collection set * @throws Exception the exception */ public CollectionSet executeCollectorTest(Map<String, Object> parameters, int expectedFiles) throws Exception { XmlCollector collector = new XmlCollector(); collector.setXmlCollectionDao(m_xmlCollectionDao); CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters); Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); ServiceParameters serviceParams = new ServiceParameters(new HashMap<String,Object>()); CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String)parameters.get("collection")), false, false); collectionSet.visit(persister); Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRootDirectory(), new String[] { getRrdExtension() }, true).size()); return collectionSet; }
private SnmpAttribute buildStringAttribute() { EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); m_easyMockUtils.replayAll(); SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); SnmpCollectionResource 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); SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes())); }
@Before public void setUp() throws Exception { MockUtil.println("------------ Begin Test " + m_testName.getMethodName() + " --------------------------"); MockLogAppender.setupLogging(); m_fileAnticipator = new FileAnticipator(); m_rrdStrategy = new JRobinRrdStrategy(); m_resourceStorageDao = new FilesystemResourceStorageDao(); m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir()); m_intf = new OnmsIpInterface(); m_node = new OnmsNode(); m_node.setId(1); m_intf.setId(25); m_intf.setNode(m_node); m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1")); m_ifDao = m_easyMockUtils.createMock(IpInterfaceDao.class); m_serviceParams = new ServiceParameters(new HashMap<String,Object>()); }
@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(); }