@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);
  }
 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());
   }
 }
Exemple #4
0
  /**
   * mergeAgentAttributes
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   */
  public void mergeAgentAttributes(OnmsNode scannedNode) {
    if (hasNewValue(scannedNode.getSysContact(), getSysContact())) {
      setSysContact(scannedNode.getSysContact());
    }

    if (hasNewValue(scannedNode.getSysDescription(), getSysDescription())) {
      setSysDescription(scannedNode.getSysDescription());
    }

    if (hasNewValue(scannedNode.getSysLocation(), getSysLocation())) {
      setSysLocation(scannedNode.getSysLocation());
    }

    if (hasNewValue(scannedNode.getSysName(), getSysName())) {
      setSysName(scannedNode.getSysName());
    }

    if (hasNewValue(scannedNode.getSysObjectId(), getSysObjectId())) {
      setSysObjectId(scannedNode.getSysObjectId());
    }
  }