Search in sources :

Example 26 with SnmpCollectionAgent

use of org.opennms.netmgt.collectd.SnmpCollectionAgent 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)

Example 27 with SnmpCollectionAgent

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

the class CollectionResourceWrapperIT method testGetCounterValueWithWrap.

@Test
public void testGetCounterValueWithWrap() throws Exception {
    // Create Resource
    SnmpCollectionAgent agent = createCollectionAgent();
    SnmpCollectionResource resource = createNodeResource(agent);
    // We manipulate the Date objects passed to the
    // CollectionResourceWrapper to simulate various collection intervals
    Date baseDate = new Date();
    // Add Counter Attribute
    String attributeName = "myCounter";
    String attributeId = "node[1].resourceType[node].instance[null].metric[" + attributeName + "]";
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    BigInteger initialValue = new BigDecimal(Math.pow(2, 32) - 20000).toBigInteger();
    SnmpAttribute attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", initialValue);
    attributes.put(attribute.getName(), attribute);
    // Get counter value - first time
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes, baseDate);
    Assert.assertFalse(CollectionResourceWrapper.s_cache.containsKey(attributeId));
    // Last value is null
    Assert.assertEquals(Double.valueOf(Double.NaN), wrapper.getAttributeValue(attributeName));
    // Last value is null
    Assert.assertEquals(Double.valueOf(Double.NaN), wrapper.getAttributeValue(attributeName));
    Assert.assertEquals(Double.valueOf(initialValue.doubleValue()), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
    // Increase counter
    attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", new BigInteger("40000"));
    attributes.put(attribute.getName(), attribute);
    wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 300000));
    // Get counter value - second time (wrap)
    // last = MAX - 20000, new = 40000; then last - new = 60000, rate: 60000/300 = 200
    Assert.assertEquals(Double.valueOf(initialValue.doubleValue()), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
    Assert.assertEquals(Double.valueOf(200.0), wrapper.getAttributeValue(attributeName));
    Assert.assertEquals(Double.valueOf(40000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
    Assert.assertEquals(Double.valueOf(200.0), wrapper.getAttributeValue(attributeName));
    Assert.assertEquals(Double.valueOf(40000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
    Assert.assertEquals(Double.valueOf(200.0), wrapper.getAttributeValue(attributeName));
    Assert.assertEquals(Double.valueOf(40000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
    EasyMock.verify(agent);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) BigInteger(java.math.BigInteger) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 28 with SnmpCollectionAgent

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

the class CollectionResourceWrapperIT method testGenericResource.

@Test
public void testGenericResource() 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("hrStorageIndex");
    rt.setLabel("host-resources storage");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    strategy.addParameter(new Parameter("sibling-column-name", "hrStorageLabel"));
    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 used = addAttributeToCollectionResource(resource, "hrStorageUsed", AttributeType.GAUGE, "hrStorageIndex", "5000");
    SnmpAttribute label = addAttributeToCollectionResource(resource, "hrStorageLabel", AttributeType.STRING, "hrStorageIndex", "/opt");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(used.getName(), used);
    attributes.put(label.getName(), label);
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    Assert.assertEquals("opt", wrapper.getInstanceLabel());
}
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 29 with SnmpCollectionAgent

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

the class ThresholdingVisitorIT method testBug3664.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds-bug3664.xml
     * 
     * Updated to reflect the fact that counter are treated as rates.
     */
@Test
public void testBug3664() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3664.xml");
    Integer ifIndex = 1;
    Long ifSpeed = 10000000l;
    String ifName = "wlan0";
    String domain = "myDomain";
    String ifAlias = ifName;
    String ifAliasComment = "#";
    String label = domain + "/" + ifAlias;
    addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifOutOctets", label, ifIndex.toString());
    addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifInOctets", label, ifIndex.toString());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("thresholding-enabled", "true");
    params.put("storeByIfAlias", "true");
    ThresholdingVisitor visitor = createVisitor(params);
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    long timestamp = new Date().getTime();
    // Step 1
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
    IfInfo ifInfo = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 10000);
    addAttributeToCollectionResource(ifInfo, resourceType, "ifOutOctets", "counter", "ifIndex", 10000);
    AliasedResource resource = new AliasedResource(resourceType, domain, ifInfo, ifAliasComment, ifAlias);
    resource.visit(visitor);
    // Step 2 - Increment Counters
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
    ifInfo = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 46000);
    addAttributeToCollectionResource(ifInfo, resourceType, "ifOutOctets", "counter", "ifIndex", 46000);
    resource = new AliasedResource(resourceType, domain, ifInfo, ifAliasComment, ifAlias);
    resource.visit(visitor);
    EasyMock.verify(agent);
    verifyEvents(0);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) Date(java.util.Date) BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) AliasedResource(org.opennms.netmgt.collectd.AliasedResource) MibObject(org.opennms.netmgt.config.datacollection.MibObject) IfInfo(org.opennms.netmgt.collectd.IfInfo) Test(org.junit.Test)

Example 30 with SnmpCollectionAgent

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

the class ThresholdingVisitorIT method testBug3227.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds-bug3227.xml
     * 
     * There is no Frame Relay related thresholds definitions on test-thresholds-bug3227.xml.
     * When visit resources, getEntityMap from ThresholdingSet must be null.
     * Updated to reflect the fact that counter are treated as rates.
     */
@Test
public void testBug3227() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3227.xml");
    ThresholdingVisitor visitor = createVisitor();
    SnmpCollectionAgent agent = createCollectionAgent();
    GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "frCircuitIfIndex");
    // Creating Resource
    SnmpInstId inst = new SnmpInstId(100);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, "frCircuitIfIndex", inst);
    addAttributeToCollectionResource(resource, resourceType, "frReceivedOctets", "counter", "frCircuitIfIndex", 1000);
    addAttributeToCollectionResource(resource, resourceType, "frSentOctets", "counter", "frCircuitIfIndex", 1000);
    /*
         * Run Visitor
         * I must receive 2 special info events because getEntityMap should be called 2 times.
         * One for each attribute and one for each resource.
         * Original code will throw a NullPointerException after call getEntityMap.
         * Original code expects WARNs, but this message is now an INFO.
         */
    resource.visit(visitor);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) Test(org.junit.Test)

Aggregations

SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)30 Test (org.junit.Test)22 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)22 HashMap (java.util.HashMap)13 Date (java.util.Date)10 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)10 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)10 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)9 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)8 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)8 MibObject (org.opennms.netmgt.config.datacollection.MibObject)7 BigInteger (java.math.BigInteger)6 IfInfo (org.opennms.netmgt.collectd.IfInfo)6 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)6 SnmpIfData (org.opennms.netmgt.collectd.SnmpIfData)6 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)6 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)5 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)5 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)5 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)5