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));
}
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);
}
Aggregations