Search in sources :

Example 1 with IfInfo

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

the class ThresholdingVisitorIT method runInterfaceResource.

private void runInterfaceResource(ThresholdingVisitor visitor, String ipAddress, String ifName, Long ifSpeed, Integer ifIndex, long v1, long v2) {
    SnmpIfData ifData = createSnmpIfData(ipAddress, ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    // Step 1
    visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime()));
    SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v1);
    addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v1);
    resource.visit(visitor);
    // Step 2 - Increment Counters
    visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime() + 300000));
    resource = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v2);
    addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v2);
    resource.visit(visitor);
    EasyMock.verify(agent);
}
Also used : IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) IfInfo(org.opennms.netmgt.collectd.IfInfo) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

Example 2 with IfInfo

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

the class ThresholdingVisitorIT method testDisabledCollection.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds-bug3428.xml
     * 
     * Updated to reflect the fact that counter are treated as rates.
     * 
     * This is related with the cutomer support ticket number 300
     */
@Test
public void testDisabledCollection() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3428.xml");
    Integer ifIndex = 1;
    Long ifSpeed = 100000000l;
    String ifName = "wlan0";
    addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString());
    // Create interface resource with data collection disabled
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, false);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    ThresholdingVisitor visitor = createVisitor();
    // Step 1 (should be ignored)
    SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", 10000);
    addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", 10000);
    resource.visit(visitor);
    // Step 2 (should be ignored) - Increment Counters; real value = (46000 - 10000)/300 = 120
    resource = new IfInfo(resourceType, agent, ifData);
    addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", 46000);
    addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", 46000);
    resource.visit(visitor);
    EasyMock.verify(agent);
    verifyEvents(1);
}
Also used : BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) IfInfo(org.opennms.netmgt.collectd.IfInfo) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) Test(org.junit.Test)

Example 3 with IfInfo

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

the class ThresholdingVisitorIT method testIgnoreAliasedResources.

/*
     * 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 testIgnoreAliasedResources() 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 = "#";
    // equals to storeByIfAlias = false
    ThresholdingVisitor visitor = createVisitor();
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    // Step 1
    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
    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 : BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) AliasedResource(org.opennms.netmgt.collectd.AliasedResource) IfInfo(org.opennms.netmgt.collectd.IfInfo) Test(org.junit.Test)

Example 4 with IfInfo

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

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

the class ThresholdingVisitorIT method runCounterWrapTest.

/*
     * Parameter expectedValue should be around 200:
     * Initial counter value is 20000 below limit.
     * Next value is 40000, so the difference will be 60000.
     * Counters are treated as rates so 60000/300 is 200.
     */
private void runCounterWrapTest(double bits, double expectedValue) throws Exception {
    Integer ifIndex = 1;
    Long ifSpeed = 10000000l;
    String ifName = "wlan0";
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3194.xml");
    addHighThresholdEvent(1, 100, 90, expectedValue, ifName, "1", "ifOutOctets", ifName, ifIndex.toString());
    ThresholdingVisitor visitor = createVisitor();
    // Creating Interface Resource Type
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    // Creating Data Source
    MibObject object = createMibObject("counter", "ifOutOctets", "ifIndex");
    SnmpAttributeType objectType = new NumericAttributeType(resourceType, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    long timestamp = new Date().getTime();
    // Step 1 - Initialize Counter
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
    BigDecimal n = new BigDecimal(Math.pow(2, bits) - 20000);
    SnmpValue snmpValue1 = SnmpUtils.getValueFactory().getCounter64(n.toBigInteger());
    SnmpCollectionResource resource1 = new IfInfo(resourceType, agent, ifData);
    resource1.setAttributeValue(objectType, snmpValue1);
    resource1.visit(visitor);
    // Step 2 - Wrap Counter
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
    SnmpValue snmpValue2 = SnmpUtils.getValueFactory().getCounter64(new BigInteger("40000"));
    SnmpCollectionResource resource2 = new IfInfo(resourceType, agent, ifData);
    resource2.setAttributeValue(objectType, snmpValue2);
    resource2.visit(visitor);
    // Verify Events
    EasyMock.verify(agent);
    verifyEvents(0);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) BigInteger(java.math.BigInteger) IfInfo(org.opennms.netmgt.collectd.IfInfo) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

Aggregations

IfInfo (org.opennms.netmgt.collectd.IfInfo)6 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)6 SnmpIfData (org.opennms.netmgt.collectd.SnmpIfData)6 BigInteger (java.math.BigInteger)4 Test (org.junit.Test)4 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 AliasedResource (org.opennms.netmgt.collectd.AliasedResource)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 BigDecimal (java.math.BigDecimal)1 MockDatabase (org.opennms.core.test.db.MockDatabase)1 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)1 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)1 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)1 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)1 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)1 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1