Search in sources :

Example 6 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService 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 7 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService 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 8 with MonitoredService

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

the class SshMonitorIT method testPollWithBannerOpenSSH.

@Test
public void testPollWithBannerOpenSSH() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "OpenSSH");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Up"), ps.isUp());
    assertFalse(createAssertMessage(ps, "not Down"), ps.isDown());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Test(org.junit.Test)

Example 9 with MonitoredService

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

the class SshMonitorIT method testPollWithBannerOpenSSHRegexp.

@Test
public void testPollWithBannerOpenSSHRegexp() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "^SSH\\-2\\.0\\-OpenSSH_\\d+\\.\\d+.*$");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Up"), ps.isUp());
    assertFalse(createAssertMessage(ps, "not Down"), ps.isDown());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Test(org.junit.Test)

Example 10 with MonitoredService

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

the class SshMonitorIT method testPollWithBannerMissing.

@Test
public void testPollWithBannerMissing() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "OpenNMS");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Down"), ps.isDown());
    assertFalse(createAssertMessage(ps, "not Up"), ps.isUp());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Test(org.junit.Test)

Aggregations

MonitoredService (org.opennms.netmgt.poller.MonitoredService)54 PollStatus (org.opennms.netmgt.poller.PollStatus)51 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)44 Test (org.junit.Test)39 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)31 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)27 HashMap (java.util.HashMap)22 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)9 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)6 ServerSocket (java.net.ServerSocket)6 Socket (java.net.Socket)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 Parameter (org.opennms.netmgt.config.poller.Parameter)5 InetAddress (java.net.InetAddress)3 Ignore (org.junit.Ignore)2 Package (org.opennms.netmgt.config.poller.Package)2 AbstractServiceMonitor (org.opennms.netmgt.poller.support.AbstractServiceMonitor)2