use of org.opennms.netmgt.poller.PollStatus 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());
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollCaseForCRLFCheck.
@Test
public void testPollCaseForCRLFCheck() 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");
// Having \r should fail in cheking for end of the line as the requirement is for CRLF
s.getOutputStream().write("220 localhost.localdomain ESMTP bogon\r".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.isUnavailable());
assertFalse(ps.isUp());
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class SmtpMonitorIT method testPoll.
@Test
public void testPoll() 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: 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.PollStatus in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testLoginDynamicCredentialsTwice.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentialsTwice() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)>Login (.)(.)(.)(.) Username and Password<\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <!-- Pick out the letters w-i-t-h to try and log in, this will fail -->\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" response-range=\"300-399\" locationMatch=\"/opennms/spring_security_login\\?login_error\" port=\"10342\" method=\"POST\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/spring_security_login\" query=\"login_error\" port=\"10342\" failureMatch=\"(?s)Log out\" failureMessage=\"Login should have failed but did not\" successMatch=\"Your login attempt was not successful\"/>\n" + " <!-- Pick out the letters d-e-m-o to try and log in, this will succeed -->\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)<hea(.)><titl(.)>.*</for(.)></b(.)dy>\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" response-range=\"300-399\" port=\"10342\" method=\"POST\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/events.html\" port=\"10342\" successMatch=\"Event Queries\" />\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_logout\" port=\"10342\" successMatch=\"Login with Username and Password\" />\n" + "</page-sequence>\n");
try {
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
} finally {
// Print some debug output if necessary
}
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testRedirectLocationDoesNotMatch.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRedirectLocationDoesNotMatch() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)<hea(.)><titl(.)>.*</for(.)></b(.)dy>\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\" locationMatch=\"/opensadfnms/\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + "</page-sequence>\n");
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected down but was " + status + ": reason = " + status.getReason(), status.isDown());
assertEquals("Failed to find '/opensadfnms/' in Location: header at http://127.0.0.1:10342/opennms/j_spring_security_check", status.getReason());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
Aggregations