Search in sources :

Example 86 with SnmpAgentConfig

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

the class NodeDiscoveryOspf method runCollection.

protected void runCollection() {
    final Date now = new Date();
    SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
    final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
    final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfGeneralGroup).withDescription("ospfGeneralGroup").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: Agent error while scanning the ospfGeneralGroup table", e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: Ospf Linkd node collection interrupted, exiting", e);
        return;
    }
    if (ospfGeneralGroup.getOspfRouterId() == null) {
        LOG.info("run: node[{}]: address {}. ospf mib not supported", getNodeId(), getPrimaryIpAddressString());
        return;
    }
    if (ospfGeneralGroup.getOspfRouterId().equals(InetAddressUtils.addr("0.0.0.0"))) {
        LOG.info("run: node[{}]: address {}. ospf identifier 0.0.0.0 is not valid", getNodeId(), getPrimaryIpAddressString());
        return;
    }
    if (Status.get(ospfGeneralGroup.getOspfAdminStat()) == Status.disabled) {
        LOG.info("run: node[{}]: address {}. ospf status: disabled", getNodeId(), getPrimaryIpAddressString());
        return;
    }
    m_linkd.getQueryManager().store(getNodeId(), ipAddrTableGetter.get(ospfGeneralGroup.getOspfElement()));
    final List<OspfLink> links = new ArrayList<OspfLink>();
    OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {

        public void processOspfNbrRow(final OspfNbrRow row) {
            links.add(row.getOspfLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfNbrTableTracker).withDescription("ospfNbrTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.error("run: collection execution failed, exiting", e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    List<OspfLink> localOspfPorts = new ArrayList<OspfLink>();
    OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {

        public void processOspfIfRow(final OspfIfRow row) {
            localOspfPorts.add(row.getOspfLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfIfTableTracker).withDescription("ospfIfTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.error("run: collection execution failed, exiting", e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    for (OspfLink link : links) {
        for (OspfLink localospfport : localOspfPorts) {
            localospfport = ipAddrTableGetter.get(localospfport);
            if (InetAddressUtils.inSameNetwork(localospfport.getOspfIpAddr(), link.getOspfRemIpAddr(), localospfport.getOspfIpMask())) {
                link.setOspfIpAddr(localospfport.getOspfIpAddr());
                link.setOspfAddressLessIndex(localospfport.getOspfAddressLessIndex());
                link.setOspfIpMask(localospfport.getOspfIpMask());
                link.setOspfIfIndex(localospfport.getOspfIfIndex());
            }
        }
        m_linkd.getQueryManager().store(getNodeId(), link);
    }
    m_linkd.getQueryManager().reconcileOspf(getNodeId(), now);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OspfIfTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfIfTableTracker) ArrayList(java.util.ArrayList) OspfNbrTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker) Date(java.util.Date) OspfIpAddrTableGetter(org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter) OspfGeneralGroupTracker(org.opennms.netmgt.enlinkd.snmp.OspfGeneralGroupTracker) ExecutionException(java.util.concurrent.ExecutionException) OspfLink(org.opennms.netmgt.model.OspfLink)

Example 87 with SnmpAgentConfig

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

the class NodeDiscoveryCdp method runCollection.

protected void runCollection() {
    final Date now = new Date();
    final CdpGlobalGroupTracker cdpGlobalGroup = new CdpGlobalGroupTracker();
    SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, cdpGlobalGroup).withDescription("cdpGlobalGroup").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: Agent error while scanning the cdpGlobalGroup table", getNodeId(), e);
        return;
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: Cdp cdpGlobalGroup collection interrupted, exiting", getNodeId(), e);
        return;
    }
    if (cdpGlobalGroup.getCdpDeviceId() == null) {
        LOG.info("run: node [{}]: CDP_MIB not supported", getNodeId());
        return;
    }
    CdpElement cdpElement = cdpGlobalGroup.getCdpElement();
    m_linkd.getQueryManager().store(getNodeId(), cdpElement);
    if (cdpElement.getCdpGlobalRun() == TruthValue.FALSE) {
        LOG.info("run: node [{}]. CDP disabled.", getNodeId());
        return;
    }
    List<CdpLink> links = new ArrayList<CdpLink>();
    CdpCacheTableTracker cdpCacheTable = new CdpCacheTableTracker() {

        public void processCdpCacheRow(final CdpCacheRow row) {
            links.add(row.getLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, cdpCacheTable).withDescription("cdpCacheTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.error("run: node [{}]: collection execution failed, exiting", getNodeId(), e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: node [{}]: Cdp Linkd collection interrupted, exiting", getNodeId(), e);
        return;
    }
    final CdpInterfacePortNameGetter cdpInterfacePortNameGetter = new CdpInterfacePortNameGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
    for (CdpLink link : links) m_linkd.getQueryManager().store(getNodeId(), cdpInterfacePortNameGetter.get(link));
    m_linkd.getQueryManager().reconcileCdp(getNodeId(), now);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) CdpInterfacePortNameGetter(org.opennms.netmgt.enlinkd.snmp.CdpInterfacePortNameGetter) CdpCacheTableTracker(org.opennms.netmgt.enlinkd.snmp.CdpCacheTableTracker) ArrayList(java.util.ArrayList) CdpGlobalGroupTracker(org.opennms.netmgt.enlinkd.snmp.CdpGlobalGroupTracker) ExecutionException(java.util.concurrent.ExecutionException) CdpLink(org.opennms.netmgt.model.CdpLink) Date(java.util.Date) CdpElement(org.opennms.netmgt.model.CdpElement)

Example 88 with SnmpAgentConfig

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

the class EnLinkdSnmpIT method testOspfNbrTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfNbrTableWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    String trackerName = "ospfNbrTable";
    OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {

        public void processOspfNbrRow(final OspfNbrRow row) {
            OspfLink link = row.getOspfLink();
            try {
                assertEquals(InetAddress.getByName("192.168.100.249"), link.getOspfRemRouterId());
                assertEquals(InetAddress.getByName("192.168.100.245"), link.getOspfRemIpAddr());
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            assertEquals(0, link.getOspfRemAddressLessIndex().intValue());
        }
    };
    try {
        m_client.walk(config, ospfNbrTableTracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) UnknownHostException(java.net.UnknownHostException) OspfNbrTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker) OspfLink(org.opennms.netmgt.model.OspfLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 89 with SnmpAgentConfig

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

the class EnLinkdSnmpIT method testOspfGeneralGroupWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfGeneralGroupWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    String trackerName = "ospfGeneralGroup";
    final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
    try {
        m_client.walk(config, ospfGeneralGroup).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    OspfElement ospfElement = ospfGeneralGroup.getOspfElement();
    assertEquals(InetAddress.getByName("192.168.100.246"), ospfElement.getOspfRouterId());
    assertEquals(null, ospfElement.getOspfRouterIdNetmask());
    assertEquals(null, ospfElement.getOspfRouterIdIfindex());
    assertEquals(Status.enabled, ospfElement.getOspfAdminStat());
    assertEquals(2, ospfElement.getOspfVersionNumber().intValue());
    assertEquals(TruthValue.FALSE, ospfElement.getOspfBdrRtrStatus());
    assertEquals(TruthValue.FALSE, ospfElement.getOspfASBdrRtrStatus());
    final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null);
    OspfElement ospfElementN = ipAddrTableGetter.get(ospfElement);
    assertEquals(InetAddress.getByName("192.168.100.246"), ospfElementN.getOspfRouterId());
    assertEquals(InetAddress.getByName("255.255.255.252"), ospfElementN.getOspfRouterIdNetmask());
    assertEquals(10101, ospfElementN.getOspfRouterIdIfindex().intValue());
    assertEquals(Status.enabled, ospfElementN.getOspfAdminStat());
    assertEquals(2, ospfElementN.getOspfVersionNumber().intValue());
    assertEquals(TruthValue.FALSE, ospfElementN.getOspfBdrRtrStatus());
    assertEquals(TruthValue.FALSE, ospfElementN.getOspfASBdrRtrStatus());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OspfElement(org.opennms.netmgt.model.OspfElement) OspfGeneralGroupTracker(org.opennms.netmgt.enlinkd.snmp.OspfGeneralGroupTracker) OspfIpAddrTableGetter(org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 90 with SnmpAgentConfig

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

the class EnLinkdSnmpIT method test2LldpLocGetter.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH2_IP, port = 161, resource = "classpath:/linkd/nms17216/switch2-walk.txt") })
public void test2LldpLocGetter() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH2_IP));
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
    LldpLink link = new LldpLink();
    link.setLldpLocalPortNum(1);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(1, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/1", link.getLldpPortId());
    assertEquals("GigabitEthernet0/1", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
    link = new LldpLink();
    link.setLldpLocalPortNum(2);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(2, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/2", link.getLldpPortId());
    assertEquals("GigabitEthernet0/2", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) 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