/** {@inheritDoc} */
 @Transactional
 public void deleteInterface(final Integer nodeId, final String ipAddr) {
   final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddr);
   if (iface != null && shouldDelete(iface)) {
     m_ipInterfaceDao.delete(iface);
     iface.visit(new DeleteEventVisitor(m_eventForwarder));
   }
 }
  @Transactional
  private OnmsIpInterface saveOrUpdate(final OnmsIpInterface iface) {
    iface.visit(new ServiceTypeFulfiller());
    infof(this, "SaveOrUpdating IpInterface %s", iface);
    m_ipInterfaceDao.saveOrUpdate(iface);
    m_ipInterfaceDao.flush();

    return iface;
  }
 /** {@inheritDoc} */
 @Transactional
 public OnmsIpInterface getPrimaryInterfaceForNode(final OnmsNode node) {
   final OnmsNode dbNode = getDbNode(node);
   if (dbNode == null) {
     return null;
   } else {
     final OnmsIpInterface primaryIface = dbNode.getPrimaryInterface();
     if (primaryIface != null) {
       m_ipInterfaceDao.initialize(primaryIface);
       m_ipInterfaceDao.initialize(primaryIface.getMonitoredServices());
     }
     return primaryIface;
   }
 }
  @Transactional
  public OnmsMonitoredService updateMonitoredServiceState(
      final Integer nodeId, final String ipAddress, final String svcName) {
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    assertNotNull(
        iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);

    return new UpsertTemplate<OnmsMonitoredService, MonitoredServiceDao>(
        m_transactionManager, m_monitoredServiceDao) {

      @Override
      protected OnmsMonitoredService query() {
        return iface.getMonitoredServiceByServiceType(svcName);
      }

      @Override
      protected OnmsMonitoredService doUpdate(OnmsMonitoredService dbObj) { // NMS-3906
        debugf(
            this,
            "current status of service %s on node with IP %s is %s ",
            dbObj.getServiceName(),
            dbObj.getIpAddress().getHostAddress(),
            dbObj.getStatus());
        if ("S".equals(dbObj.getStatus())) {
          debugf(
              this,
              "suspending polling for service %s on node with IP %s",
              dbObj.getServiceName(),
              dbObj.getIpAddress().getHostAddress());
          dbObj.setStatus("F");
          m_monitoredServiceDao.update(dbObj);
          sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, dbObj);
        }
        if ("R".equals(dbObj.getStatus())) {
          debugf(
              this,
              "resume polling for service %s on node with IP %s",
              dbObj.getServiceName(),
              dbObj.getIpAddress().getHostAddress());
          dbObj.setStatus("A");
          m_monitoredServiceDao.update(dbObj);
          sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, dbObj);
        }
        return dbObj;
      }

      @Override
      protected OnmsMonitoredService doInsert() {
        return null;
      }

      private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
        final EventBuilder bldr = new EventBuilder(eventUEI, "ProvisionService");
        bldr.setNodeid(dbObj.getNodeId());
        bldr.setInterface(dbObj.getIpAddress());
        bldr.setService(dbObj.getServiceName());
        m_eventForwarder.sendNow(bldr.getEvent());
      }
    }.execute();
  }
 /** {@inheritDoc} */
 @Transactional
 public OnmsMonitoredService addMonitoredService(
     final Integer ipInterfaceId, final String svcName) {
   final OnmsIpInterface iface = m_ipInterfaceDao.get(ipInterfaceId);
   assertNotNull(iface, "could not find interface with id %d", ipInterfaceId);
   return addMonitoredService(iface, svcName);
 }
 /** {@inheritDoc} */
 @Transactional
 public OnmsMonitoredService addMonitoredService(
     final Integer nodeId, final String ipAddress, final String svcName) {
   final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
   assertNotNull(
       iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
   return addMonitoredService(iface, svcName);
 }
  /** {@inheritDoc} */
  @Transactional
  public OnmsIpInterface setIsPrimaryFlag(final Integer nodeId, final String ipAddress) {
    // TODO upsert? not sure if this needs one.. leave the todo here in case
    if (nodeId == null) {
      LogUtils.debugf(this, "nodeId is null!");
      return null;
    } else if (ipAddress == null) {
      LogUtils.debugf(this, "ipAddress is null!");
      return null;
    }
    final OnmsIpInterface svcIface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    if (svcIface == null) {
      LogUtils.infof(
          this, "unable to find IPInterface for nodeId=%s, ipAddress=%s", nodeId, ipAddress);
      return null;
    }
    OnmsIpInterface primaryIface = null;
    if (svcIface.isPrimary()) {
      primaryIface = svcIface;
    } else if (svcIface.getNode().getPrimaryInterface() == null) {
      svcIface.setIsSnmpPrimary(PrimaryType.PRIMARY);
      m_ipInterfaceDao.saveOrUpdate(svcIface);
      m_ipInterfaceDao.flush();
      primaryIface = svcIface;
    } else {
      svcIface.setIsSnmpPrimary(PrimaryType.SECONDARY);
      m_ipInterfaceDao.saveOrUpdate(svcIface);
      m_ipInterfaceDao.flush();
    }

    m_ipInterfaceDao.initialize(primaryIface);
    return primaryIface;
  }
Пример #8
0
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();
    startServer("None&8&", "10");

    // Initialize Mocks
    m_transactionManager = new MockPlatformTransactionManager();
    m_ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
    m_eventProxy = EasyMock.createMock(EventProxy.class);
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("winsrv");
    builder
        .addInterface(getServer().getInetAddress().getHostAddress())
        .addSnmpInterface(1)
        .setCollectionEnabled(true);
    builder.getCurrentNode().setId(1);
    OnmsIpInterface iface = builder.getCurrentNode().getIpInterfaces().iterator().next();
    iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
    iface.setId(1);
    EasyMock.expect(m_ipInterfaceDao.load(1)).andReturn(iface).anyTimes();
    EasyMock.replay(m_ipInterfaceDao, m_eventProxy);

    // Initialize NSClient Configuration
    String nsclient_config =
        "<nsclient-config port=\""
            + getServer().getLocalPort()
            + "\" retry=\"1\" timeout=\"3000\" />";
    NSClientPeerFactory.setInstance(
        new NSClientPeerFactory(new ByteArrayInputStream(nsclient_config.getBytes())));
    NSClientDataCollectionConfigFactory.setInstance(
        new NSClientDataCollectionConfigFactory(
            "src/test/resources/nsclient-datacollection-config.xml"));

    // Initialize Collection Agent
    m_collectionAgent = DefaultCollectionAgent.create(1, m_ipInterfaceDao, m_transactionManager);
  }
  @Test
  @JUnitSnmpAgents(
      value = {
        @JUnitSnmpAgent(
            host = ROUTER1_IP,
            port = 161,
            resource = "classpath:linkd/nms17216/router1-walk.txt")
      })
  @Transactional
  public final void testRouter1() throws MarshalException, ValidationException, IOException {
    m_capsd.init();
    m_capsd.start();
    m_capsd.scanSuspectInterface(ROUTER1_IP);

    List<OnmsIpInterface> ips = m_interfaceDao.findByIpAddress(ROUTER1_IP);
    assertTrue("Has only one ip interface", ips.size() == 1);

    OnmsIpInterface ip = ips.get(0);

    for (OnmsIpInterface ipinterface : ip.getNode().getIpInterfaces()) {
      if (ipinterface.getIfIndex() != null)
        System.out.println(
            "ROUTER1_IP_IF_MAP.put(InetAddress.getByName(\""
                + ipinterface.getIpHostName()
                + "\"), "
                + ipinterface.getIfIndex()
                + ");");
    }

    for (OnmsSnmpInterface snmpinterface : ip.getNode().getSnmpInterfaces()) {
      if (snmpinterface.getIfName() != null)
        System.out.println(
            "ROUTER1_IF_IFNAME_MAP.put("
                + snmpinterface.getIfIndex()
                + ", \""
                + snmpinterface.getIfName()
                + "\");");
      if (snmpinterface.getIfDescr() != null)
        System.out.println(
            "ROUTER1_IF_IFDESCR_MAP.put("
                + snmpinterface.getIfIndex()
                + ", \""
                + snmpinterface.getIfDescr()
                + "\");");
      if (snmpinterface.getPhysAddr() != null)
        System.out.println(
            "ROUTER1_IF_MAC_MAP.put("
                + snmpinterface.getIfIndex()
                + ", \""
                + snmpinterface.getPhysAddr()
                + "\");");
      if (snmpinterface.getIfAlias() != null)
        System.out.println(
            "ROUTER1_IF_IFALIAS_MAP.put("
                + snmpinterface.getIfIndex()
                + ", \""
                + snmpinterface.getIfAlias()
                + "\");");
    }

    m_capsd.stop();
  }
Пример #10
0
 @Before
 public void setUp() {
   MockLogAppender.setupLogging();
   m_populator.populateDatabase();
   m_interfaces = m_ipInterfaceDao.findAll();
 }