Beispiel #1
0
  /**
   * Registers an OpenNMS event listener with this class. When an event occurs, OpenNMS will call
   * the onEvent() method of this object.
   */
  @Override
  public void registerListener() {
    List<String> ueiList = new ArrayList<String>();
    String[] temp = config.getEventlist().getUei();
    for (int i = 0; i < temp.length; i++) ueiList.add(temp[i]);

    LOG.info("QosD Registering for {} types of event", temp.length);
    eventIpcManager.addEventListener(this, ueiList);
  }
Beispiel #2
0
  @Override
  protected void setUp() throws Exception {
    EventIpcManager m_eventIpcManager;
    NodeDao m_nodeDao;

    MockLogAppender.setupLogging();

    Resource threshdResource = new ClassPathResource("/etc/thresholds.xml");
    File homeDir = threshdResource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());

    // Test setup
    m_eventIpcManager = m_easyMockUtils.createMock(EventIpcManager.class);
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
    m_ipIfDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
    m_scheduler = new MockScheduler();

    m_eventIpcManager.addEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isACollection(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isA(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.removeEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();

    //        MockNetwork m_network = new MockNetwork();
    //        m_network.setCriticalService("ICMP");
    //        m_network.addNode(1, "Router");
    //        m_network.addInterface("192.168.1.1");
    //        m_network.addService("ICMP");
    //        m_network.addService("SMTP");
    //        m_network.addInterface("192.168.1.2");
    //        m_network.addService("ICMP");
    //        m_network.addService("SMTP");
    //        m_network.addNode(2, "Server");
    //        m_network.addInterface("192.168.1.3");
    //        m_network.addService("ICMP");
    //        m_network.addService("HTTP");
    //        m_network.addNode(3, "Firewall");
    //        m_network.addInterface("192.168.1.4");
    //        m_network.addService("SMTP");
    //        m_network.addService("HTTP");
    //        m_network.addInterface("192.168.1.5");
    //        m_network.addService("SMTP");
    //        m_network.addService("HTTP");
    //
    //        MockDatabase m_db = new MockDatabase();
    //        m_db.populate(m_network);
    //
    //        DataSourceFactory.setInstance(m_db);

    // Mock the FilterDao without using EasyMockUtils so that it can be verified separately
    m_filterDao = EasyMock.createMock(FilterDao.class);
    List<InetAddress> allIps = new ArrayList<InetAddress>();
    allIps.add(addr("192.168.1.1"));
    allIps.add(addr("192.168.1.2"));
    allIps.add(addr("192.168.1.3"));
    allIps.add(addr("192.168.1.4"));
    allIps.add(addr("192.168.1.5"));
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*"))
        .andReturn(allIps)
        .anyTimes();
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE 1.1.1.1"))
        .andReturn(new ArrayList<InetAddress>(0))
        .anyTimes();
    EasyMock.replay(m_filterDao);
    FilterDaoFactory.setInstance(m_filterDao);

    // This call will also ensure that the poll-outages.xml file can parse IPv4
    // and IPv6 addresses.
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);

    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();

    m_collectd = new Collectd();
    m_collectd.setEventIpcManager(m_eventIpcManager);
    // m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setIpInterfaceDao(m_ipIfDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setScheduler(m_scheduler);
    m_collectd.setTransactionTemplate(transTemplate);
    // m_collectd.afterPropertiesSet();

    ThresholdingConfigFactory.setInstance(
        new ThresholdingConfigFactory(
            ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml")));
  }
 /** Create message selector to set to the subscription */
 private void addEventListener() {
   m_eventIpcManager.addEventListener(this, EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI);
   m_eventIpcManager.addEventListener(this, EventConstants.RELOAD_DAEMON_CONFIG_UEI);
 }