use of org.opennms.netmgt.poller.mock.MockMonitoredService 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.mock.MockMonitoredService 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.mock.MockMonitoredService in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollSvrStatus554.
@Test
public void testPollSvrStatus554() throws UnknownHostException, InterruptedException {
m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
System.out.println("S: 554 localhost.localdomain ESMTP bogon");
s.getOutputStream().write("554 localhost.localdomain ESMTP bogon\r\n".getBytes());
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String command = r.readLine();
System.out.println("C: " + command);
if (command.equals("QUIT")) {
System.out.println("S: 221-Goodbye, friend.");
s.getOutputStream().write("221-Goodbye, friend.\r\n".getBytes());
System.out.println("S: 221 See ya");
s.getOutputStream().write("221 See ya\r\n".getBytes());
}
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
ServiceMonitor sm = new SmtpMonitor();
MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("port", m_serverSocket.getLocalPort());
PollStatus ps = sm.poll(svc, parms);
assertTrue(ps.isUnavailable());
assertFalse(ps.isUp());
}
use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollCase1.
@Test
public void testPollCase1() throws UnknownHostException, InterruptedException {
m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
System.out.println("S: 220-localhost.localdomain ESMTP bogon");
s.getOutputStream().write("220-localhost.localdomain ESMTP bogon\r\n".getBytes());
System.out.println("S: 220-send me mail soon!");
s.getOutputStream().write("220-send me mail soon!\r\n".getBytes());
System.out.println("S: 220 send me mail now!");
s.getOutputStream().write("220 send me mail now!\r\n".getBytes());
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String command = r.readLine();
System.out.println("C: " + command);
if (command.startsWith("HELO ")) {
System.out.println("S: 250 Hello");
s.getOutputStream().write("250 Hello\r\n".getBytes());
}
command = r.readLine();
System.out.println("C: " + command);
if (command.equals("QUIT")) {
System.out.println("S: 250 Hello");
s.getOutputStream().write("221 See ya\r\n".getBytes());
}
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
ServiceMonitor sm = new SmtpMonitor();
MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("port", m_serverSocket.getLocalPort());
PollStatus ps = sm.poll(svc, parms);
assertTrue(ps.isUp());
assertFalse(ps.isDown());
}
use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.
the class HttpMonitorIT method callTestWithInvalidNodelabelHostName.
public void callTestWithInvalidNodelabelHostName(boolean preferIPv6) throws UnknownHostException {
if (m_runTests == false)
return;
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
PollStatus status = null;
ServiceMonitor monitor = new HttpMonitor();
MockMonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
svc.setNodeLabel("bad.virtual.host.example.com");
final int port = JUnitHttpServerExecutionListener.getPort();
if (port > 0) {
m.put("port", String.valueOf(port));
} else {
throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
}
m.put("retry", "0");
m.put("timeout", "500");
// Ensure that we get a 404 for this GET since we're using an inappropriate virtual host
m.put("response", "404");
m.put("verbose", "true");
m.put("nodelabel-host-name", "true");
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
Aggregations