Search in sources :

Example 6 with Collector

use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.

the class CollectdTest method setupCollector.

private void setupCollector(String svcName, ServiceCollector svcCollector) throws CollectionInitializationException {
    MockServiceCollector.setDelegate(svcCollector);
    // Tell the config to use the MockServiceCollector for the specified service
    Collector collector = new Collector();
    collector.setService(svcName);
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_easyMockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfig = m_easyMockUtils.createMock(CollectdConfiguration.class);
    expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfig).anyTimes();
    expect(m_collectdConfig.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    expect(m_collectdConfig.getThreads()).andReturn(1).anyTimes();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Collector(org.opennms.netmgt.config.collectd.Collector) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory)

Example 7 with Collector

use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.

the class DuplicatePrimaryAddressIT method initialize.

/**
 * Initialize.
 *
 * @param scheduleExistingNodes true, to emulate having data on the database
 * @throws Exception the exception
 */
private void initialize(boolean scheduleExistingNodes) throws Exception {
    MockLogAppender.setupLogging();
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    FilterDaoFactory.setInstance(m_filterDao);
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            Assert.fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    OnmsNode n1 = netBuilder.addNode("node1").setId(1).setForeignSource("TestA").setForeignId("node1").getNode();
    OnmsIpInterface ip1 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    OnmsNode n2 = netBuilder.addNode("node2").setId(3).setForeignSource("TestB").setForeignId("node2").getNode();
    OnmsIpInterface ip2 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(4).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    Assert.assertNotSame(ip1.getNode().getId(), ip2.getNode().getId());
    List<OnmsIpInterface> initialIfs = new ArrayList<>();
    if (scheduleExistingNodes) {
        initialIfs.add(ip1);
        initialIfs.add(ip2);
    }
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(n1).anyTimes();
    EasyMock.expect(m_nodeDao.load(3)).andReturn(n2).anyTimes();
    createGetPackagesExpectation();
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ip1).anyTimes();
    EasyMock.expect(m_ifaceDao.load(4)).andReturn(ip2).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    m_collectd.afterPropertiesSet();
    m_collectd.start();
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) ArrayList(java.util.ArrayList) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File)

Example 8 with Collector

use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.

the class CollectdTest method setupCollector.

private void setupCollector(String svcName, boolean successfulInit) throws CollectionInitializationException {
    ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class);
    svcCollector.initialize();
    MockServiceCollector.setDelegate(svcCollector);
    // Tell the config to use the MockServiceCollector for the specified service
    Collector collector = new Collector();
    collector.setService(svcName);
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_easyMockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfig = m_easyMockUtils.createMock(CollectdConfiguration.class);
    expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfig).anyTimes();
    expect(m_collectdConfig.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    expect(m_collectdConfig.getThreads()).andReturn(1).anyTimes();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Collector(org.opennms.netmgt.config.collectd.Collector) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory)

Aggregations

Collector (org.opennms.netmgt.config.collectd.Collector)8 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)6 ServiceCollector (org.opennms.netmgt.collection.api.ServiceCollector)4 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)2 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2 MockTransactionTemplate (org.opennms.netmgt.dao.mock.MockTransactionTemplate)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)2 EasyMockUtils (org.opennms.test.mock.EasyMockUtils)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2