use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class NewtsPersisterIT method canPersist.
@Test
public void canPersist() throws InterruptedException {
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
RrdRepository repo = new RrdRepository();
// Only the last element of the path matters here
repo.setRrdBaseDir(Paths.get("a", "path", "that", "ends", "with", "snmp").toFile());
Persister persister = m_persisterFactory.createPersister(params, repo);
int nodeId = 1;
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get(Integer.toString(nodeId)));
NodeLevelResource nodeLevelResource = new NodeLevelResource(nodeId);
// Build a collection set with a single sample
Timestamp now = Timestamp.now();
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeLevelResource, "metrics", "metric", 900, AttributeType.GAUGE).withTimestamp(now.asDate()).build();
// Persist
collectionSet.visit(persister);
// Wait for the sample(s) to be flushed
Thread.sleep(5 * 1000);
// Fetch the (persisted) sample
Resource resource = new Resource("snmp:1:metrics");
Timestamp end = Timestamp.now();
Results<Sample> samples = m_sampleRepository.select(Context.DEFAULT_CONTEXT, resource, Optional.of(now), Optional.of(end));
assertEquals(1, samples.getRows().size());
Row<Sample> row = samples.getRows().iterator().next();
assertEquals(900, row.getElement("metric").getValue().doubleValue(), 0.00001);
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResource.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-5.xml
*/
@Test
public void testThresholdsFiltersOnNodeResource() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
ThresholdingVisitor visitor = createVisitor();
// Adding Expected Thresholds
addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
// Creating Node ResourceType
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, collection);
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1");
m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
// Creating Resource
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageUsed", "gauge", "node", 50);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageUsed", "gauge", "node", 60);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageUsed", "gauge", "node", 70);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageSize", "gauge", "node", 100);
// Run Visitor and Verify Events
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class ThresholdingVisitorIT method createVisitor.
private ThresholdingVisitor createVisitor(Map<String, Object> params) {
ServiceParameters svcParams = new ServiceParameters(params);
ThresholdingVisitor visitor = ThresholdingVisitor.create(1, "127.0.0.1", "SNMP", getRepository(), svcParams, m_resourceStorageDao);
assertNotNull(visitor);
return visitor;
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class TcpOutputStrategyTest method persist.
public void persist(CollectionSet collectionSet, boolean forceStoreByGroup) {
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
RrdRepository repo = new RrdRepository();
repo.setRrdBaseDir(tempFolder.getRoot());
Persister persister = persisterFactory.createPersister(params, repo, false, forceStoreByGroup, false);
collectionSet.visit(persister);
}
use of org.opennms.netmgt.collection.api.ServiceParameters 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