Search in sources :

Example 11 with SnmpAgentConfig

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

the class ShowConfigCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    final InetAddress agentAdress = InetAddress.getByName(m_host);
    final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(agentAdress, m_location);
    System.out.println("Address: " + InetAddrUtils.str(agent.getAddress()));
    System.out.println("ProxyForAddress: " + InetAddrUtils.str(agent.getProxyFor()));
    System.out.println("Port: " + agent.getPort());
    System.out.println("Timeout: " + agent.getTimeout());
    System.out.println("Retries: " + agent.getTimeout());
    System.out.println("MaxVarsPerPdu: " + agent.getMaxVarsPerPdu());
    System.out.println("MaxRepetitions: " + agent.getMaxRepetitions());
    System.out.println("MaxRequestSize: " + agent.getMaxRequestSize());
    System.out.println("Version: " + agent.getVersionAsString());
    // the credentials in this context
    if (agent.isVersion3()) {
        System.out.println("SecurityLevel: " + agent.getSecurityLevel());
        System.out.println("SecurityName: " + agent.getSecurityName());
        System.out.println("AuthPassPhrase: " + agent.getAuthPassPhrase());
        System.out.println("AuthProtocol: " + agent.getAuthProtocol());
        System.out.println("PrivPassphrase: " + agent.getPrivPassPhrase());
        System.out.println("PrivProtocol: " + agent.getPrivProtocol());
        System.out.println("ContextName: " + agent.getContextName());
        System.out.println("EngineId: " + agent.getEngineId());
        System.out.println("ContextEngineId: " + agent.getContextEngineId());
        System.out.println("EnterpriseId: " + agent.getEnterpriseId());
    } else {
        System.out.println("ReadCommunity: " + agent.getReadCommunity());
        System.out.println("WriteCommunity: " + agent.getWriteCommunity());
    }
    System.out.println();
    return null;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) InetAddress(java.net.InetAddress)

Example 12 with SnmpAgentConfig

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

the class MockSnmpStrategyTest method testSetMultipleBadAgent.

@Test
public void testSetMultipleBadAgent() throws Exception {
    final SnmpAgentConfig sac = getAgentConfig();
    sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
    final SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
    final SnmpValue[] values = new SnmpValue[] { m_strategy.getValueFactory().getInt32(4), m_strategy.getValueFactory().getGauge32(5) };
    m_strategy.set(sac, oids, values);
    final SnmpValue[] results = m_strategy.get(sac, oids);
    assertNotNull(results);
    assertEquals(2, results.length);
    assertNull(results[0]);
    assertNull(results[1]);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Example 13 with SnmpAgentConfig

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

the class MockSnmpStrategyTest method testSetBadAgent.

@Test
public void testSetBadAgent() throws Exception {
    final SnmpAgentConfig sac = getAgentConfig();
    sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
    m_strategy.set(sac, SnmpObjId.get(".1.3.5.1.1.3.0"), m_strategy.getValueFactory().getInt32(4));
    final SnmpValue result = m_strategy.get(sac, SnmpObjId.get(".1.3.5.1.1.3.0"));
    assertNull(result);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 14 with SnmpAgentConfig

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

the class MockSnmpStrategyTest method testTrackerTimeout.

@Test
public void testTrackerTimeout() throws Exception {
    final CountingColumnTracker ct = new CountingColumnTracker(SnmpObjId.get(".1.3.5.1.1"));
    final SnmpAgentConfig sac = getAgentConfig();
    sac.setPort(12345);
    try (final SnmpWalker walker = SnmpUtils.createWalker(sac, "test", ct)) {
        assertNotNull(walker);
        walker.start();
        walker.waitFor();
    }
    assertEquals("it should match no columns (timeout)", Long.valueOf(0).longValue(), ct.getCount());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpWalker(org.opennms.netmgt.snmp.SnmpWalker) Test(org.junit.Test)

Example 15 with SnmpAgentConfig

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

the class SnmpRequestDTOTest method getSnmpWalkRequest.

private static SnmpRequestDTO getSnmpWalkRequest() throws UnknownHostException {
    final SnmpAgentConfig agent = new SnmpAgentConfig();
    agent.setAddress(InetAddress.getByName("192.168.0.2"));
    final SnmpWalkRequestDTO walkRequest = new SnmpWalkRequestDTO();
    walkRequest.setCorrelationId("42");
    walkRequest.setMaxRepetitions(4);
    walkRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "3"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "5"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "4")));
    SnmpWalkRequestDTO singleInstanceWalkRequest = new SnmpWalkRequestDTO();
    singleInstanceWalkRequest.setCorrelationId("43");
    singleInstanceWalkRequest.setInstance(SnmpInstId.INST_ZERO);
    singleInstanceWalkRequest.setOids(Lists.newArrayList(SnmpObjId.get(".1.3.6.1.2.1.3.1.3")));
    final SnmpGetRequestDTO getRequest = new SnmpGetRequestDTO();
    getRequest.setCorrelationId("44");
    getRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.3.1.3"), "0")));
    final SnmpRequestDTO snmpRequest = new SnmpRequestDTO();
    snmpRequest.setDescription("some random oids");
    snmpRequest.setLocation("dc2");
    snmpRequest.setAgent(agent);
    snmpRequest.setWalkRequests(Lists.newArrayList(walkRequest, singleInstanceWalkRequest));
    snmpRequest.setGetRequests(Lists.newArrayList(getRequest));
    return snmpRequest;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Aggregations

SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)120 InetAddress (java.net.InetAddress)31 Test (org.junit.Test)31 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)23 ArrayList (java.util.ArrayList)22 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)21 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)16 PollStatus (org.opennms.netmgt.poller.PollStatus)14 Map (java.util.Map)11 ExecutionException (java.util.concurrent.ExecutionException)9 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)8 Date (java.util.Date)7 LldpLink (org.opennms.netmgt.model.LldpLink)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 HashMap (java.util.HashMap)6 List (java.util.List)5 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4