use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class MockNetworkTest method testInvalidPoll.
public void testInvalidPoll() throws UnknownHostException {
m_network.resetInvalidPollCount();
MonitoredService svc = new MockMonitoredService(99, "InvalidNode", InetAddressUtils.addr("1.1.1.1"), "ICMP");
ServiceMonitor monitor = m_pollerConfig.getServiceMonitor("ICMP");
monitor.poll(svc, Collections.emptyMap());
assertEquals(1, m_network.getInvalidPollCount());
}
use of org.opennms.netmgt.poller.MonitoredService 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();
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.
private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
// For the purposes of this test, it's important the attributes are not added in lexicographical order
Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
props.put("ping1", Integer.valueOf(1));
props.put("loss", Integer.valueOf(2));
props.put("median", Integer.valueOf(3));
pollStatus.setProperties(props);
ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
Package pkg = new Package();
MockNetwork mockNetwork = new MockNetwork();
mockNetwork.createStandardNetwork();
MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
Map<String, Object> params = Maps.newHashMap();
params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
params.put("rrd-base-name", "smtp-base");
EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().andReturn(null).once();
m_rrdStrategy.createFile(EasyMock.anyObject());
EasyMock.expectLastCall().once();
m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
EasyMock.expectLastCall().andReturn(null).once();
// This is the important bit, the order of the values should match the order there were inserted above
m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
EasyMock.expectLastCall().once();
EasyMock.replay(m_rrdStrategy);
// Trigger the poll
lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
// Verify
EasyMock.verify(m_rrdStrategy);
// Reset
EasyMock.reset(m_rrdStrategy);
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SeleniumMonitorTest method testPollStatusNotNull.
//Requires Firefox to be installed to run
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/testWar"))
public void testPollStatusNotNull() throws UnknownHostException {
MonitoredService monSvc = new MockMonitoredService(1, "papajohns", InetAddressUtils.addr("213.187.33.164"), "PapaJohnsSite");
Map<String, Object> params = new HashMap<String, Object>();
params.put("selenium-test", "SeleniumGroovyTest.groovy");
params.put("base-url", "localhost");
params.put("port", "10342");
SeleniumMonitor ajaxPSM = new SeleniumMonitor();
PollStatus pollStatus = ajaxPSM.poll(monSvc, params);
assertNotNull("PollStatus must not be null", pollStatus);
System.err.println("PollStatus message: " + pollStatus.getReason());
assertEquals(PollStatus.available(), pollStatus);
}
Aggregations