/** Create message selector to set to the subscription */
  BroadcastEventProcessor() {
    // Create the selector for the ueis this service is interested in
    //
    List<String> ueiList = new ArrayList<String>();

    // nodeGainedInterface
    ueiList.add(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI);

    // interfaceDeleted
    ueiList.add(EventConstants.INTERFACE_DELETED_EVENT_UEI);

    EventIpcManagerFactory.init();
    EventIpcManagerFactory.getIpcManager().addEventListener(this, ueiList);
  }
  /**
   * sendEvent
   *
   * @param uei a {@link java.lang.String} object.
   */
  protected void sendEvent(String uei) {
    EventBuilder bldr = new EventBuilder(uei, "NotifdConfigFactory");

    try {
      EventIpcManagerFactory.getIpcManager().sendNow(bldr.getEvent());
    } catch (Throwable t) {
    }
  }
Example #3
0
  protected void setUp() throws Exception {
    super.setUp();
    MockUtil.println("------------ Begin Test " + this + " --------------------------");
    MockLogAppender.setupLogging();

    if (m_runSupers) {

      createMockNetwork();

      populateDatabase();

      DataSourceFactory.setInstance(m_db);

      SnmpPeerFactory.setInstance(
          new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));

      if (isStartEventd()) {
        m_eventdIpcMgr = new EventIpcManagerDefaultImpl();

        JdbcEventdServiceManager eventdServiceManager = new JdbcEventdServiceManager();
        eventdServiceManager.setDataSource(m_db);
        eventdServiceManager.afterPropertiesSet();

        /*
         * Make sure we specify a full resource path since "this" is
         * the unit test class, which is most likely in another package.
         */
        File configFile =
            ConfigurationTestUtils.getFileForResource(
                this, "/org/opennms/netmgt/mock/eventconf.xml");
        DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
        eventConfDao.setConfigResource(new FileSystemResource(configFile));
        eventConfDao.afterPropertiesSet();
        EventconfFactory.setInstance(eventConfDao);

        EventExpander eventExpander = new EventExpander();
        eventExpander.setEventConfDao(eventConfDao);
        eventExpander.afterPropertiesSet();

        JdbcEventWriter jdbcEventWriter = new JdbcEventWriter();
        jdbcEventWriter.setEventdServiceManager(eventdServiceManager);
        jdbcEventWriter.setDataSource(m_db);
        jdbcEventWriter.setGetNextIdString(
            "select nextVal('eventsNxtId')"); // for HSQL: "SELECT max(eventId)+1 from events"
        jdbcEventWriter.afterPropertiesSet();

        EventIpcBroadcastProcessor eventIpcBroadcastProcessor = new EventIpcBroadcastProcessor();
        eventIpcBroadcastProcessor.setEventIpcBroadcaster(m_eventdIpcMgr);
        eventIpcBroadcastProcessor.afterPropertiesSet();

        List<EventProcessor> eventProcessors = new ArrayList<EventProcessor>(3);
        eventProcessors.add(eventExpander);
        eventProcessors.add(jdbcEventWriter);
        eventProcessors.add(eventIpcBroadcastProcessor);

        DefaultEventHandlerImpl eventHandler = new DefaultEventHandlerImpl();
        eventHandler.setEventProcessors(eventProcessors);
        eventHandler.afterPropertiesSet();

        m_eventdIpcMgr.setHandlerPoolSize(5);
        m_eventdIpcMgr.setEventHandler(eventHandler);
        m_eventdIpcMgr.afterPropertiesSet();

        m_eventProxy = m_eventdIpcMgr;

        EventIpcManagerFactory.setIpcManager(m_eventdIpcMgr);

        EventIpcManagerEventHandlerProxy proxy = new EventIpcManagerEventHandlerProxy();
        proxy.setEventIpcManager(m_eventdIpcMgr);
        proxy.afterPropertiesSet();
        List<EventHandler> eventHandlers = new ArrayList<EventHandler>(1);
        eventHandlers.add(proxy);

        TcpEventReceiver tcpEventReceiver = new TcpEventReceiver();
        tcpEventReceiver.setPort(5837);
        tcpEventReceiver.setEventHandlers(eventHandlers);

        UdpEventReceiver udpEventReceiver = new UdpEventReceiver();
        udpEventReceiver.setPort(5837);
        tcpEventReceiver.setEventHandlers(eventHandlers);

        List<EventReceiver> eventReceivers = new ArrayList<EventReceiver>(2);
        eventReceivers.add(tcpEventReceiver);
        eventReceivers.add(udpEventReceiver);

        m_eventd = new Eventd();
        m_eventd.setEventdServiceManager(eventdServiceManager);
        m_eventd.setEventReceivers(eventReceivers);
        m_eventd.setReceiver(new BroadcastEventProcessor(m_eventdIpcMgr, eventConfDao));

        m_eventd.init();
        m_eventd.start();
      }
    }

    m_transMgr = new DataSourceTransactionManager(DataSourceFactory.getInstance());
  }
Example #4
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")));
  }
 /** Unsubscribe from eventd */
 public void close() {
   EventIpcManagerFactory.getIpcManager().removeEventListener(this);
 }