Search in sources :

Example 11 with MibObject

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

the class DefaultDataCollectionConfigDao method processObjectList.

/**
     * Takes a list of MibObj objects iterates over them
     * creating corresponding MibObject objects and adding them to the supplied
     * MibObject list.
     * @param groupName TODO
     * @param groupIfType TODO
     * @param objectList
     *            List of MibObject objects parsed from
     *            'datacollection-config.xml'
     * @param mibObjectList
     *            List of MibObject objects currently being built
     */
private void processObjectList(final String groupName, final String groupIfType, final List<MibObj> objectList, final List<MibObject> mibObjectList) {
    for (final MibObj mibObj : objectList) {
        // Create a MibObject from the XML MibObj
        final MibObject aMibObject = new MibObject();
        aMibObject.setGroupName(groupName);
        aMibObject.setGroupIfType(groupIfType);
        aMibObject.setOid(mibObj.getOid());
        aMibObject.setAlias(mibObj.getAlias());
        aMibObject.setType(mibObj.getType());
        aMibObject.setInstance(mibObj.getInstance());
        aMibObject.setMaxval(mibObj.getMaxval());
        aMibObject.setMinval(mibObj.getMinval());
        final ResourceType resourceType = getConfiguredResourceTypes().get(mibObj.getInstance());
        if (resourceType != null) {
            aMibObject.setResourceType(resourceType);
        }
        // Add the MIB object provided it isn't already in the list
        if (!mibObjectList.contains(aMibObject)) {
            mibObjectList.add(aMibObject);
        }
    }
}
Also used : ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) MibObj(org.opennms.netmgt.config.datacollection.MibObj) MibObject(org.opennms.netmgt.config.datacollection.MibObject)

Example 12 with MibObject

use of org.opennms.netmgt.config.datacollection.MibObject 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)

Example 13 with MibObject

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

the class ThresholdingVisitorIT method addAttributeToCollectionResource.

private static void addAttributeToCollectionResource(SnmpCollectionResource resource, ResourceType type, String attributeName, String attributeType, String attributeInstance, long value) {
    MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
    SnmpAttributeType objectType = new NumericAttributeType(type, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    SnmpValue snmpValue = attributeType.equals("counter") ? SnmpUtils.getValueFactory().getCounter32(value) : SnmpUtils.getValueFactory().getGauge32(value);
    resource.setAttributeValue(objectType, snmpValue);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Example 14 with MibObject

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

the class DataCollectionConfigFactoryTest method testSetInstance.

@Test
public void testSetInstance() throws IOException {
    initDataCollectionFactory(m_xml);
    assertEquals(m_rrdRepository.getAbsolutePath(), DataCollectionConfigFactory.getInstance().getRrdPath());
    assertEquals(0, DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.9.9.9.9", "127.0.0.1", 0).size());
    for (MibObject object : DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.3.6.1.4.1.200", "127.0.0.1", 0)) {
        assertEquals("Invalid MibObject: " + object, "ifIndex", object.getInstance());
    }
    assertArrayEquals(new String[0], DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().keySet().toArray(new String[0]));
}
Also used : MibObject(org.opennms.netmgt.config.datacollection.MibObject) Test(org.junit.Test)

Example 15 with MibObject

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

the class DataCollectionConfigFactoryTest method testValidResourceType.

@Test
public void testValidResourceType() throws IOException {
    String modifiedXml = m_xml.replaceFirst("ifIndex", "brocadeIndex").replaceFirst("<groups", m_brocadeXmlFragment + "<groups");
    initDataCollectionFactory(modifiedXml);
    assertEquals(m_rrdRepository.getAbsolutePath(), DataCollectionConfigFactory.getInstance().getRrdPath());
    assertEquals(0, DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.9.9.9.9", "127.0.0.1", 0).size());
    List<MibObject> mibObjects = DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.3.6.1.4.1.200", "127.0.0.1", 0);
    // Make sure that the first value was edited as intended
    MibObject first = mibObjects.remove(0);
    assertEquals("Invalid MibObject: " + first, "brocadeIndex", first.getInstance());
    for (MibObject object : mibObjects) {
        assertEquals("Invalid MibObject: " + object, "ifIndex", object.getInstance());
    }
    assertArrayEquals(new String[] { "brocadeIndex" }, DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().keySet().toArray(new String[0]));
}
Also used : MibObject(org.opennms.netmgt.config.datacollection.MibObject) Test(org.junit.Test)

Aggregations

MibObject (org.opennms.netmgt.config.datacollection.MibObject)25 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)16 Test (org.junit.Test)9 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)9 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)8 HashMap (java.util.HashMap)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)6 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)6 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)6 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)5 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)5 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)5 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5 Date (java.util.Date)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)4 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)4 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)3 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)3 RrdPersistOperationBuilder (org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder)3