Search in sources :

Example 1 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 2 with SnmpAgentConfig

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

the class Snmp4JV2TrapBuilder method send.

@Override
public void send(String destAddr, int destPort, String community) throws Exception {
    SnmpAgentConfig snmpAgentConfig = m_strategy.buildAgentConfig(destAddr, destPort, community, m_pdu);
    Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(snmpAgentConfig);
    m_strategy.send(agentConfig, m_pdu, false);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 3 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 4 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 5 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)

Aggregations

SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)117 Test (org.junit.Test)31 InetAddress (java.net.InetAddress)30 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)23 ArrayList (java.util.ArrayList)22 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)21 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)20 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)4 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4