use of com.mycila.xmltool.XMLTag 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
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(builder.build()));
}
use of com.mycila.xmltool.XMLTag in project opennms by OpenNMS.
the class WSManCollectorTest method canCollectFromMultivaluedKeyUsingIndexOf.
@Test
public void canCollectFromMultivaluedKeyUsingIndexOf() {
/* The iDrac provides the following keys in the DCIM_ComputerSystem entry:
* <n1:IdentifyingDescriptions>CIM:GUID</n1:IdentifyingDescriptions>
* <n1:IdentifyingDescriptions>CIM:Tag</n1:IdentifyingDescriptions>
* <n1:IdentifyingDescriptions>DCIM:ServiceTag</n1:IdentifyingDescriptions>
* <n1:OtherIdentifyingInfo>44454C4C-3700-104A-8052-C3C04BB25031</n1:OtherIdentifyingInfo>
* <n1:OtherIdentifyingInfo>mainsystemchassis</n1:OtherIdentifyingInfo>
* <n1:OtherIdentifyingInfo>C7BBBP1</n1:OtherIdentifyingInfo>
*
* We want to be able to collect the value of 'OtherIdentifyingInfo' at the same
* index where 'IdentifyingDescriptions' has the value of 'DCIM:ServiceTag'.
*/
Group group = new Group();
group.setName("DCIM_ComputerSystem");
Attrib attr = new Attrib();
attr.setName("OtherIdentifyingInfo");
attr.setAlias("ServiceTag");
attr.setIndexOf("#IdentifyingDescriptions matches '.*ServiceTag'");
attr.setType(AttributeType.STRING);
group.addAttrib(attr);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_ComputerSystem").addTag("IdentifyingDescriptions").setText("CIM:GUID").addTag("IdentifyingDescriptions").setText("DCIM:ServiceTag").addTag("IdentifyingDescriptions").setText("CIM:Tag").addTag("OtherIdentifyingInfo").setText("44454C4C-3700-104A-8052-C3C04BB25031").addTag("OtherIdentifyingInfo").setText("C7BBBP1").addTag("OtherIdentifyingInfo").setText("mainsystemchassis");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertEquals("C7BBBP1", attributesByName.get("ServiceTag").getStringValue());
}
use of com.mycila.xmltool.XMLTag in project opennms by OpenNMS.
the class WSManCollectorTest method canProcessEnumerationResults.
@Test
public void canProcessEnumerationResults() {
Group group = new Group();
group.setName("ComputerSystem");
addAttribute(group, "PrimaryStatus", "GaugeWithValue", AttributeType.GAUGE);
addAttribute(group, "!PrimaryStatus!", "GaugeWithoutValue", AttributeType.GAUGE);
addAttribute(group, "ElementName", "StringWithValue", AttributeType.STRING);
addAttribute(group, "!ElementName!", "StringWithoutValue", AttributeType.STRING);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_ComputerSystem").addTag("ElementName").setText("Computer System").addTag("PrimaryStatus").setText("42.1").addTag("OtherIdentifyingInfo").setText("ANONYMIZED01").addTag("OtherIdentifyingInfo").setText("mainsystemchassis").addTag("OtherIdentifyingInfo").setText("ANONYMIZED02");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("GaugeWithoutValue"));
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("StringWithoutValue"));
assertEquals(42.1, attributesByName.get("GaugeWithValue").getNumericValue().doubleValue(), 2);
assertEquals("Computer System", attributesByName.get("StringWithValue").getStringValue());
}
use of com.mycila.xmltool.XMLTag in project opennms by OpenNMS.
the class WSManCollectorTest method canCollectFromMultipleRecordsUsingFilter.
@Test
public void canCollectFromMultipleRecordsUsingFilter() {
Group group = new Group();
group.setName("DCIM_NumericSensor");
Attrib attr = new Attrib();
attr.setName("CurrentReading");
attr.setAlias("sysBoardInletTemp");
attr.setFilter("#ElementName == 'System Board Inlet Temp'");
attr.setType(AttributeType.GAUGE);
group.addAttrib(attr);
attr = new Attrib();
attr.setName("CurrentReading");
attr.setAlias("sysBoardExhaustTemp");
attr.setFilter("#ElementName == 'System Board Exhaust Temp'");
attr.setType(AttributeType.GAUGE);
group.addAttrib(attr);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_NumericSensor").addTag("CurrentReading").setText("260").addTag("ElementName").setText("System Board Inlet Temp").gotoRoot().addTag("DCIM_NumericSensor").addTag("CurrentReading").setText("370").addTag("ElementName").setText("System Board Exhaust Temp");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertEquals(Double.valueOf(260), attributesByName.get("sysBoardInletTemp").getNumericValue());
assertEquals(Double.valueOf(370), attributesByName.get("sysBoardExhaustTemp").getNumericValue());
}
Aggregations