Search in sources :

Example 46 with MonitoredService

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

the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.

private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
    PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
    // For the purposes of this test, it's important the attributes are not added in lexicographical order
    Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
    props.put("ping1", Integer.valueOf(1));
    props.put("loss", Integer.valueOf(2));
    props.put("median", Integer.valueOf(3));
    pollStatus.setProperties(props);
    ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
    Package pkg = new Package();
    MockNetwork mockNetwork = new MockNetwork();
    mockNetwork.createStandardNetwork();
    MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
    pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
    LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
    MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
    Map<String, Object> params = Maps.newHashMap();
    params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
    params.put("rrd-base-name", "smtp-base");
    EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
    m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(null).once();
    m_rrdStrategy.createFile(EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
    EasyMock.expectLastCall().andReturn(null).once();
    // This is the important bit, the order of the values should match the order there were inserted above
    m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(m_rrdStrategy);
    // Trigger the poll
    lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
    // Verify
    EasyMock.verify(m_rrdStrategy);
    // Reset
    EasyMock.reset(m_rrdStrategy);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) LinkedHashMap(java.util.LinkedHashMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) AbstractServiceMonitor(org.opennms.netmgt.poller.support.AbstractServiceMonitor) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Package(org.opennms.netmgt.config.poller.Package)

Example 47 with MonitoredService

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

the class SSLCertMonitorIT method testExpiredDateForCertificate.

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

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * -1);
            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 48 with MonitoredService

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

the class SSLCertMonitorIT method testHostNameVerificationFails.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testHostNameVerificationFails() 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", "klatschmohnwiese");
    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 49 with MonitoredService

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

the class SSLCertMonitorIT method testInternetWebsite.

@Test
@Ignore
public void testInternetWebsite() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor();
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "443");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "www.google.com", DnsUtils.resolveHostname("www.google.com", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 50 with MonitoredService

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

the class SmtpMonitorIT method testPollSvrStatus554.

@Test
public void testPollSvrStatus554() 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: 554 localhost.localdomain ESMTP bogon");
                s.getOutputStream().write("554 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.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)

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