Search in sources :

Example 1 with MockCollectionAgent

use of org.opennms.core.collection.test.MockCollectionAgent in project opennms by OpenNMS.

the class TcpOutputStrategyTest method peristAndReceiveProtobufMessages.

@Test
public void peristAndReceiveProtobufMessages() {
    Date start = new Date();
    // Build a collection set with both numeric and string attributes
    String owner = "192.168.1.1";
    MockCollectionAgent agent = new MockCollectionAgent(1, "n1", InetAddressUtils.addr(owner));
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
    InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth0, "mib2-interfaces", "ifSpeed", "10000000");
    builder.withStringAttribute(eth0, "mib2-interfaces", "ifHighSpeed", "10");
    CollectionSet collectionSet = builder.build();
    // Persist without storeByGroup
    persist(collectionSet, false);
    // Wait for the server to receive the readings
    await().until(() -> allReadings.size() == 1);
    PerformanceDataReadings readings = allReadings.get(0);
    // The reading should contain three messages
    assertEquals(3, readings.getMessageCount());
    PerformanceDataReading reading = readings.getMessage(0);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifInErrors").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Collections.emptyList()).build(), reading);
    reading = readings.getMessage(1);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10000000")).build(), reading);
    reading = readings.getMessage(2);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifHighSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10")).build(), reading);
    // Persist with storeByGroup
    persist(collectionSet, true);
    // Wait for the server to receive the readings
    await().until(() -> allReadings.size() == 2);
    readings = allReadings.get(1);
    // The reading should contain 1 message
    assertEquals(1, readings.getMessageCount());
    reading = readings.getMessage(0);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "mib2-interfaces").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Arrays.asList("10", "10000000")).build(), reading);
    // The reading should be a timestamp in milliseconds
    Date dateFromReading = new Date(reading.getTimestamp());
    assertTrue(String.format("%s <= %s", start, dateFromReading), start.compareTo(dateFromReading) <= 0);
}
Also used : PerformanceDataReading(org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReading) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) PerformanceDataReadings(org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReadings) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 2 with MockCollectionAgent

use of org.opennms.core.collection.test.MockCollectionAgent in project opennms by OpenNMS.

the class NMS7963IT method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
    dao.setConfigDirectory("src/test/resources/etc/datacollection");
    dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml"));
    dao.afterPropertiesSet();
    DataCollectionConfigFactory.setInstance(dao);
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
    m_temporaryFolder.newFolder("snmp");
    m_persisterFactory = new RrdPersisterFactory();
    m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    m_persisterFactory.setRrdStrategy(m_rrdStrategy);
    m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1"));
    m_nodeDao = EasyMock.createMock(NodeDao.class);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("mynode.local");
    node.setAssetRecord(new OnmsAssetRecord());
    EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes();
    EasyMock.replay(m_nodeDao);
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) FileSystemResource(org.springframework.core.io.FileSystemResource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Before(org.junit.Before)

Example 3 with MockCollectionAgent

use of org.opennms.core.collection.test.MockCollectionAgent in project opennms by OpenNMS.

the class NodeLevelDataOnMultipleNodesTest method executeCollectorTest.

/**
 * 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());
}
Also used : CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) File(java.io.File) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 4 with MockCollectionAgent

use of org.opennms.core.collection.test.MockCollectionAgent in project opennms by OpenNMS.

the class JMXCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("opennms.home", new File("src/test/resources").getAbsolutePath());
    jmxDataCollectionConfigDao = new JMXDataCollectionConfigDao();
    jmxNodeInfo = new JMXNodeInfo(0);
    jmxCollector = new JMXCollectorImpl();
    jmxCollector.setJmxConfigDao(new JmxConfigDaoJaxb());
    jmxCollector.setJmxDataCollectionConfigDao(jmxDataCollectionConfigDao);
    platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("org.opennms.netmgt.collectd.jmxhelper:type=JmxTest");
    JmxTestMBean testMBean = new JmxTest();
    platformMBeanServer.registerMBean(testMBean, objectName);
    collectionAgent = new MockCollectionAgent(1, "node", "fs", "fid", InetAddress.getLoopbackAddress());
}
Also used : JmxConfigDaoJaxb(org.opennms.netmgt.dao.jmx.JmxConfigDaoJaxb) JMXDataCollectionConfigDao(org.opennms.netmgt.config.JMXDataCollectionConfigDao) JmxTest(org.opennms.netmgt.collectd.jmxhelper.JmxTest) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) JmxTestMBean(org.opennms.netmgt.collectd.jmxhelper.JmxTestMBean) File(java.io.File) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Example 5 with MockCollectionAgent

use of org.opennms.core.collection.test.MockCollectionAgent in project opennms by OpenNMS.

the class EvaluateStatsIT method testPersister.

/**
 * Test persister.
 *
 * @throws Exception the exception
 */
@Test
public void testPersister() throws Exception {
    RrdRepository repo = new RrdRepository();
    repo.setRrdBaseDir(new File("/tmp"));
    EvaluateGroupPersister persister = new EvaluateGroupPersister(stats, new ServiceParameters(new HashMap<String, Object>()), repo);
    MockCollectionAgent agent = new MockCollectionAgent(1, "node.local", "Test", "001", InetAddressUtils.addr("127.0.0.1"));
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
    InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth0, "mib2-X-interfaces", "ifHighSpeed", "1000");
    InterfaceLevelResource eth1 = new InterfaceLevelResource(node, "eth1");
    builder.withNumericAttribute(eth1, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth1, "mib2-X-interfaces", "ifHighSpeed", "1000");
    builder.build().visit(persister);
    stats.dumpCache();
    Assert.assertEquals(1, registry.getGauges().get("evaluate.nodes").getValue());
    Assert.assertEquals(2, registry.getGauges().get("evaluate.resources").getValue());
    Assert.assertEquals(4, registry.getGauges().get("evaluate.groups").getValue());
    Assert.assertEquals(8, registry.getGauges().get("evaluate.numeric-attributes").getValue());
    Assert.assertEquals(2, registry.getGauges().get("evaluate.string-attributes").getValue());
    Assert.assertEquals(8, registry.getMeters().get("evaluate.samples").getCount());
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) HashMap(java.util.HashMap) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) File(java.io.File) Test(org.junit.Test)

Aggregations

MockCollectionAgent (org.opennms.core.collection.test.MockCollectionAgent)8 Before (org.junit.Before)5 FileSystemResource (org.springframework.core.io.FileSystemResource)4 File (java.io.File)3 RrdPersisterFactory (org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory)3 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)3 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)3 Test (org.junit.Test)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)2 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)2 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 EventProxy (org.opennms.netmgt.events.api.EventProxy)2 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 XmlDataCollectionConfigDaoJaxb (org.opennms.protocols.xml.dao.jaxb.XmlDataCollectionConfigDaoJaxb)2 Resource (org.springframework.core.io.Resource)2