Search in sources :

Example 1 with Parameter

use of org.opennms.netmgt.config.datacollection.Parameter in project opennms by OpenNMS.

the class ResourceDaoIntegrityIT method createResourceTypes.

/**
     * Define a resource type so that test the GenericIndexResourceType
     */
private Map<String, ResourceType> createResourceTypes() {
    Map<String, ResourceType> types = new HashMap<String, ResourceType>();
    ResourceType hrStorageIndex = new ResourceType();
    hrStorageIndex.setName("hrStorageIndex");
    hrStorageIndex.setLabel("Storage (SNMP MIB-2 Host Resources)");
    hrStorageIndex.setResourceLabel("${hrStorageDescr}");
    hrStorageIndex.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collectd.PersistAllSelectorStrategy"));
    StorageStrategy storageStrategy = new StorageStrategy("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    storageStrategy.addParameter(new Parameter("sibling-column-name", "hrStorageDescr"));
    storageStrategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/^-//"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/\\s//"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
    hrStorageIndex.setStorageStrategy(storageStrategy);
    types.put(hrStorageIndex.getName(), hrStorageIndex);
    return types;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) HashMap(java.util.HashMap) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 2 with Parameter

use of org.opennms.netmgt.config.datacollection.Parameter in project opennms by OpenNMS.

the class CollectionResourceWrapperIT method testNumericFields.

@Test
public void testNumericFields() throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    ResourceType rt = new ResourceType();
    rt.setName("dskIndex");
    rt.setLabel("Disk Table Index (UCD-SNMP MIB)");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    strategy.addParameter(new Parameter("sibling-column-name", "ns-dskPath"));
    strategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
    strategy.addParameter(new Parameter("replace-all", "s/^-//"));
    strategy.addParameter(new Parameter("replace-all", "s/\\s//"));
    strategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(pstrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
    SnmpAttribute total = addAttributeToCollectionResource(resource, "ns-dskTotal", AttributeType.GAUGE, "dskIndex", "10000");
    SnmpAttribute used = addAttributeToCollectionResource(resource, "ns-dskUsed", AttributeType.GAUGE, "dskIndex", "5000");
    SnmpAttribute label = addAttributeToCollectionResource(resource, "ns-dskPath", AttributeType.STRING, "dskIndex", "/opt");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(used.getName(), used);
    attributes.put(total.getName(), total);
    attributes.put(label.getName(), label);
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    Assert.assertEquals("opt", wrapper.getInstanceLabel());
    Assert.assertEquals(new Double("10000.0"), wrapper.getAttributeValue(total.getName()));
    Assert.assertEquals("10000.0", wrapper.getFieldValue(total.getName()));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 3 with Parameter

use of org.opennms.netmgt.config.datacollection.Parameter in project opennms by OpenNMS.

the class PersistRegexSelectorStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
    String localhost = InetAddress.getLocalHost().getHostAddress();
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("myNode");
    builder.addInterface(localhost).setIsManaged("M").setIsSnmpPrimary("P");
    OnmsNode node = builder.getCurrentNode();
    node.setId(1);
    OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next();
    EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes();
    EasyMock.replay(ipInterfaceDao);
    Package pkg = new Package();
    pkg.setName("junitTestPackage");
    Filter filter = new Filter();
    filter.setContent("IPADDR != '0.0.0.0'");
    pkg.setFilter(filter);
    Service service = new Service();
    service.setName("SNMP");
    pkg.addService(service);
    Map<String, Object> map = new TreeMap<String, Object>();
    List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters();
    for (org.opennms.netmgt.config.collectd.Parameter p : params) {
        map.put(p.getKey(), p.getValue());
    }
    map.put("collection", "default");
    serviceParams = new ServiceParameters(map);
    LocationAwareSnmpClient locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory());
    PlatformTransactionManager ptm = new MockPlatformTransactionManager();
    SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ipInterfaceDao, ptm);
    OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, serviceParams, new MockDataCollectionConfigDao(), locationAwareSnmpClient);
    org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
    rt.setName("myResourceType");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
    rt.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz("org.opennms.netmgt.collectd.PersistRegexSelectorStrategy");
    Parameter param = new Parameter();
    param.setKey(PersistRegexSelectorStrategy.MATCH_EXPRESSION);
    param.setValue("#name matches '^agalue.*$'");
    persistenceSelectorStrategy.addParameter(param);
    rt.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, snmpCollection, rt);
    resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));
    AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
    mibObject.setInstance("1");
    mibObject.setAlias("name");
    mibObject.setType("string");
    StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType);
    SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
    resourceA.setAttributeValue(attributeType, snmpValue);
    resourceB = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.2"));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) Snmp4JValueFactory(org.opennms.netmgt.snmp.snmp4j.Snmp4JValueFactory) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) LocationAwareSnmpClientRpcImpl(org.opennms.netmgt.snmp.proxy.common.LocationAwareSnmpClientRpcImpl) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) MockDataCollectionConfigDao(org.opennms.netmgt.dao.mock.MockDataCollectionConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) Service(org.opennms.netmgt.config.collectd.Service) TreeMap(java.util.TreeMap) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) MockRpcClientFactory(org.opennms.core.rpc.mock.MockRpcClientFactory) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Filter(org.opennms.netmgt.config.collectd.Filter) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Parameter(org.opennms.netmgt.config.datacollection.Parameter) MibObject(org.opennms.netmgt.config.datacollection.MibObject) Package(org.opennms.netmgt.config.collectd.Package) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Before(org.junit.Before)

Example 4 with Parameter

use of org.opennms.netmgt.config.datacollection.Parameter 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()));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) Arrays(java.util.Arrays) CollectionStatus(org.opennms.netmgt.collection.api.CollectionStatus) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InetAddrUtils(org.opennms.netmgt.snmp.InetAddrUtils) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) Supplier(java.util.function.Supplier) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) XMLDoc(com.mycila.xmltool.XMLDoc) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) CollectionException(org.opennms.netmgt.collection.api.CollectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Node(org.w3c.dom.Node) AttributeType(org.opennms.netmgt.collection.api.AttributeType) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Collection(org.opennms.netmgt.config.wsman.Collection) Attrib(org.opennms.netmgt.config.wsman.Attrib) OnmsNode(org.opennms.netmgt.model.OnmsNode) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) XMLTag(com.mycila.xmltool.XMLTag) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Group(org.opennms.netmgt.config.wsman.Group) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Definition(org.opennms.netmgt.config.wsman.Definition) Matchers.any(org.mockito.Matchers.any) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) List(java.util.List) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) Assert.assertFalse(org.junit.Assert.assertFalse) CollectionSetUtils(org.opennms.core.collection.test.CollectionSetUtils) ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Group(org.opennms.netmgt.config.wsman.Group) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) XMLTag(com.mycila.xmltool.XMLTag) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Parameter(org.opennms.netmgt.config.datacollection.Parameter) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 5 with Parameter

use of org.opennms.netmgt.config.datacollection.Parameter in project opennms by OpenNMS.

the class SiblingColumnStorageStrategyTest method createParameter.

private Parameter createParameter(String key, String value) {
    Parameter p = new Parameter();
    p.setKey(key);
    p.setValue(value);
    return p;
}
Also used : Parameter(org.opennms.netmgt.config.datacollection.Parameter)

Aggregations

Parameter (org.opennms.netmgt.config.datacollection.Parameter)6 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)5 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)5 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)2 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)2 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)2 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)2 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)2 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)2 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)2 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)2 Maps (com.google.common.collect.Maps)1 XMLDoc (com.mycila.xmltool.XMLDoc)1 XMLTag (com.mycila.xmltool.XMLTag)1