Search in sources :

Example 6 with SnmpAgentConfig

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

the class Snmp4JStrategy method buildAgentConfig.

protected SnmpAgentConfig buildAgentConfig(String address, int port, String community, PDU pdu) throws UnknownHostException {
    SnmpAgentConfig config = new SnmpAgentConfig();
    config.setAddress(InetAddress.getByName(address));
    config.setPort(port);
    config.setVersion(pdu instanceof PDUv1 ? SnmpAgentConfig.VERSION1 : SnmpAgentConfig.VERSION2C);
    return config;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) PDUv1(org.snmp4j.PDUv1)

Example 7 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)

Example 8 with SnmpAgentConfig

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

the class ProxySnmpAgentConfigFactory method getAgentConfig.

@Override
public SnmpAgentConfig getAgentConfig(final InetAddress address, String location) {
    final SnmpAgentConfigProxyMapper mapper = SnmpAgentConfigProxyMapper.getInstance();
    final SnmpAgentAddress agentAddress = mapper.getAddress(address);
    final String addressString = str(address);
    if (agentAddress == null) {
        LOG.debug("No agent address mapping found for {}!  Try adding a @JUnitSnmpAgent(host=\"{}\", resource=\"...\" entry...", addressString, addressString);
        return super.getAgentConfig(address, location);
    }
    final SnmpAgentConfig config = new SnmpAgentConfig(agentAddress.getAddress());
    config.setProxyFor(address);
    config.setPort(agentAddress.getPort());
    LOG.debug("proxying {} -> {}", addressString, agentAddress);
    return config;
}
Also used : SnmpAgentAddress(org.opennms.netmgt.snmp.SnmpAgentAddress) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 9 with SnmpAgentConfig

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

the class SnmpTrapHelper method forwardV3Trap.

/**
     * Create an SNMP V3 trap based on the content of the specified trap configuration, and send it to the appropriate destination.
     *
     * @param trapConfig The trap configuration mapping object
     * @throws SnmpTrapException if any.
     */
private void forwardV3Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
    SnmpV3TrapBuilder trap = SnmpUtils.getV3TrapBuilder();
    populateTrapBuilder(trap, trapConfig);
    try {
        SnmpAgentConfig config = getAgentConfig(trapConfig);
        trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getSecurityLevel(), config.getSecurityName(), config.getAuthPassPhrase(), config.getAuthProtocol(), config.getPrivPassPhrase(), config.getPrivProtocol());
    } catch (Throwable e) {
        throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder)

Example 10 with SnmpAgentConfig

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

the class EnLinkdSnmpIT method testOspfIfTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfIfTableWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    String trackerName = "ospfIfTable";
    final List<OspfLink> links = new ArrayList<OspfLink>();
    OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {

        public void processOspfIfRow(final OspfIfRow row) {
            links.add(row.getOspfLink());
        }
    };
    try {
        m_client.walk(config, ospfIfTableTracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null);
    for (OspfLink link : links) {
        link = ipAddrTableGetter.get(link);
        assertEquals(0, link.getOspfAddressLessIndex().intValue());
        if (link.getOspfIpAddr().equals(InetAddress.getByName("192.168.100.246"))) {
            assertEquals(10101, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.252"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.10.1"))) {
            assertEquals(10, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.20.1"))) {
            assertEquals(20, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.30.1"))) {
            assertEquals(30, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.40.1"))) {
            assertEquals(40, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else {
            assertEquals(false, true);
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OspfIfTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfIfTableTracker) ArrayList(java.util.ArrayList) OspfLink(org.opennms.netmgt.model.OspfLink) OspfIpAddrTableGetter(org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

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