Search in sources :

Example 11 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method testUsingFetch.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateRrds = { "test" }, anticipateMetaFiles = false)
public void testUsingFetch() throws Exception {
    System.err.println("=== testUsingFetch ===");
    File snmpDir = (File) m_context.getAttribute("rrdDirectory");
    // We initialize an empty attribute map, key=e.g OID; value=e.g. datasource name
    Map<String, String> attributeMappings = new HashMap<String, String>();
    int stepSize = 1;
    int numUpdates = 2;
    long start = System.currentTimeMillis();
    final int stepSizeInMillis = stepSize * 1000;
    final int rangeSizeInMillis = stepSizeInMillis + 20000;
    File rrdFile = new File(snmpDir, rrd("test"));
    RrdStrategy<RrdDef, RrdDb> m_rrdStrategy = new JRobinRrdStrategy();
    RrdDataSource rrdDataSource = new RrdDataSource("testAttr", RrdAttributeType.GAUGE, stepSize * 2, "U", "U");
    RrdDef def = m_rrdStrategy.createDefinition("test", snmpDir.getAbsolutePath(), "test", stepSize, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100"));
    m_rrdStrategy.createFile(def);
    RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath());
    for (int i = 0; i < numUpdates; i++) {
        m_rrdStrategy.updateFile(rrdFileObject, "test", ((start / 1000) - (stepSize * (numUpdates - i))) + ":1");
    }
    m_rrdStrategy.closeFile(rrdFileObject);
    assertEquals(Double.valueOf(1.0), m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), "testAttr", stepSizeInMillis, rangeSizeInMillis));
}
Also used : RrdDef(org.jrobin.core.RrdDef) HashMap(java.util.HashMap) RrdDb(org.jrobin.core.RrdDb) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) File(java.io.File) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method verifyPersistedStringProperties.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void verifyPersistedStringProperties() throws Exception {
    // Perform the collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    // Persist
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    // Verify results on disk
    Map<String, String> properties = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "brocadeFCPortIndex", "1"));
    // "string" attributes should convert the octets directly to a string
    String value = properties.get("swFCPortName");
    assertTrue(value.startsWith("..3DUfw"));
    // "hexstring" attributes should convert the octets to a hex string
    // see http://issues.opennms.org/browse/NMS-7367
    value = properties.get("swFCPortWwn");
    assertEquals("1100334455667788", value);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

JUnitCollector (org.opennms.core.collection.test.JUnitCollector)12 Test (org.junit.Test)11 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)8 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)7 Transactional (org.springframework.transaction.annotation.Transactional)6 File (java.io.File)4 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)2 HashMap (java.util.HashMap)1 RrdDb (org.jrobin.core.RrdDb)1 RrdDef (org.jrobin.core.RrdDef)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 RrdDataSource (org.opennms.netmgt.rrd.RrdDataSource)1 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)1 FileAnticipator (org.opennms.test.FileAnticipator)1