Search in sources :

Example 1 with PollStatus

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

the class RadiusAuthMonitorTest method testResponse.

@Test
@Ignore("have to have a radius server set up")
public void testResponse() throws Exception {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new RadiusAuthMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("192.168.211.11"), "RADIUS");
    m.put("user", "testing");
    m.put("password", "password");
    m.put("retry", "1");
    m.put("secret", "testing123");
    m.put("authtype", "chap");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with PollStatus

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

the class PollerClientRpcModule method execute.

@Override
public CompletableFuture<PollerResponseDTO> execute(PollerRequestDTO request) {
    final String className = request.getClassName();
    final ServiceMonitor monitor = serviceMonitorRegistry.getMonitorByClassName(className);
    if (monitor == null) {
        return CompletableFuture.completedFuture(new PollerResponseDTO(PollStatus.unknown("No monitor found with class name '" + className + "'.")));
    }
    return CompletableFuture.supplyAsync(new Supplier<PollerResponseDTO>() {

        @Override
        public PollerResponseDTO get() {
            PollStatus pollStatus;
            try {
                final Map<String, Object> parameters = request.getMonitorParameters();
                pollStatus = monitor.poll(request, parameters);
            } catch (RuntimeException e) {
                pollStatus = PollStatus.unknown(e.getMessage());
            }
            return new PollerResponseDTO(pollStatus);
        }
    }, executor);
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) Map(java.util.Map)

Example 3 with PollStatus

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

the class JCifsMonitorTest method testPoll.

@Test
public void testPoll() throws UnknownHostException {
    MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddress.getByName("10.123.123.123"), "JCIFS");
    Map<String, Object> m = Collections.synchronizedMap(new TreeMap<String, Object>());
    replay(mockSmbFolderEmpty, mockSmbFolderNotEmpty, mockSmbFileValidPath, mockSmbFileInvalidPath, SmbFile.class);
    JCifsMonitor jCifsMonitor = new JCifsMonitor();
    PollStatus pollStatus;
    /*
         * checking path does exist and mode is PATH_EXIST => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking path does not exist and mode is PATH_EXIST => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/invalidPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking path does exist and mode is PATH_NOT_EXIST => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_NOT_EXIST");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking path does not exist and mode is PATH_NOT_EXIST => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_NOT_EXIST");
    m.put("path", "/invalidPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder not empty and mode is FOLDER_EMPTY => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_EMPTY");
    m.put("path", "/folderNotEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking folder empty and mode is FOLDER_EMPTY => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_EMPTY");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder not empty and mode is FOLDER_NOT_EMPTY => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_NOT_EMPTY");
    m.put("path", "/folderNotEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder empty and mode is FOLDER_NOT_EMPTY => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_NOT_EMPTY");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for invalid mode => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "ABC");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.unknown(), pollStatus);
    /*
         * checking for SmbException => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/smbException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for MalformedUrlException => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/malformedUrlException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for overriding Ip address via empty string => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("smbHost", "");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking for overriding Ip address via smbHost => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("smbHost", "192.168.0.123");
    m.put("path", "/smbException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    assertTrue(pollStatus.getReason().matches(".*192\\.168\\.0\\.123.*"));
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) EasyMock.anyObject(org.easymock.EasyMock.anyObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PollStatus

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

the class MinionHeartbeatMonitor method poll.

@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
    // Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat
    final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000);
    // Get the minion to test whereas the minion ID is the nodes foreign ID by convention
    final OnmsNode node = nodeDao.get().get(svc.getNodeId());
    final OnmsMinion minion = minionDao.get().findById(node.getForeignId());
    // Calculate the time since the last heartbeat was received
    final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime();
    final PollStatus status;
    if (lastSeen <= period) {
        status = PollStatus.available();
    } else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) {
        status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat.");
    } else {
        status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0));
    }
    return status;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion)

Example 5 with PollStatus

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

the class MockMonitor method doPoll.

private PollStatus doPoll(int nodeId, String ipAddr, String svcName) {
    synchronized (m_network) {
        MockService svc = m_network.getService(nodeId, ipAddr, svcName);
        if (svc == null) {
            LOG.info("Invalid Poll: {}/{}/{}", nodeId, ipAddr, svcName);
            m_network.receivedInvalidPoll(ipAddr, svcName);
            return PollStatus.unknown("Mock.");
        } else {
            LOG.info("Poll: [{}/{}/{}]", svc.getInterface().getNode().getLabel(), ipAddr, svcName);
            PollStatus pollStatus = svc.poll();
            return PollStatus.get(pollStatus.getStatusCode(), pollStatus.getReason());
        }
    }
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus)

Aggregations

PollStatus (org.opennms.netmgt.poller.PollStatus)209 Test (org.junit.Test)98 MonitoredService (org.opennms.netmgt.poller.MonitoredService)57 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)53 InetAddress (java.net.InetAddress)40 HashMap (java.util.HashMap)36 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)36 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)32 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)29 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