use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class TcpMonitorIT method testLocalhostIPv6Connection.
@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostIPv6Connection() throws UnknownHostException {
if (Boolean.getBoolean("skipIpv6Tests"))
return;
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
Parameter p = new Parameter();
ServiceMonitor monitor = new TcpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "::1", addr("::1"), "TCP");
p.setKey("port");
p.setValue("10342");
m.put(p.getKey(), p.getValue());
p.setKey("retry");
p.setValue("1");
m.put(p.getKey(), p.getValue());
p.setKey("timeout");
p.setValue("500");
m.put(p.getKey(), p.getValue());
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class TcpMonitorIT method testExternalServerConnection.
/*
* Test method for 'org.opennms.netmgt.poller.monitors.TcpMonitor.poll(NetworkInterface, Map, Package)'
*/
@Test
public void testExternalServerConnection() throws UnknownHostException {
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
Parameter p = new Parameter();
ServiceMonitor monitor = new TcpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(99, "www.opennms.org", DnsUtils.resolveHostname("www.opennms.org"), "TCP");
p.setKey("port");
p.setValue("3020");
m.put(p.getKey(), p.getValue());
p.setKey("retry");
p.setValue("1");
m.put(p.getKey(), p.getValue());
p.setKey("timeout");
p.setValue("500");
m.put(p.getKey(), p.getValue());
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
assertNotNull(status.getReason());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class TcpMonitorIT method testLocalhostConnection.
@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostConnection() throws UnknownHostException {
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
Parameter p = new Parameter();
ServiceMonitor monitor = new TcpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost"), "TCP");
p.setKey("port");
p.setValue("10342");
m.put(p.getKey(), p.getValue());
p.setKey("retry");
p.setValue("1");
m.put(p.getKey(), p.getValue());
p.setKey("timeout");
p.setValue("500");
m.put(p.getKey(), p.getValue());
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollCase3.
@Test
public void testPollCase3() 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());
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: 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.isUp());
assertFalse(ps.isDown());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollCase2.
@Test
public void testPollCase2() 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());
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());
System.out.println("S: 250 send me mail now!");
s.getOutputStream().write("250 send me mail now!\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());
}
Aggregations