Search in sources :

Example 1 with SnmpPeerFactory

use of org.opennms.netmgt.config.SnmpPeerFactory in project opennms by OpenNMS.

the class DefaultCollectionAgentTest method canGetLocationAwareAgentConfig.

/**
     * Verifies that the SNMP agent configuration is retrieved using
     * the location name that is associated with the interface/node.
     */
@Test
public void canGetLocationAwareAgentConfig() {
    // Mock the peer factory
    SnmpPeerFactory snmpPeerFactory = mock(SnmpPeerFactory.class);
    SnmpPeerFactory.setInstance(snmpPeerFactory);
    // Mock the other arguments required to create a DefaultCollectionAgent
    Integer ifaceId = 1;
    IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
    PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
    OnmsIpInterface ipIface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS);
    when(ifaceDao.load(ifaceId)).thenReturn(ipIface);
    when(ipIface.getNode().getLocation().getLocationName()).thenReturn("Ocracoke");
    // Retrieve the agent configuration
    SnmpCollectionAgent agent = DefaultCollectionAgent.create(ifaceId, ifaceDao, transMgr);
    agent.getAgentConfig();
    // Verify
    verify(snmpPeerFactory, times(1)).getAgentConfig(any(), eq("Ocracoke"));
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) SnmpPeerFactory(org.opennms.netmgt.config.SnmpPeerFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Test(org.junit.Test)

Example 2 with SnmpPeerFactory

use of org.opennms.netmgt.config.SnmpPeerFactory in project opennms by OpenNMS.

the class CollectorConfigDaoImplIT method initialize.

private void initialize() throws IOException, Exception {
    System.setProperty("opennms.home", ConfigurationTestUtils.getDaemonEtcDirectory().getParentFile().getAbsolutePath());
    InputStream stream = null;
    stream = getInputStreamForFile("/org/opennms/netmgt/config/test-database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(stream));
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/snmp-config.xml");
    SnmpPeerFactory.setInstance(new SnmpPeerFactory(new InputStreamResource(stream)));
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/datacollection-config.xml");
    DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
    dataCollectionDao.setConfigResource(new InputStreamResource(stream));
    dataCollectionDao.afterPropertiesSet();
    DataCollectionConfigFactory.setInstance(dataCollectionDao);
    stream.close();
    stream = getInputStreamForFile("/org/opennms/netmgt/config/collectd-testdata.xml");
    try {
        new CollectdConfigFactory(stream, "localhost", false);
    } finally {
        stream.close();
    }
}
Also used : InputStream(java.io.InputStream) SnmpPeerFactory(org.opennms.netmgt.config.SnmpPeerFactory) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 3 with SnmpPeerFactory

use of org.opennms.netmgt.config.SnmpPeerFactory in project opennms by OpenNMS.

the class OpenNMSITCase method setUp.

@Before
public void setUp() throws Exception {
    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(m_registry);
            EventUtilJdbcImpl eventUtil = new EventUtilJdbcImpl();
            AbstractEventUtil.setInstance(eventUtil);
            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();
            EventExpander eventExpander = new EventExpander(m_registry);
            eventExpander.setEventConfDao(eventConfDao);
            eventExpander.setEventUtil(eventUtil);
            eventExpander.afterPropertiesSet();
            EventIpcBroadcastProcessor eventIpcBroadcastProcessor = new EventIpcBroadcastProcessor(m_registry);
            eventIpcBroadcastProcessor.setEventIpcBroadcaster(m_eventdIpcMgr);
            eventIpcBroadcastProcessor.afterPropertiesSet();
            List<EventProcessor> eventProcessors = new ArrayList<EventProcessor>(3);
            eventProcessors.add(eventExpander);
            eventProcessors.add(eventIpcBroadcastProcessor);
            DefaultEventHandlerImpl eventHandler = new DefaultEventHandlerImpl(m_registry);
            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());
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) EventIpcManagerEventHandlerProxy(org.opennms.netmgt.eventd.adaptors.EventIpcManagerEventHandlerProxy) JdbcEventdServiceManager(org.opennms.netmgt.dao.mock.JdbcEventdServiceManager) Eventd(org.opennms.netmgt.eventd.Eventd) SnmpPeerFactory(org.opennms.netmgt.config.SnmpPeerFactory) ArrayList(java.util.ArrayList) EventHandler(org.opennms.netmgt.eventd.adaptors.EventHandler) ByteArrayResource(org.springframework.core.io.ByteArrayResource) EventIpcManagerDefaultImpl(org.opennms.netmgt.eventd.EventIpcManagerDefaultImpl) FileSystemResource(org.springframework.core.io.FileSystemResource) TcpEventReceiver(org.opennms.netmgt.eventd.adaptors.tcp.TcpEventReceiver) DefaultEventConfDao(org.opennms.netmgt.config.DefaultEventConfDao) DefaultEventHandlerImpl(org.opennms.netmgt.eventd.DefaultEventHandlerImpl) EventReceiver(org.opennms.netmgt.eventd.adaptors.EventReceiver) TcpEventReceiver(org.opennms.netmgt.eventd.adaptors.tcp.TcpEventReceiver) UdpEventReceiver(org.opennms.netmgt.eventd.adaptors.udp.UdpEventReceiver) EventIpcBroadcastProcessor(org.opennms.netmgt.eventd.processor.EventIpcBroadcastProcessor) BroadcastEventProcessor(org.opennms.netmgt.eventd.BroadcastEventProcessor) EventProcessor(org.opennms.netmgt.events.api.EventProcessor) UdpEventReceiver(org.opennms.netmgt.eventd.adaptors.udp.UdpEventReceiver) BroadcastEventProcessor(org.opennms.netmgt.eventd.BroadcastEventProcessor) File(java.io.File) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) Before(org.junit.Before)

Aggregations

SnmpPeerFactory (org.opennms.netmgt.config.SnmpPeerFactory)3 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)1 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)1 DefaultEventConfDao (org.opennms.netmgt.config.DefaultEventConfDao)1 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)1 JdbcEventdServiceManager (org.opennms.netmgt.dao.mock.JdbcEventdServiceManager)1 BroadcastEventProcessor (org.opennms.netmgt.eventd.BroadcastEventProcessor)1 DefaultEventHandlerImpl (org.opennms.netmgt.eventd.DefaultEventHandlerImpl)1 EventExpander (org.opennms.netmgt.eventd.EventExpander)1 EventIpcManagerDefaultImpl (org.opennms.netmgt.eventd.EventIpcManagerDefaultImpl)1 Eventd (org.opennms.netmgt.eventd.Eventd)1 EventHandler (org.opennms.netmgt.eventd.adaptors.EventHandler)1 EventIpcManagerEventHandlerProxy (org.opennms.netmgt.eventd.adaptors.EventIpcManagerEventHandlerProxy)1 EventReceiver (org.opennms.netmgt.eventd.adaptors.EventReceiver)1