@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"));
  }
 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);
 }
 /**
  * Constructor for AbstractSaveOrUpdateOperation.
  *
  * @param nodeId a {@link java.lang.Integer} object.
  * @param foreignSource a {@link java.lang.String} object.
  * @param foreignId a {@link java.lang.String} object.
  * @param nodeLabel a {@link java.lang.String} object.
  * @param building a {@link java.lang.String} object.
  * @param city a {@link java.lang.String} object.
  */
 public AbstractSaveOrUpdateOperation(
     final Integer nodeId,
     final String foreignSource,
     final String foreignId,
     final String nodeLabel,
     final String building,
     final String city) {
   m_node = new OnmsNode();
   m_node.setId(nodeId);
   m_node.setLabel(nodeLabel);
   m_node.setLabelSource(NodeLabelSource.USER);
   m_node.setType(NodeType.ACTIVE);
   m_node.setForeignSource(foreignSource);
   m_node.setForeignId(foreignId);
   m_node.getAssetRecord().setBuilding(building);
   m_node.getAssetRecord().setCity(city);
 }
Exemple #4
0
  /**
   * mergeNodeAttributes
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   */
  public void mergeNodeAttributes(OnmsNode scannedNode, EventForwarder eventForwarder) {
    final String scannedLabel = scannedNode.getLabel();

    boolean send = false;

    if (m_oldLabel != null || m_oldLabelSource != null) {
      send = true;
    } else if (hasNewValue(scannedLabel, getLabel())) {
      m_oldLabel = getLabel();
      m_oldLabelSource = getLabelSource();
      send = true;
    }

    if (send) {
      LOG.debug("mergeNodeAttributes(): sending NODE_LABEL_CHANGED_EVENT_UEI");
      // Create a NODE_LABEL_CHANGED_EVENT_UEI event
      final EventBuilder bldr =
          new EventBuilder(
              EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "OnmsNode.mergeNodeAttributes");

      bldr.setNodeid(scannedNode.getId());
      bldr.setHost("host");

      if (m_oldLabel != null) {
        bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL, m_oldLabel);
        if (m_oldLabelSource != null) {
          bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL_SOURCE, m_oldLabelSource.toString());
        }
      }

      if (scannedLabel != null) {
        bldr.addParam(EventConstants.PARM_NEW_NODE_LABEL, scannedLabel);
        if (scannedNode.getLabelSource() != null) {
          bldr.addParam(
              EventConstants.PARM_NEW_NODE_LABEL_SOURCE, scannedNode.getLabelSource().toString());
        }
      }

      m_oldLabel = null;
      m_oldLabelSource = null;

      eventForwarder.sendNow(bldr.getEvent());

      // Update the node label value
      m_label = scannedLabel;
    } else {
      LOG.debug("mergeNodeAttributes(): skipping event.");
    }

    if (hasNewValue(scannedNode.getForeignSource(), getForeignSource())) {
      setForeignSource(scannedNode.getForeignSource());
    }

    if (hasNewValue(scannedNode.getForeignId(), getForeignId())) {
      setForeignId(scannedNode.getForeignId());
    }

    if (hasNewValue(scannedNode.getLabelSource(), getLabelSource())) {
      setLabelSource(scannedNode.getLabelSource());
    }

    if (hasNewValue(scannedNode.getNetBiosName(), getNetBiosDomain())) {
      setNetBiosName(scannedNode.getNetBiosDomain());
    }

    if (hasNewValue(scannedNode.getNetBiosDomain(), getNetBiosDomain())) {
      setNetBiosDomain(scannedNode.getNetBiosDomain());
    }

    if (hasNewValue(scannedNode.getOperatingSystem(), getOperatingSystem())) {
      setOperatingSystem(scannedNode.getOperatingSystem());
    }

    mergeAgentAttributes(scannedNode);

    mergeAdditionalCategories(scannedNode);
  }