Search in sources :

Example 11 with OnmsMonitoredService

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

the class DefaultDistributedStatusServiceTest method testCreateStatusPutUnreportedServicesLast.

public void testCreateStatusPutUnreportedServicesLast() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    command.setApplication(m_application1.getName());
    expect(m_applicationDao.findByName("Application 1")).andReturn(m_application1);
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(Collections.singleton(m_locationMonitor1_1));
    OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpService)).andReturn(null);
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpsService)).andReturn(new OnmsLocationSpecificStatus(m_locationMonitor1_1, httpsService, PollStatus.available()));
    expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1);
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createStatusTable(command, errors);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed status view for Application 1 from Raleigh location");
    expectedTable.addColumn("Node", "");
    expectedTable.addColumn("Monitor", "");
    expectedTable.addColumn("Service", "");
    expectedTable.addColumn("Status", "");
    expectedTable.addColumn("Response", "");
    expectedTable.addColumn("Last Status Change", "");
    expectedTable.addColumn("Last Update", "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Normal", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTPS", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Up", "bright");
    expectedTable.addCell("", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Indeterminate", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTP", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Unknown", "bright");
    expectedTable.addCell("No status recorded for this service from this location", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    assertTableEquals(expectedTable, table);
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) BindException(org.springframework.validation.BindException) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 12 with OnmsMonitoredService

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

the class DefaultDistributedStatusServiceTest method expectResourceDaoCall.

private void expectResourceDaoCall(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> services) {
    PrefabGraph httpGraph = new PrefabGraph("http", "title", new String[] { "http" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    PrefabGraph httpsGraph = new PrefabGraph("https", "title", new String[] { "https" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    for (OnmsMonitoredService service : services) {
        OnmsResource resource = new OnmsResource("foo", "even more foo", new MockResourceType(), new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
        expect(m_resourceDao.getResourceForIpInterface(service.getIpInterface(), monitor)).andReturn(resource);
        expect(m_graphDao.getPrefabGraphsForResource(resource)).andReturn(new PrefabGraph[] { httpGraph, httpsGraph });
    }
    expect(m_graphDao.getPrefabGraph(httpGraph.getName())).andReturn(httpGraph).anyTimes();
    expect(m_graphDao.getPrefabGraph(httpsGraph.getName())).andReturn(httpsGraph).atLeastOnce();
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 13 with OnmsMonitoredService

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

the class DefaultProvisionService method updateMonitoredServiceState.

@Transactional
@Override
public OnmsMonitoredService updateMonitoredServiceState(final Integer nodeId, final String ipAddress, final String svcName) {
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
    return new UpsertTemplate<OnmsMonitoredService, MonitoredServiceDao>(m_transactionManager, m_monitoredServiceDao) {

        @Override
        protected OnmsMonitoredService query() {
            return iface.getMonitoredServiceByServiceType(svcName);
        }

        @Override
        protected OnmsMonitoredService doUpdate(OnmsMonitoredService dbObj) {
            // NMS-3906
            LOG.debug("current status of service {} on node with IP {} is {} ", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress(), dbObj.getStatus());
            switch(dbObj.getStatus()) {
                case "S":
                    LOG.debug("suspending polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("F");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "R":
                    LOG.debug("resume polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("A");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "A":
                    // we can ignore active statuses
                    break;
                default:
                    LOG.warn("Unhandled state: {}", dbObj.getStatus());
                    break;
            }
            return dbObj;
        }

        @Override
        protected OnmsMonitoredService doInsert() {
            return null;
        }

        private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
            final EventBuilder bldr = new EventBuilder(eventUEI, "ProvisionService");
            bldr.setNodeid(dbObj.getNodeId());
            bldr.setInterface(dbObj.getIpAddress());
            bldr.setService(dbObj.getServiceName());
            m_eventForwarder.sendNow(bldr.getEvent());
        }
    }.execute();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with OnmsMonitoredService

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

the class MonitoredServiceDaoIT method testFindAllServices.

@Test
public void testFindAllServices() {
    final List<OnmsMonitoredService> allSvcs = m_monitoredServiceDao.findAllServices();
    assertTrue(allSvcs.size() > 1);
    for (OnmsMonitoredService ifservice : allSvcs) {
        assertNotNull(ifservice.getIpInterface());
        assertNotNull(ifservice.getIpInterface().getNode());
        assertNotNull(ifservice.getIpAddress());
        assertNotNull(ifservice.getNodeId());
        assertNotNull(ifservice.getServiceType());
    }
}
Also used : OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 15 with OnmsMonitoredService

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

the class QueryManagerDaoImpl method updateServiceStatus.

@Override
public void updateServiceStatus(int nodeId, String ipAddr, String serviceName, String status) {
    try {
        OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, InetAddress.getByName(ipAddr), serviceName);
        service.setStatus(status);
        m_monitoredServiceDao.saveOrUpdate(service);
    } catch (UnknownHostException e) {
        LOG.error("Failed to set the status for service named {} on node id {} and interface {} to {}.", serviceName, nodeId, ipAddr, status, e);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)119 Date (java.util.Date)37 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)27 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)25 Transactional (org.springframework.transaction.annotation.Transactional)22 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 HashSet (java.util.HashSet)9 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5