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);
}
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();
}
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);
}
Aggregations