Search in sources :

Example 36 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultResourceDaoTest method testFindNodeResourcesWithDistributedResponseTime.

@Test
public void testFindNodeResourcesWithDistributedResponseTime() throws Exception {
    List<OnmsNode> nodes = new LinkedList<>();
    OnmsNode node = createNode();
    OnmsIpInterface ip = createIpInterface();
    node.addIpInterface(ip);
    nodes.add(node);
    expect(m_nodeDao.findAll()).andReturn(nodes);
    File response = m_fileAnticipator.tempDir("response");
    File distributed = m_fileAnticipator.tempDir(response, "distributed");
    File monitor = m_fileAnticipator.tempDir(distributed, LOCATION_MONITOR_ID);
    File ipDir = m_fileAnticipator.tempDir(monitor, "192.168.1.1");
    m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
    // Setup the status to match the path on disk
    OnmsLocationMonitor locMon = new OnmsLocationMonitor();
    locMon.setId(LOCATION_MONITOR_ID);
    OnmsIpInterface ipIntf = new OnmsIpInterface();
    ipIntf.setIpAddress(InetAddress.getByName("192.168.1.1"));
    LocationMonitorIpInterface locMonIpIntf = new LocationMonitorIpInterface(locMon, ipIntf);
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId())).andReturn(Collections.singleton(locMonIpIntf)).anyTimes();
    m_easyMockUtils.replayAll();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource list should not be null", resources);
    assertEquals("Resource list size", 1, resources.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) File(java.io.File) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 37 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultResourceDaoTest method testGetResourceForIpInterfaceWithLocationMonitor.

@Test
public void testGetResourceForIpInterfaceWithLocationMonitor() throws Exception {
    OnmsIpInterface ip = createIpInterfaceOnNode();
    OnmsLocationMonitor locMon = new OnmsLocationMonitor();
    locMon.setId(LOCATION_MONITOR_ID);
    // Create distributed/9850/209.61.128.9
    File response = m_fileAnticipator.tempDir("response");
    File distributed = m_fileAnticipator.tempDir(response, "distributed");
    File locMonDir = m_fileAnticipator.tempDir(distributed, locMon.getId().toString());
    File ipDir = m_fileAnticipator.tempDir(locMonDir, InetAddressUtils.str(ip.getIpAddress()));
    m_fileAnticipator.tempFile(ipDir, "http" + m_rrdFileExtension);
    ArrayList<LocationMonitorIpInterface> locationMonitorInterfaces = new ArrayList<>();
    locationMonitorInterfaces.add(new LocationMonitorIpInterface(locMon, ip));
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(ip.getNode().getId())).andReturn(locationMonitorInterfaces);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis() - 86400000l)).anyTimes();
    m_easyMockUtils.replayAll();
    OnmsResource resource = m_resourceDao.getResourceForIpInterface(ip, locMon);
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource should not be null", resource);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ArrayList(java.util.ArrayList) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 38 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultDistributedPollerService method getLocationMonitorDetails.

/**
 * {@inheritDoc}
 */
@Override
public LocationMonitorListModel getLocationMonitorDetails(LocationMonitorIdCommand cmd, BindingResult errors) {
    LocationMonitorListModel model = new LocationMonitorListModel();
    model.setErrors(errors);
    if (errors.getErrorCount() > 0) {
        return model;
    }
    OnmsLocationMonitor monitor = m_locationMonitorDao.load(cmd.getMonitorId());
    OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitor.getLocation());
    model.addLocationMonitor(new LocationMonitorModel(monitor, def));
    return model;
}
Also used : LocationMonitorListModel(org.opennms.web.svclayer.model.LocationMonitorListModel) LocationMonitorModel(org.opennms.web.svclayer.model.LocationMonitorListModel.LocationMonitorModel) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 39 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultDistributedPollerService method resumeLocationMonitor.

/**
 * {@inheritDoc}
 */
@Override
public void resumeLocationMonitor(LocationMonitorIdCommand command, BindingResult errors) {
    if (command == null) {
        throw new IllegalStateException("command argument cannot be null");
    }
    if (errors == null) {
        throw new IllegalStateException("errors argument cannot be null");
    }
    if (errors.hasErrors()) {
        return;
    }
    OnmsLocationMonitor monitor = m_locationMonitorDao.load(command.getMonitorId());
    if (monitor.getStatus() != MonitorStatus.PAUSED) {
        errors.addError(new ObjectError(MonitorStatus.class.getName(), new String[] { "distributed.locationMonitor.notPaused" }, new Object[] { command.getMonitorId() }, "Location monitor " + command.getMonitorId() + " is not paused."));
        return;
    }
    monitor.setStatus(MonitorStatus.STARTED);
    m_locationMonitorDao.update(monitor);
}
Also used : ObjectError(org.springframework.validation.ObjectError) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 40 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultDistributedStatusService method calculateCurrentStatus.

/**
 * <p>calculateCurrentStatus</p>
 *
 * @param monitors a {@link java.util.Collection} object.
 * @param applicationServices a {@link java.util.Collection} object.
 * @param statuses a {@link java.util.Collection} object.
 * @return a {@link org.opennms.web.svclayer.support.DefaultDistributedStatusService.Severity} object.
 */
public Severity calculateCurrentStatus(Collection<OnmsLocationMonitor> monitors, Collection<OnmsMonitoredService> applicationServices, Collection<OnmsLocationSpecificStatus> statuses) {
    int goodMonitors = 0;
    int badMonitors = 0;
    for (OnmsLocationMonitor monitor : monitors) {
        if (monitor == null || monitor.getStatus() != MonitorStatus.STARTED) {
            continue;
        }
        Severity status = calculateCurrentStatus(monitor, applicationServices, statuses);
        if (status == Severity.NORMAL) {
            goodMonitors++;
        } else if (status != Severity.INDETERMINATE) {
            badMonitors++;
        }
    }
    if (goodMonitors == 0 && badMonitors == 0) {
        // No current responses
        return Severity.INDETERMINATE;
    } else if (goodMonitors != 0 && badMonitors == 0) {
        // No bad responses
        return Severity.NORMAL;
    } else if (goodMonitors == 0 && badMonitors != 0) {
        // All bad responses
        return Severity.CRITICAL;
    } else if (goodMonitors != 0 && badMonitors != 0) {
        // Some bad responses
        return Severity.WARNING;
    } else {
        throw new IllegalStateException("Shouldn't have gotten here. " + "good monitors = " + goodMonitors + ", bad monitors = " + badMonitors);
    }
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Aggregations

OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)53 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)18 Date (java.util.Date)15 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)15 ArrayList (java.util.ArrayList)14 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)14 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)14 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)6 BindException (org.springframework.validation.BindException)6 HashSet (java.util.HashSet)5 ObjectError (org.springframework.validation.ObjectError)5 GWTLocationMonitor (org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Criteria (org.opennms.core.criteria.Criteria)3 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)3 LocationMonitorState (org.opennms.features.poller.remote.gwt.client.LocationMonitorState)3