Search in sources :

Example 21 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.

the class SnmpMultiResponseDTOTest method getSnmpMultiResponse.

private static SnmpMultiResponseDTO getSnmpMultiResponse() {
    final SnmpValueFactory snmpValueFactory = new Snmp4JValueFactory();
    final SnmpResult result = new SnmpResult(SnmpObjId.get(".1.3.6.1.2"), new SnmpInstId(".1.3.6.1.2.1.4.34.1.3.1.2.3.4"), snmpValueFactory.getCounter64(BigInteger.TEN));
    final SnmpResponseDTO responseDTO = new SnmpResponseDTO();
    responseDTO.setCorrelationId("42");
    responseDTO.getResults().add(result);
    final SnmpMultiResponseDTO multiResponseDTO = new SnmpMultiResponseDTO();
    multiResponseDTO.getResponses().add(responseDTO);
    return multiResponseDTO;
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Snmp4JValueFactory(org.opennms.netmgt.snmp.snmp4j.Snmp4JValueFactory) SnmpResult(org.opennms.netmgt.snmp.SnmpResult)

Example 22 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.

the class TcaCollectorIT method testCollector.

/**
	 * Test collector.
	 *
	 * @throws Exception the exception
	 */
@Test
public void testCollector() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "default");
    // Create Collection Set
    TcaCollector collector = new TcaCollector();
    collector.setConfigDao(m_configDao);
    collector.setResourceStorageDao(m_resourceStorageDao);
    collector.setResourceTypesDao(m_resourceTypesDao);
    collector.setLocationAwareSnmpClient(m_client);
    CollectionSetVisitor persister = m_persisterFactory.createOneToOnePersister(new ServiceParameters(parameters), collector.getRrdRepository("default"), false, false);
    // Setup SNMP Value Handling
    SnmpValueFactory valFac = SnmpUtils.getValueFactory();
    SnmpObjId peer1 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.37.60");
    SnmpObjId peer2 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.38.70");
    // Collect and Persist Data - Step 1
    CollectionSet collectionSet = collector.collect(m_collectionAgent, parameters);
    validateCollectionSet(collectionSet);
    collectionSet.visit(persister);
    // Generate new SNMP Data
    StringBuffer sb = new StringBuffer("|25|");
    long ts = 1327451787l;
    for (int i = 0; i < 25; i++) {
        sb.append(ts++);
        sb.append(",12,-1,12,-2,1|");
    }
    // Get Current Values
    SnmpValue v1a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
    SnmpValue v2a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
    // Set New Values
    SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer1, valFac.getOctetString(sb.toString().getBytes()));
    SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer2, valFac.getOctetString(sb.toString().getBytes()));
    // Validate New Values
    SnmpValue v1b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
    SnmpValue v2b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
    Assert.assertFalse(v1a.toDisplayString().equals(v1b.toDisplayString()));
    Assert.assertFalse(v2a.toDisplayString().equals(v2b.toDisplayString()));
    // Collect and Persist Data - Step 2
    collectionSet = collector.collect(m_collectionAgent, parameters);
    validateCollectionSet(collectionSet);
    collectionSet.visit(persister);
    // Validate Persisted Data
    Path pathToJrbFile = getSnmpRoot().toPath().resolve(Paths.get("1", TcaCollectionHandler.RESOURCE_TYPE_NAME, "171.19.37.60", TcaCollectionHandler.INBOUND_DELAY + m_rrdStrategy.getDefaultFileExtension()));
    RrdDb jrb = new RrdDb(pathToJrbFile.toString());
    // According with the Fixed Step
    Assert.assertEquals(1, jrb.getArchive(0).getArcStep());
    // According with the Sample Data
    Assert.assertEquals(ts - 1, jrb.getArchive(0).getEndTime());
    Robin inboundDelay = jrb.getArchive(0).getRobin(0);
    for (int i = inboundDelay.getSize() - 49; i < inboundDelay.getSize() - 25; i++) {
        Assert.assertEquals(new Double(11), Double.valueOf(inboundDelay.getValue(i)));
    }
    for (int i = inboundDelay.getSize() - 24; i < inboundDelay.getSize(); i++) {
        Assert.assertEquals(new Double(12), Double.valueOf(inboundDelay.getValue(i)));
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) Robin(org.jrobin.core.Robin) Test(org.junit.Test)

Example 23 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.

the class SyntaxToEventTest method testProcessSyntaxWithNull.

@Test
public void testProcessSyntaxWithNull() {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    assertNotNull(valueFactory);
    byte[] macAddr = { 0x00, 0x55, 0x55, 0x55, 0x55, 0x55 };
    SnmpValue octetString = valueFactory.getOctetString(macAddr);
    Parm parm = SyntaxToEvent.processSyntax("Test", octetString);
    assertEquals("Test", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_MAC_ADDRESS, parm.getValue().getEncoding());
    assertEquals("00:55:55:55:55:55", parm.getValue().getContent());
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test)

Example 24 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.

the class SyntaxToEventTest method testProcessSyntaxForUnprintableBytes.

@Test
public void testProcessSyntaxForUnprintableBytes() {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    assertNotNull(valueFactory);
    byte[] ipAddr = { (byte) 0x4d, (byte) 0x5f, (byte) 0xf1, (byte) 0x95 };
    SnmpValue octetString = valueFactory.getOctetString(ipAddr);
    Parm parm = SyntaxToEvent.processSyntax("testOtherData", octetString);
    assertEquals("testOtherData", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_BASE64, parm.getValue().getEncoding());
    assertEquals("TV/xlQ==", parm.getValue().getContent());
    byte[] macAddr = new byte[] { (byte) 0x4c, (byte) 0x66, (byte) 0x41, (byte) 0xd9, (byte) 0x9a, (byte) 0xf6 };
    octetString = valueFactory.getOctetString(macAddr);
    parm = SyntaxToEvent.processSyntax("testSomeMacAddress", octetString);
    assertEquals("testSomeMacAddress", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_MAC_ADDRESS, parm.getValue().getEncoding());
    assertEquals("4C:66:41:D9:9A:F6", parm.getValue().getContent());
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test)

Example 25 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.

the class SyntaxToEventTest method testProcessSyntaxZeros.

@Test
public void testProcessSyntaxZeros() {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    assertNotNull(valueFactory);
    byte[] macAddr = { 000, 000, 000, 000, 000, 000 };
    SnmpValue octetString = valueFactory.getOctetString(macAddr);
    Parm parm = SyntaxToEvent.processSyntax("Test", octetString);
    assertEquals("Test", parm.getParmName());
    assertEquals("00:00:00:00:00:00", parm.getValue().getContent());
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test)

Aggregations

SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)25 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)24 Test (org.junit.Test)23 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 Parm (org.opennms.netmgt.xml.event.Parm)7 LinkedHashMap (java.util.LinkedHashMap)5 DirtiesContext (org.springframework.test.annotation.DirtiesContext)5 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)2 Event (org.opennms.netmgt.xml.event.Event)2 InetAddress (java.net.InetAddress)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Robin (org.jrobin.core.Robin)1 RrdDb (org.jrobin.core.RrdDb)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)1 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)1 MockSnmpValueFactory (org.opennms.netmgt.snmp.mock.MockSnmpValueFactory)1