private void updateSnmpDataForSnmpInterfaces() {
    if (m_collector != null && m_collector.hasIfTable()) {

      for (IfTableEntry entry : m_collector.getIfTable()) {

        Integer ifIndex = entry.getIfIndex();

        if (ifIndex == null) continue;

        LOG.debug("Updating SNMP Interface with ifIndex {}", ifIndex);

        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = m_node.getSnmpInterfaceWithIfIndex(ifIndex);

        if (snmpIf == null) {
          // if not then create one
          snmpIf = new OnmsSnmpInterface(m_node, ifIndex);
        }

        snmpIf.setIfAlias(m_collector.getIfAlias(ifIndex));
        snmpIf.setIfName(m_collector.getIfName(ifIndex));
        snmpIf.setIfType(getIfType(ifIndex));
        snmpIf.setNetMask(getNetMask(ifIndex));
        snmpIf.setIfAdminStatus(getAdminStatus(ifIndex));
        snmpIf.setIfDescr(m_collector.getIfDescr(ifIndex));
        snmpIf.setIfSpeed(m_collector.getInterfaceSpeed(ifIndex));
        snmpIf.setPhysAddr(m_collector.getPhysAddr(ifIndex));
      }
    }
  }
Exemplo n.º 2
0
  @Test
  @Transactional
  public void testGetIfIndexByName() throws SQLException {
    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.save(builder.getCiscoWsC2948());
    m_nodeDao.flush();

    OnmsNode ciscorouter = m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME);
    assertEquals("FastEthernet2", ciscorouter.getSnmpInterfaceWithIfIndex(3).getIfDescr());

    OnmsNode ciscosw = m_nodeDao.findByForeignId("linkd", CISCO_WS_C2948_NAME);
    assertEquals("2/44", ciscosw.getSnmpInterfaceWithIfIndex(52).getIfName());

    HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager();
    assertEquals(3, db.getIfIndexByName(ciscorouter.getId(), "FastEthernet2"));
    assertEquals(52, db.getIfIndexByName(ciscosw.getId(), "2/44"));
  }
  private void updateSnmpDataForInterface(OnmsIpInterface ipIf) {
    if (m_collector == null || !m_collector.hasIpAddrTable() || !m_collector.hasIfTable()) {
      return;
    }

    final InetAddress inetAddr = ipIf.getIpAddress();
    final String ipAddr = InetAddressUtils.str(inetAddr);

    LOG.debug("Creating SNMP info for interface {}", ipAddr);

    int ifIndex = m_collector.getIfIndex(inetAddr);
    if (ifIndex == -1) {
      return;
    }

    // first look to see if an snmpIf was created already
    OnmsSnmpInterface snmpIf = m_node.getSnmpInterfaceWithIfIndex(ifIndex);

    if (snmpIf == null) {
      // if not then create one
      snmpIf = new OnmsSnmpInterface(m_node, ifIndex);
      snmpIf.setIfAlias(m_collector.getIfAlias(ifIndex));
      snmpIf.setIfName(m_collector.getIfName(ifIndex));
      snmpIf.setIfType(getIfType(ifIndex));
      snmpIf.setNetMask(getNetMask(ifIndex));
      snmpIf.setIfAdminStatus(getAdminStatus(ifIndex));
      snmpIf.setIfDescr(m_collector.getIfDescr(ifIndex));
      snmpIf.setIfSpeed(m_collector.getInterfaceSpeed(ifIndex));
      snmpIf.setPhysAddr(m_collector.getPhysAddr(ifIndex));
    }

    snmpIf.setCollectionEnabled(true);

    ipIf.setSnmpInterface(snmpIf);

    // FIXME: Improve OpenNMS to provide these values
    // ifOperStatus

  }