use of org.opennms.netmgt.filter.api.FilterDao in project opennms by OpenNMS.
the class LatencyThresholdingSetIT method setUp.
@Before
public void setUp() throws Exception {
BeanUtils.setStaticApplicationContext(m_context);
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
// Use a mock FilterDao that always returns 127.0.0.1 in the active IP list
FilterDao filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(filterDao);
EasyMock.replay(filterDao);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<Event>();
}
use of org.opennms.netmgt.filter.api.FilterDao in project opennms by OpenNMS.
the class CollectdTest method setUp.
@Before
public 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();
// 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.setNodeDao(m_nodeDao);
m_collectd.setIpInterfaceDao(m_ipIfDao);
m_collectd.setFilterDao(m_filterDao);
m_collectd.setScheduler(m_scheduler);
m_collectd.setTransactionTemplate(transTemplate);
m_collectd.setPersisterFactory(new MockPersisterFactory());
m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml")));
}
use of org.opennms.netmgt.filter.api.FilterDao in project opennms by OpenNMS.
the class RrdSummaryControllerTest method canGenerateEmptySummary.
/**
* Verifies that an empty summary can be generated so an existing
* node without any resources.
*/
@Test
public void canGenerateEmptySummary() {
// Return a single node when called using the given filter
String rule = "ipaddr iplike 172.20.1.1";
FilterDao filterDao = mock(FilterDao.class);
when(filterDao.getNodeMap(rule)).thenReturn(ImmutableSortedMap.of(1, "node1"));
OnmsNode node = mock(OnmsNode.class);
NodeDao nodeDao = mock(NodeDao.class);
when(nodeDao.load(1)).thenReturn(node);
OnmsResource resource = mock(OnmsResource.class);
ResourceDao resourceDao = mock(ResourceDao.class);
when(resourceDao.getResourceForNode(node)).thenReturn(resource);
// Use our mocks
m_rrdSummaryService.setFilterDao(filterDao);
m_rrdSummaryService.setNodeDao(nodeDao);
m_rrdSummaryService.setResourceDao(resourceDao);
// Building the summary spec.
SummarySpecification summarySpec = new SummarySpecification();
summarySpec.setFilterRule("ipaddr iplike 172.20.1.1");
summarySpec.setStartTime(1472746964);
summarySpec.setEndTime(1473265364);
summarySpec.setAttributeSieve(".*");
// Invoke the controller
HttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = m_controller.processFormSubmission(response, summarySpec);
Summary summary = (Summary) mv.getModel().get("summary");
// Verify the response
assertEquals(0, summary.getResources().size());
}
use of org.opennms.netmgt.filter.api.FilterDao in project opennms by OpenNMS.
the class PollableServiceConfigTest method testPollableServiceConfig.
@Test
public void testPollableServiceConfig() throws Exception {
final FilterDao fd = mock(FilterDao.class);
FilterDaoFactory.setInstance(fd);
InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
PersisterFactory persisterFactory = new MockPersisterFactory();
ResourceStorageDao resourceStorageDao = new FilesystemResourceStorageDao();
final PollContext context = mock(PollContext.class);
final PollableNetwork network = new PollableNetwork(context);
final PollableNode node = network.createNodeIfNecessary(1, "foo", null);
final PollableInterface iface = new PollableInterface(node, InetAddressUtils.addr("127.0.0.1"));
final PollableService svc = new PollableService(iface, "MQ_API_DirectRte_v2");
final PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
final Package pkg = factory.getPackage("MapQuest");
final Timer timer = mock(Timer.class);
final PollableServiceConfig psc = new PollableServiceConfig(svc, factory, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, m_locationAwarePollerClient);
PollStatus pollStatus = psc.poll();
assertThat(pollStatus.getReason(), not(containsString("Unexpected exception")));
}
use of org.opennms.netmgt.filter.api.FilterDao in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptorIT method executeThresholdTest.
private void executeThresholdTest(Double[] rtValues) throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("rrd-repository", "/tmp");
parameters.put("ds-name", "icmp");
parameters.put("rrd-base-name", "icmp");
parameters.put("thresholding-enabled", "true");
FilterDao filterDao = m_mocks.createMock(FilterDao.class);
expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(filterDao);
MonitoredService svc = m_mocks.createMock(MonitoredService.class);
expect(svc.getNodeId()).andReturn(1);
expect(svc.getIpAddr()).andReturn("127.0.0.1").atLeastOnce();
expect(svc.getSvcName()).andReturn("ICMP").atLeastOnce();
expect(svc.getNodeLocation()).andReturn(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID).atLeastOnce();
ServiceMonitor service = new MockServiceMonitor(rtValues);
int step = 1;
List<String> rras = Collections.singletonList("RRA:AVERAGE:0.5:1:2016");
Package pkg = new Package();
Rrd rrd = new Rrd();
rrd.setStep(step);
rrd.setRras(rras);
pkg.setRrd(rrd);
expect(m_pollerConfig.getRRAList(pkg)).andReturn(rras).anyTimes();
expect(m_pollerConfig.getStep(pkg)).andReturn(step).anyTimes();
m_mocks.replayAll();
LatencyStoringServiceMonitorAdaptor adaptor = new LatencyStoringServiceMonitorAdaptor(m_pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
// Make sure that the ThresholdingSet initializes with test settings
String previousOpennmsHome = System.setProperty("opennms.home", "src/test/resources");
for (int i = 0; i < rtValues.length; i++) {
adaptor.handlePollResult(svc, parameters, service.poll(svc, parameters));
// Emulate the appropriate wait time prior inserting another value into the RRD files.
Thread.sleep(1000 * step);
}
System.setProperty("opennms.home", previousOpennmsHome);
m_mocks.verifyAll();
}
Aggregations