use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class WSManCollectorTest method canGenerateManyResources.
/**
* NMS-8924: Verifies that the generated collection set includes a resource
* for every node (XML) in the response.
*/
@Test
public void canGenerateManyResources() {
// Define our resource type, and create a supplier that returns a new instance on every call
NodeLevelResource node = mock(NodeLevelResource.class);
ResourceType rt = new ResourceType();
rt.setName("wsProcIndex");
rt.setLabel("Processor (wsman)");
rt.setResourceLabel("Processor (${wmiOSCpuName})");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz(SiblingColumnStorageStrategy.class.getCanonicalName());
strategy.addParameter(new Parameter("sibling-column-name", "wmiOSCpuName"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
rt.setPersistenceSelectorStrategy(pstrategy);
final AtomicInteger instanceId = new AtomicInteger();
Supplier<Resource> resourceSupplier = () -> {
return new GenericTypeResource(node, rt, Integer.toString(instanceId.getAndIncrement()));
};
// Define our group
Group group = new Group();
group.setName("windows-os-wmi-processor");
addAttribute(group, "Name", "wmiOSCpuName", AttributeType.STRING);
addAttribute(group, "InterruptsPersec", "wmiOSCpuIntsPerSec", AttributeType.GAUGE);
addAttribute(group, "PercentProcessorTime", "wmiOSCpuPctProcTime", AttributeType.GAUGE);
addAttribute(group, "PercentDPCTime", "wmiOSCpuPctDPCTime", AttributeType.GAUGE);
addAttribute(group, "PercentInterruptTime", "wmiOSCpuPctIntrTime", AttributeType.GAUGE);
addAttribute(group, "PercentUserTime", "wmiOSCpuPctUserTime", AttributeType.GAUGE);
// Mock the agent
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
// Sample data
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c0").addTag("InterruptsPersec").setText("95").gotoRoot().addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c1").addTag("InterruptsPersec").setText("100");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
// Process the data and generate the collection set
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify the result
CollectionSet collectionSet = builder.build();
assertEquals(Arrays.asList("wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuName[c0,null]", "wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,95.0]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuName[c1,null]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,100.0]"), CollectionSetUtils.flatten(collectionSet));
assertEquals(Sets.newHashSet("c0", "c1"), CollectionSetUtils.getResourcesByLabel(collectionSet).keySet());
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class WSManCollectorTest method canSuccesfullyCollectFromGroupWithNoAttributes.
@Test
public void canSuccesfullyCollectFromGroupWithNoAttributes() throws CollectionInitializationException, CollectionException {
OnmsNode node = mock(OnmsNode.class);
NodeDao nodeDao = mock(NodeDao.class);
when(nodeDao.get(0)).thenReturn(node);
WSManConfigDao configDao = mock(WSManConfigDao.class);
when(configDao.getAgentConfig(any())).thenReturn(new Definition());
Collection collection = new Collection();
WSManDataCollectionConfigDao dataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
when(dataCollectionConfigDao.getCollectionByName("default")).thenReturn(collection);
WsManCollector collector = new WsManCollector();
collector.setWSManClientFactory(mock(WSManClientFactory.class));
collector.setWSManConfigDao(configDao);
collector.setWSManDataCollectionConfigDao(dataCollectionConfigDao);
collector.setNodeDao(nodeDao);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getAddress()).thenReturn(InetAddressUtils.getLocalHostAddress());
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
Map<String, Object> collectionParams = Maps.newHashMap();
collectionParams.put("collection", "default");
collectionParams.putAll(collector.getRuntimeAttributes(agent, collectionParams));
CollectionSet collectionSet = collector.collect(agent, collectionParams);
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
assertEquals(0, CollectionSetUtils.getAttributesByName(collectionSet).size());
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class HttpCollectorIT method doTestNMS4886.
public final void doTestNMS4886(String svcName) throws Exception {
HttpCollector collector = new HttpCollector();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("http-collection", "default");
parameters.put("port", "10342");
collector.initialize();
Package pkg = new Package();
Filter filter = new Filter();
filter.setContent("IPADDR IPLIKE *.*.*.*");
pkg.setFilter(filter);
Service service = new Service();
service.setName(svcName);
Parameter collectionParm = new Parameter();
collectionParm.setKey("http-collection");
collectionParm.setValue("default");
service.addParameter(collectionParm);
Parameter portParm = new Parameter();
portParm.setKey("port");
portParm.setValue("10342");
service.addParameter(portParm);
pkg.addService(service);
CollectionSpecification collectionSpecification = new CollectionSpecification(pkg, svcName, collector, new DefaultCollectdInstrumentation(), CollectorTestUtils.createLocationAwareCollectorClient());
CollectionSet collectionSet = collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, collectionSpecification, collectionSet);
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorWithMibPropertiesIT method testCollect.
/**
* Test collection with MibObj Properties.
*
* @throws Exception the exception
*/
@Test
@JUnitCollector(datacollectionType = "snmp", datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config-NMS8484.xml")
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/airespace.properties")
public void testCollect() throws Exception {
System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
Map<String, String> slot0 = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "bsnAPIfLoadParametersEntry", "132.178.97.20.31.224.0"));
assertEquals("AP84b2.6111.29ac", slot0.get("bsnAPName"));
assertEquals("0", slot0.get("slotNumber"));
Map<String, String> slot1 = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "bsnAPIfLoadParametersEntry", "132.178.97.20.31.224.1"));
assertEquals("AP84b2.6111.29ac", slot1.get("bsnAPName"));
assertEquals("1", slot1.get("slotNumber"));
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorWithMibPropertiesIT method testCollectCiscoQoS.
/**
* Test collection for Cisco QoS with MibObj Properties.
*
* @throws Exception the exception
*/
@Test
@JUnitCollector(datacollectionType = "snmp", datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config-cisco-qos.xml")
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/cisco-qos.properties")
public void testCollectCiscoQoS() throws Exception {
System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
Map<String, String> map = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "cbQosCMStatsEntry", "290.508801"));
assertEquals("OUTBOUND-LLQ", map.get("cbQosClassMapPolicy"));
assertEquals("GESTION-ROUTING", map.get("cbQosClassMapName"));
assertEquals("Conexion Valencia", map.get("ifAlias"));
}
Aggregations