Search in sources :

Example 1 with OnmsSnmpCollection

use of org.opennms.netmgt.collectd.OnmsSnmpCollection 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 2 with OnmsSnmpCollection

use of org.opennms.netmgt.collectd.OnmsSnmpCollection in project opennms by OpenNMS.

the class BasePersisterTest method buildStringAttribute.

private SnmpAttribute buildStringAttribute() {
    EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes();
    m_easyMockUtils.replayAll();
    SnmpCollectionAgent agent = DefaultCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr);
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("string");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes()));
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) StringAttributeType(org.opennms.netmgt.collectd.StringAttributeType) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) MibObject(org.opennms.netmgt.config.datacollection.MibObject) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection)

Example 3 with OnmsSnmpCollection

use of org.opennms.netmgt.collectd.OnmsSnmpCollection 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);
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) ResourcePath(org.opennms.netmgt.model.ResourcePath) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) Test(org.junit.Test)

Example 4 with OnmsSnmpCollection

use of org.opennms.netmgt.collectd.OnmsSnmpCollection in project opennms by OpenNMS.

the class ThresholdingVisitorIT method createGenericIndexResourceType.

private GenericIndexResourceType createGenericIndexResourceType(SnmpCollectionAgent agent, String resourceTypeName) {
    org.opennms.netmgt.config.datacollection.ResourceType type = createIndexResourceType(agent, resourceTypeName);
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    return new GenericIndexResourceType(agent, collection, type);
}
Also used : HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType)

Example 5 with OnmsSnmpCollection

use of org.opennms.netmgt.collectd.OnmsSnmpCollection in project opennms by OpenNMS.

the class CollectionResourceWrapperIT method testInterfaceResource.

@Test
public void testInterfaceResource() throws Exception {
    // Set Defaults
    String ipAddress = "10.0.0.1";
    String ifName = "eth0";
    int ifIndex = 2;
    // Initialize Database
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    network.addNode(1, "testNode");
    network.addInterface(ipAddress);
    network.setIfAlias(ifName);
    network.setIfIndex(ifIndex);
    network.addService("ICMP");
    network.addService("SNMP");
    network.addService("HTTP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    // Create Mock Collection Agent
    SnmpCollectionAgent agent = createCollectionAgent();
    // Create SnmpIfData
    OnmsNode node = new OnmsNode();
    node.setId(agent.getNodeId());
    node.setLabel("testNode");
    node.setForeignSource(agent.getForeignSource());
    node.setForeignId(agent.getForeignId());
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, ifIndex);
    snmpIface.setIfDescr(ifName);
    snmpIface.setIfName(ifName);
    snmpIface.setIfAlias(ifName);
    snmpIface.setIfSpeed(10000000l);
    snmpIface.setPhysAddr("001122334455");
    SnmpIfData ifData = new SnmpIfData(snmpIface);
    // Creating IfResourceType
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    IfResourceType resourceType = new IfResourceType(agent, collection);
    // Creating Resource
    SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
    SnmpAttribute attribute = addAttributeToCollectionResource(resource, "ifInOctets", AttributeType.COUNTER, "ifIndex", "5000");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(attribute.getName(), attribute);
    // Create Wrapper
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    // Validations
    Assert.assertEquals(node.getId().intValue(), wrapper.getNodeId());
    // Should be the address of the SNMP Agent (Bug 3808)
    Assert.assertEquals("127.0.0.1", wrapper.getHostAddress());
    Assert.assertEquals("eth0-001122334455", wrapper.getIfLabel());
    Assert.assertEquals("if", wrapper.getResourceTypeName());
    Assert.assertEquals("SNMP", wrapper.getServiceName());
    Assert.assertEquals(true, wrapper.isAnInterfaceResource());
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getInstance());
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals("eth0", wrapper.getIfInfoValue("snmpifname"));
    Assert.assertEquals("eth0-001122334455", wrapper.getInstanceLabel());
    Assert.assertEquals("nodeSource[JUnit:T001].interfaceSnmp[eth0-001122334455]", wrapper.getResourceId().toString());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) MockNetwork(org.opennms.netmgt.mock.MockNetwork) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) MockDatabase(org.opennms.core.test.db.MockDatabase) IfInfo(org.opennms.netmgt.collectd.IfInfo) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)9 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)9 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)9 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)9 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 Test (org.junit.Test)4 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)4 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)4 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)3 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)2 Parameter (org.opennms.netmgt.config.datacollection.Parameter)2 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)2 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)2 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)2 MockDatabase (org.opennms.core.test.db.MockDatabase)1