Search in sources :

Example 11 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)

Example 12 with MonitoredService

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

the class SSLCertMonitorIT method testExpiringDateForCertificate.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testExpiringDateForCertificate() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 4);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isUnavailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 13 with MonitoredService

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

the class SSLCertMonitorIT method testHostNameVerificationSucceeds.

@Test
@JUnitHttpServer(port = 10342, https = true, vhosts = "test.example.com")
public void testHostNameVerificationSucceeds() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    parameters.put("server-name", "${nodelabel}.example.com");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "test", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 14 with MonitoredService

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

the class SSLCertMonitorIT method testValidDateForCertificate.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testValidDateForCertificate() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 15 with MonitoredService

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

the class SshMonitorIT method testPollWithInvalidRegexpBanner.

@Test
public void testPollWithInvalidRegexpBanner() throws UnknownHostException, PatternSyntaxException {
    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+\\g$");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUnavailable());
    assertTrue(createAssertMessage(ps, "Unavailable"), ps.isUnavailable());
}
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)59 PollStatus (org.opennms.netmgt.poller.PollStatus)56 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)49 Test (org.junit.Test)43 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)31 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)31 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 Parameter (org.opennms.netmgt.config.poller.Parameter)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 InetAddress (java.net.InetAddress)4 Ignore (org.junit.Ignore)3 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)3 List (java.util.List)2