Search in sources :

Example 6 with PollStatus

use of org.opennms.netmgt.poller.PollStatus 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());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 7 with PollStatus

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());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 8 with PollStatus

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());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 9 with PollStatus

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());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 10 with PollStatus

use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.

the class PageSequenceMonitorIT method testVirtualHost.

@Test
public void testVirtualHost() throws Exception {
    m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + "  <page user-agent=\"Donald\" path=\"/\" scheme=\"https\" port=\"443\" successMatch=\"Get the Network to Work\" virtual-host=\"www.opennms.com\"/>\n" + "</page-sequence>\n");
    PollStatus status = m_monitor.poll(getHttpService("www.opennms.com"), 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));
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) Test(org.junit.Test)

Aggregations

PollStatus (org.opennms.netmgt.poller.PollStatus)200 Test (org.junit.Test)92 MonitoredService (org.opennms.netmgt.poller.MonitoredService)51 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)47 InetAddress (java.net.InetAddress)39 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)36 HashMap (java.util.HashMap)35 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)29 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)28 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)18 IOException (java.io.IOException)17 Socket (java.net.Socket)17 InputStreamReader (java.io.InputStreamReader)16 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)14 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)14 BufferedReader (java.io.BufferedReader)13 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)12 InterruptedIOException (java.io.InterruptedIOException)11 ConnectException (java.net.ConnectException)11 NoRouteToHostException (java.net.NoRouteToHostException)11