/** {@inheritDoc} */
 @Transactional
 public OnmsNode getDbNodeInitCat(final Integer nodeId) {
   final OnmsNode node = m_nodeDao.get(nodeId);
   m_nodeDao.initialize(node.getCategories());
   m_nodeDao.initialize(node.getDistPoller());
   return node;
 }
  /** {@inheritDoc} */
  @Override
  public void foundInterface(
      final String ipAddr,
      final Object descr,
      final InterfaceSnmpPrimaryType snmpPrimary,
      final boolean managed,
      final int status) {

    if ("".equals(ipAddr)) {
      LOG.error("Found interface on node {} with an empty ipaddr! Ignoring!", m_node.getLabel());
      // create a bogus OnmsIpInterface and set it to current to services we run across get ignored
      // as well
      m_currentInterface = new OnmsIpInterface();
      return;
    }

    m_currentInterface = new OnmsIpInterface(ipAddr, m_node);
    m_currentInterface.setIsManaged(status == 3 ? "U" : "M");
    m_currentInterface.setIsSnmpPrimary(PrimaryType.get(snmpPrimary.toString()));
    // m_currentInterface.setIpStatus(status == 3 ? new Integer(3) : new Integer(1));

    if (InterfaceSnmpPrimaryType.P.equals(snmpPrimary)) {
      final InetAddress addr = InetAddressUtils.addr(ipAddr);
      if (addr == null) {
        LOG.error(
            "Unable to resolve address of snmpPrimary interface for node {}", m_node.getLabel());
      }
      m_collector = new IfSnmpCollector(addr);
    }

    // FIXME: verify this doesn't conflict with constructor.  The constructor already adds this
    // interface to the node.
    m_node.addIpInterface(m_currentInterface);
  }
  @Test
  public void testSimpleFilter() throws Exception {
    final InetAddress oneNinetyTwo = addr("192.168.0.1");

    final List<InetAddress> addresses = Arrays.asList(oneNinetyTwo);
    m_filterDao.setActiveIPAddressList(addresses);

    final OnmsNode node = new OnmsNode(null, "foo");
    node.setId(1);
    node.setForeignSource("foo");
    node.setForeignId("bar");
    node.setSysObjectId(".1.2.3.4.5");
    final OnmsIpInterface iface = new OnmsIpInterface(oneNinetyTwo, node);
    final OnmsServiceType serviceType = new OnmsServiceType("SNMP");
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    m_monitoredServiceDao.setMatching(Arrays.asList(service));

    final Response response = m_configResource.getAgentsJson("example1", "SNMP");
    assertEquals(200, response.getStatus());
    final Object entity = response.getEntity();
    assertNotNull(entity);
    assertTrue(entity instanceof GenericEntity<?>);
    @SuppressWarnings("unchecked")
    final List<AgentResponse> agentResponses =
        (List<AgentResponse>) ((GenericEntity<?>) entity).getEntity();
    System.err.println(agentResponses);
    assertEquals(1, agentResponses.size());
    assertEquals(oneNinetyTwo, agentResponses.get(0).getAddress());
    assertEquals(1161, agentResponses.get(0).getPort().intValue());
    assertEquals(".1.2.3.4.5", agentResponses.get(0).getParameters().get("sysObjectId"));
    assertEquals("1", agentResponses.get(0).getParameters().get("nodeId"));
    assertEquals("foo", agentResponses.get(0).getParameters().get("foreignSource"));
    assertEquals("bar", agentResponses.get(0).getParameters().get("foreignId"));
  }
  @Before
  public void setUp() throws Exception {
    // Use the mock.logLevel system property to control the log level
    MockLogAppender.setupLogging(true);

    // Set the operation delay to 1 second so that queued operations execute immediately
    m_adapter.setDelay(1);
    m_adapter.setTimeUnit(TimeUnit.SECONDS);

    Assert.notNull(m_nodeDao, "Autowiring failed, NodeDao is null");
    Assert.notNull(m_mockEventIpcManager, "Autowiring failed, IPC manager is null");
    Assert.notNull(m_populator, "Autowiring failed, DB populator is null");
    Assert.notNull(m_adapter, "Autowiring failed, adapter is null");

    // Make sure that the localhost SNMP connection config factory has overridden
    // the normal config factory
    assertTrue(m_adapter.getSnmpPeerFactory() instanceof ProxySnmpAgentConfigFactory);

    m_populator.populateDatabase();

    OnmsNode node = m_nodeDao.get(NODE_ID);
    assertNotNull(node);
    node.setSysObjectId(".1.3");
    m_nodeDao.saveOrUpdate(node);
  }
Exemple #5
0
  @Test
  @JUnitSnmpAgents(
      value = {@JUnitSnmpAgent(host = Sluck001_IP, port = 161, resource = Sluck001_SNMP_RESOURCE)})
  public void testNetworkLinksCiscoJuniperVlan() throws Exception {

    m_nodeDao.save(builder.getSluck001());
    m_nodeDao.flush();

    Package example1 = m_linkdConfig.getPackage("example1");
    example1.setUseIsisDiscovery(false);
    example1.setUseIpRouteDiscovery(false);
    example1.setUseOspfDiscovery(false);
    example1.setUseLldpDiscovery(false);
    example1.setUseCdpDiscovery(false);
    example1.setUseBridgeDiscovery(false);

    example1.setEnableVlanDiscovery(true);

    example1.setSaveStpNodeTable(false);
    example1.setSaveStpInterfaceTable(false);
    example1.setSaveRouteTable(false);

    final OnmsNode switchCisco = m_nodeDao.findByForeignId("linkd", Sluck001_NAME);

    assertTrue(m_linkd.scheduleNodeCollection(switchCisco.getId()));

    assertTrue(m_linkd.runSingleSnmpCollection(switchCisco.getId()));

    assertEquals(7, m_vlanDao.countAll());
  }
  protected static String getNodeTooltipText(
      OnmsNode node, AbstractVertex vertex, OnmsIpInterface ip) {
    StringBuffer tooltipText = new StringBuffer();

    /*
    if (node.getSysDescription() != null && node.getSysDescription().length() >0) {
        tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
        tooltipText.append("Description: " + node.getSysDescription());
        tooltipText.append(HTML_TOOLTIP_TAG_END);
    }
    */

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append(
        "Management IP and Name: " + vertex.getIpAddress() + " (" + vertex.getLabel() + ")");
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    if (node.getSysLocation() != null && node.getSysLocation().length() > 0) {
      tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
      tooltipText.append("Location: " + node.getSysLocation());
      tooltipText.append(HTML_TOOLTIP_TAG_END);
    }

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append("Status: " + getNodeStatusString(node.getType()));
    if (ip != null && ip.isManaged()) {
      tooltipText.append(" / Managed");
    } else {
      tooltipText.append(" / Unmanaged");
    }
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    return tooltipText.toString();
  }
Exemple #7
0
 @Override
 public OnmsNode load(Integer id) {
   OnmsNode node = new OnmsNode();
   node.setId(777);
   node.setLabel("p-brane");
   return node;
 }
 private InetAddress getIpForNode(final OnmsNode node) {
   LogUtils.debugf(
       this,
       "getIpForNode: node: %s Foreign Source: %s",
       node.getNodeId(),
       node.getForeignSource());
   final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
   InetAddress ipaddr = InetAddressUtils.getLocalHostAddress();
   if (primaryInterface == null) {
     log().debug("getIpForNode: found null SNMP Primary Interface, getting interfaces");
     final Set<OnmsIpInterface> ipInterfaces = node.getIpInterfaces();
     for (final OnmsIpInterface onmsIpInterface : ipInterfaces) {
       log().debug("getIpForNode: trying Interface with id: " + onmsIpInterface.getId());
       if (InetAddressUtils.str(onmsIpInterface.getIpAddress()) != null)
         ipaddr = onmsIpInterface.getIpAddress();
       else
         log()
             .debug(
                 "getIpForNode: found null ip address on Interface with id: "
                     + onmsIpInterface.getId());
     }
   } else {
     log().debug("getIpForNode: found SNMP Primary Interface");
     if (InetAddressUtils.str(primaryInterface.getIpAddress()) != null)
       ipaddr = primaryInterface.getIpAddress();
     else log().debug("getIpForNode: found null ip address on Primary Interface");
   }
   return ipaddr;
 }
 private OnmsResource getNodeResource(int nodeId) {
   final NodeResourceType nodeResourceType = new NodeResourceType(m_resourceDao, m_nodeDao);
   OnmsNode node = new OnmsNode();
   node.setId(nodeId);
   node.setLabel("Node" + nodeId);
   return nodeResourceType.createResourceForNode(node);
 }
  private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
    Assert.notNull(node, "Node may not be null");
    final String actualForeignSource = node.getForeignSource();
    if (actualForeignSource == null && !isDiscoveryEnabled()) {
      infof(
          this,
          "Not scheduling node %s to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond",
          node);
      return null;
    }

    final String effectiveForeignSource =
        actualForeignSource == null ? "default" : actualForeignSource;
    try {
      final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);

      final Duration scanInterval = fs.getScanInterval();
      Duration initialDelay = Duration.ZERO;
      if (node.getLastCapsdPoll() != null && !force) {
        final DateTime nextPoll =
            new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
        final DateTime now = new DateTime();
        if (nextPoll.isAfter(now)) {
          initialDelay = new Duration(now, nextPoll);
        }
      }

      return new NodeScanSchedule(
          node.getId(), actualForeignSource, node.getForeignId(), initialDelay, scanInterval);
    } catch (final ForeignSourceRepositoryException e) {
      warnf(this, e, "unable to get foreign source '%s' from repository", effectiveForeignSource);
      return null;
    }
  }
  public boolean isRequisitioned(OnmsMonitoredService monSvc) {
    String foreignSource = monSvc.getIpInterface().getNode().getForeignSource();
    String foreignId = monSvc.getIpInterface().getNode().getForeignId();

    // is this a discovered node
    if (foreignSource == null) return false;

    OnmsNode reqNode = getRequisitionedNode(foreignSource, foreignId);
    if (reqNode == null) {
      // this is no requisition node?
      LogUtils.errorf(
          "No requistion exists for node with foreignSource %s and foreignId %s.  Treating node as unrequistioned",
          foreignSource, foreignId);
      return false;
    }

    OnmsIpInterface reqIp = reqNode.getIpInterfaceByIpAddress(monSvc.getIpAddress());
    if (reqIp == null) {
      // there is no matching requistion ip so the interface was discovered
      return false;
    }

    OnmsMonitoredService reqSvc = reqIp.getMonitoredServiceByServiceType(monSvc.getServiceName());

    // if we found the service then its a requistion service
    return reqSvc != null;
  }
Exemple #12
0
 private static OnmsIpInterface getInterface() {
   OnmsNode node = new OnmsNode();
   node.setId(1);
   OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
   iface.setId(1);
   return iface;
 }
 public Map<Integer, String> getNodeLabelsById() {
   Map<Integer, String> nodeLabelsById = new HashMap<Integer, String>();
   for (OnmsNode node : getNodes()) {
     nodeLabelsById.put(node.getId(), node.getLabel());
   }
   return nodeLabelsById;
 }
 /** {@inheritDoc} */
 @Transactional
 public OnmsNode getNode(final Integer nodeId) {
   final OnmsNode node = m_nodeDao.get(nodeId);
   m_nodeDao.initialize(node);
   m_nodeDao.initialize(node.getCategories());
   m_nodeDao.initialize(node.getIpInterfaces());
   return node;
 }
  /** {@inheritDoc} */
  @Override
  public Long getParentNode(final Long nodeid) {
    final OnmsNode node = m_nodeDao.get(nodeid.intValue());
    Assert.notNull(node, "Unable to find node with id " + nodeid);

    final OnmsNode parent = node.getParent();
    return (parent == null ? null : new Long(parent.getId().longValue()));
  }
 /** {@inheritDoc} */
 @Override
 public String getNodeLabel(int nodeId) {
   final OnmsNode onmsNode = m_nodeDao.get(nodeId);
   if (onmsNode == null) {
     return null;
   }
   return onmsNode.getLabel();
 }
Exemple #17
0
  @Test
  public void testWorkStation() throws Exception {
    m_nodeDao.save(builder.getNodeWithoutSnmp(WORKSTATION_NAME, WORKSTATION_IP));
    m_nodeDao.flush();
    final OnmsNode workstation = m_nodeDao.findByForeignId("linkd", WORKSTATION_NAME);

    assertTrue(!m_linkd.scheduleNodeCollection(workstation.getId()));
  }
 private void updateSnmpDataForNode() {
   if (m_collector != null && m_collector.hasSystemGroup()) {
     m_node.setSysContact(m_collector.getSystemGroup().getSysContact());
     m_node.setSysDescription(m_collector.getSystemGroup().getSysDescr());
     m_node.setSysLocation(m_collector.getSystemGroup().getSysLocation());
     m_node.setSysObjectId(m_collector.getSystemGroup().getSysObjectID());
   }
 }
 private OnmsResource getNodeResource(String fs, String fid) {
   NodeResourceType nodeSourceResourceType = new NodeResourceType(m_resourceDao, m_nodeDao);
   OnmsNode node = new OnmsNode();
   node.setId(0);
   node.setLabel("Node");
   node.setForeignSource(fs);
   node.setForeignId(fid);
   return nodeSourceResourceType.createResourceForNode(node);
 }
  public void testPoll() throws EventProxyException {

    final int expectedPolldId = 7;

    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);

    m_eventProxy.send(isA(Event.class));
    expectLastCall()
        .andAnswer(
            new IAnswer<Object>() {

              @Override
              public Object answer() throws Throwable {
                Event event = (Event) getCurrentArguments()[0];
                assertEquals(
                    "Incorrect uei for demandPollService event",
                    EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI,
                    event.getUei());
                assertEquals(
                    "Incorrect nodeid for demandPollService event",
                    monSvc.getNodeId().longValue(),
                    event.getNodeid().longValue());
                assertEquals(
                    "Incorrect ipadr for demandPollService event",
                    InetAddressUtils.str(monSvc.getIpAddress()),
                    event.getInterface());
                assertEquals(
                    "Incorrect ifIndex for demandPollService event",
                    monSvc.getIfIndex(),
                    Integer.valueOf(event.getIfIndex()));
                assertEquals(
                    "Incorrect service for demandPollService event",
                    monSvc.getServiceType().getName(),
                    event.getService());
                EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
                assertEquals(
                    expectedPolldId,
                    EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
                return null;
              }
            });

    replay(m_eventProxy);

    m_pollerService.poll(monSvc, expectedPolldId);

    verify(m_eventProxy);
  }
  /** {@inheritDoc} */
  @Transactional
  public OnmsNode createUndiscoveredNode(final String ipAddress) {

    OnmsNode node =
        new UpsertTemplate<OnmsNode, NodeDao>(m_transactionManager, m_nodeDao) {

          @Override
          protected OnmsNode query() {
            List<OnmsNode> nodes =
                m_nodeDao.findByForeignSourceAndIpAddress(
                    FOREIGN_SOURCE_FOR_DISCOVERED_NODES, ipAddress);
            return nodes.size() > 0 ? nodes.get(0) : null;
          }

          @Override
          protected OnmsNode doUpdate(OnmsNode existingNode) {
            // we found an existing node so exit by returning null;
            return null;
          }

          @Override
          protected OnmsNode doInsert() {
            final Date now = new Date();

            final String hostname = getHostnameForIp(ipAddress);

            // @ipv6
            final OnmsNode node =
                new OnmsNode(createDistPollerIfNecessary("localhost", "127.0.0.1"));
            node.setLabel(hostname == null ? ipAddress : hostname);
            node.setLabelSource(hostname == null ? "A" : "H");
            node.setForeignSource(FOREIGN_SOURCE_FOR_DISCOVERED_NODES);
            node.setType("A");
            node.setLastCapsdPoll(now);

            final OnmsIpInterface iface = new OnmsIpInterface(ipAddress, node);
            iface.setIsManaged("M");
            iface.setIpHostName(hostname);
            iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE);
            iface.setIpLastCapsdPoll(now);

            m_nodeDao.save(node);
            m_nodeDao.flush();
            return node;
          }
        }.execute();

    if (node != null) {

      // we do this here rather than in the doInsert method because
      // the doInsert may abort
      node.visit(new AddEventVisitor(m_eventForwarder));
    }

    return node;
  }
 @Transactional(readOnly = true)
 private OnmsNode getDbNode(final OnmsNode node) {
   OnmsNode dbNode;
   if (node.getId() != null) {
     dbNode = m_nodeDao.get(node.getId());
   } else {
     dbNode = m_nodeDao.findByForeignId(node.getForeignSource(), node.getForeignId());
   }
   return dbNode;
 }
  /** {@inheritDoc} */
  @Transactional
  public void deleteNode(final Integer nodeId) {

    final OnmsNode node = m_nodeDao.get(nodeId);

    if (node != null && shouldDelete(node)) {
      m_nodeDao.delete(node);
      node.visit(new DeleteEventVisitor(m_eventForwarder));
    }
  }
Exemple #24
0
  @Test
  public void testGetNodeidFromIp() throws UnknownHostException, SQLException {
    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.flush();

    HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager();

    final OnmsNode node = db.getNodeidFromIp(InetAddressUtils.addr(CISCO_C870_IP)).get(0);
    assertEquals(m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME).getId(), node.getId());
  }
  @Override
  public boolean isNodeReady(AdapterOperation op) {
    boolean readyState = false;
    OnmsNode node = m_nodeDao.get(op.getNodeId());

    if (node != null && node.getSysObjectId() != null) {
      readyState = true;
    }
    return readyState;
  }
  /** {@inheritDoc} */
  @Transactional
  public void insertNode(final OnmsNode node) {

    node.setDistPoller(createDistPollerIfNecessary("localhost", "127.0.0.1"));
    m_nodeDao.save(node);
    m_nodeDao.flush();

    final EntityVisitor eventAccumlator = new AddEventVisitor(m_eventForwarder);

    node.visit(eventAccumlator);
  }
 protected AbstractVertex getVertex(OnmsNode onmsnode) {
   OnmsIpInterface ip = getAddress(onmsnode);
   AbstractVertex vertex =
       new SimpleLeafVertex(TOPOLOGY_NAMESPACE_LINKD, onmsnode.getNodeId(), 0, 0);
   vertex.setIconKey(getIconName(onmsnode));
   vertex.setLabel(onmsnode.getLabel());
   vertex.setIpAddress(ip == null ? null : ip.getIpAddress().getHostAddress());
   vertex.setNodeID(Integer.parseInt(onmsnode.getNodeId()));
   vertex.setTooltipText(getNodeTooltipText(onmsnode, vertex, ip));
   return vertex;
 }
Exemple #28
0
    private void walkTable(
        final BatchTask currentPhase,
        final Set<InetAddress> provisionedIps,
        final TableTracker tracker) {
      final OnmsNode node = getNode();
      LOG.info(
          "detecting IP interfaces for node {}/{}/{} using table tracker {}",
          node.getId(),
          node.getForeignSource(),
          node.getForeignId(),
          tracker);

      if (isAborted()) {
        LOG.debug("'{}' is marked as aborted; skipping scan of table {}", currentPhase, tracker);
      } else {
        Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");

        final SnmpAgentConfig agentConfig =
            getAgentConfigFactory().getAgentConfig(getAgentAddress());

        final SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "IP address tables", tracker);
        walker.start();

        try {
          walker.waitFor();

          if (walker.timedOut()) {
            abort("Aborting node scan : Agent timed out while scanning the IP address tables");
          } else if (walker.failed()) {
            abort(
                "Aborting node scan : Agent failed while scanning the IP address tables : "
                    + walker.getErrorMessage());
          } else {

            // After processing the SNMP provided interfaces then we need to scan any that
            // were provisioned but missing from the ip table
            for (final InetAddress ipAddr : provisionedIps) {
              final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddr);

              if (iface != null) {
                iface.setIpLastCapsdPoll(getScanStamp());
                iface.setIsManaged("M");

                currentPhase.add(ipUpdater(currentPhase, iface), "write");
              }
            }

            LOG.debug("Finished phase {}", currentPhase);
          }
        } catch (final InterruptedException e) {
          abort("Aborting node scan : Scan thread failed while waiting for the IP address tables");
        }
      }
    }
Exemple #29
0
  @Override
  public List<OnmsNode> findAll() {

    List<OnmsNode> nodeList = new LinkedList<OnmsNode>();

    OnmsNode node = new OnmsNode();
    node.setId(777);
    node.setLabel("p-brane");

    nodeList.add(node);
    return nodeList;
  }
 protected OnmsIpInterface getAddress(OnmsNode node) {
   // OnmsIpInterface ip = node.getPrimaryInterface();
   OnmsIpInterface ip = getIpInterfaceDao().findPrimaryInterfaceByNodeId(node.getId());
   if (ip == null) {
     //            for (OnmsIpInterface iterip: node.getIpInterfaces()) {
     for (OnmsIpInterface iterip : getIpInterfaceDao().findByNodeId(node.getId())) {
       ip = iterip;
       break;
     }
   }
   return ip;
 }