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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations