Search in sources :

Example 6 with OnmsApplication

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

the class LocationDataManagerTest method testGetApplicationInfo.

@Test
public void testGetApplicationInfo() {
    String appName = "Domain Controllers";
    OnmsApplication app = m_applicationDao.findByName(appName);
    System.err.println("TEST testGetApplicationInfo: calling getApplicationInfo");
    m_locationDataService.getApplicationInfo(app, new StatusDetails());
}
Also used : StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) Test(org.junit.Test)

Example 7 with OnmsApplication

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

the class LocationDataServiceIT method setUp.

@Before
public void setUp() throws Exception {
    Properties p = new Properties();
    p.setProperty("log4j.logger.org.hibernate", "INFO");
    p.setProperty("log4j.logger.org.hibernate.SQL", "DEBUG");
    MockLogAppender.setupLogging(p);
    OnmsMonitoringLocation location = new OnmsMonitoringLocation("RDU", "East Coast", new String[] { "example1" }, new String[0], "Research Triangle Park, NC", 35.715751f, -79.16262f, 1L, "odd");
    m_monitoringLocationDao.saveOrUpdate(location);
    OnmsApplication app = new OnmsApplication();
    app.setName("TestApp1");
    m_applicationDao.saveOrUpdate(app);
    OnmsNode localhostNode = new OnmsNode(location, "localhost");
    m_nodeDao.saveOrUpdate(localhostNode);
    OnmsNode googleNode = new OnmsNode(location, "google");
    m_nodeDao.saveOrUpdate(googleNode);
    OnmsIpInterface localhostIpInterface = new OnmsIpInterface(addr("127.0.0.1"), localhostNode);
    m_ipInterfaceDao.saveOrUpdate(localhostIpInterface);
    OnmsIpInterface googleIpInterface = new OnmsIpInterface(addr("66.249.80.104"), googleNode);
    m_ipInterfaceDao.saveOrUpdate(googleIpInterface);
    OnmsServiceType httpServiceType = new OnmsServiceType("HTTP");
    m_serviceTypeDao.saveOrUpdate(httpServiceType);
    m_localhostHttpService = createService(app, localhostIpInterface, httpServiceType);
    m_googleHttpService = createService(app, googleIpInterface, httpServiceType);
    m_rduMonitor1 = new OnmsLocationMonitor();
    m_rduMonitor1.setId(UUID.randomUUID().toString());
    m_rduMonitor1.setLocation("RDU");
    m_rduMonitor1.setLastUpdated(m_pollingEnd);
    m_rduMonitor1.setStatus(MonitorStatus.STARTED);
    m_locationMonitorDao.saveOrUpdate(m_rduMonitor1);
    m_rduMonitor2 = new OnmsLocationMonitor();
    m_rduMonitor2.setId(UUID.randomUUID().toString());
    m_rduMonitor2.setLocation("RDU");
    m_rduMonitor2.setLastUpdated(m_pollingEnd);
    m_rduMonitor2.setStatus(MonitorStatus.STARTED);
    m_locationMonitorDao.saveOrUpdate(m_rduMonitor2);
    m_applicationDao.flush();
    m_distPollerDao.flush();
    m_nodeDao.flush();
    m_ipInterfaceDao.flush();
    m_serviceTypeDao.flush();
    m_monitoredServiceDao.flush();
    m_locationMonitorDao.flush();
    OnmsApplication onmsApp = m_applicationDao.findByName("TestApp1");
    assertTrue(onmsApp.equals(app));
    assertEquals("Count of applications associated with services is wrong", 1, m_localhostHttpService.getApplications().size());
    assertEquals("Count of applications associated with services is wrong", 1, m_googleHttpService.getApplications().size());
    assertEquals("Count of services associated with application is wrong", 2, app.getMonitoredServices().size());
    m_pollingEnd = new Date();
    m_pollingStart = new Date(m_pollingEnd.getTime() - (1000 * 60 * 60 * 24));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Properties(java.util.Properties) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 8 with OnmsApplication

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

the class OutageRestServiceIT method setUp.

@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    Assert.assertNotNull(populator);
    Assert.assertNotNull(applicationDao);
    populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {

        private OnmsOutage unresolvedOutage;

        private OnmsEvent outageEvent;

        private OnmsApplication application;

        @Override
        public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
            return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
        }

        @Override
        public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
            OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
            outageEvent = populator.buildEvent(distPoller);
            outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
            outageEvent.setEventCreateTime(new Date(1436881548292L));
            outageEvent.setEventTime(new Date(1436881548292L));
            populator.getEventDao().save(outageEvent);
            populator.getEventDao().flush();
            // create the application
            application = new OnmsApplication();
            application.setName("Awesome Application");
            dao.save(application);
            // get the SNMP service from node 1 and assign the application to it
            final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
            svc.addApplication(application);
            application.addMonitoredService(svc);
            populator.getMonitoredServiceDao().saveOrUpdate(svc);
            populator.getMonitoredServiceDao().flush();
            // create a unresolved outage
            unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
            populator.getOutageDao().save(unresolvedOutage);
            populator.getOutageDao().flush();
        }

        @Override
        public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
            // Delete OnmsApplications
            for (OnmsApplication application : dao.findAll()) {
                dao.delete(application);
            }
        }
    });
    populator.populateDatabase();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) ApplicationDao(org.opennms.netmgt.dao.api.ApplicationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 9 with OnmsApplication

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

the class StatusRestService method getApplications.

@GET
@Path("/applications")
public Response getApplications(@Context final UriInfo uriInfo) {
    final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
    final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
    final Query query = new Query(queryParameters, severityFilter);
    final List<StatusEntity<OnmsApplication>> applications = applicationStatusService.getStatus(query);
    final int totalCount = applicationStatusService.count(query);
    final int offset = queryParameters.getOffset();
    final List<ApplicationDTO> statusEntities = applications.stream().map(a -> {
        ApplicationDTO dto = new ApplicationDTO();
        dto.setId(a.getEntity().getId());
        dto.setName(a.getEntity().getName());
        dto.setSeverity(a.getStatus());
        return dto;
    }).collect(Collectors.toList());
    final ApplicationDTOList list = new ApplicationDTOList(statusEntities);
    list.setOffset(queryParameters.getOffset());
    list.setTotalCount(totalCount);
    return createResponse(list, offset, totalCount);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) QueryParameters(org.opennms.web.utils.QueryParameters) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Produces(javax.ws.rs.Produces) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) GET(javax.ws.rs.GET) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) ApplicationStatusService(org.opennms.features.status.api.application.ApplicationStatusService) Strings(com.google.common.base.Strings) MediaType(javax.ws.rs.core.MediaType) StatusSummary(org.opennms.features.status.api.StatusSummary) BusinessServiceStatusService(org.opennms.features.status.api.bsm.BusinessServiceStatusService) Map(java.util.Map) NodeQuery(org.opennms.features.status.api.node.NodeQuery) QueryParametersBuilder(org.opennms.web.utils.QueryParametersBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) SeverityFilter(org.opennms.features.status.api.SeverityFilter) Context(javax.ws.rs.core.Context) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Query(org.opennms.features.status.api.Query) NodeStatusService(org.opennms.features.status.api.node.NodeStatusService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityFilter(org.opennms.features.status.api.SeverityFilter) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) NodeQuery(org.opennms.features.status.api.node.NodeQuery) Query(org.opennms.features.status.api.Query) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with OnmsApplication

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

the class ApplicationDaoHibernate method getApplicationStatus.

@Override
public List<ApplicationStatus> getApplicationStatus(List<OnmsApplication> applications) {
    // Applications do not have a alarm mapping, so we grab all nodeDown, interfaceDown and serviceLost alarms
    // for all monitored services of each application to calculate the maximum severity (-> status)
    final List<ApplicationStatus> statusList = new ArrayList<>();
    for (OnmsApplication application : applications) {
        final Set<String> reductionKeys = new HashSet<>();
        for (OnmsMonitoredService eachService : application.getMonitoredServices()) {
            reductionKeys.addAll(ReductionKeyHelper.getReductionKeys(eachService));
        }
        if (!reductionKeys.isEmpty()) {
            final CriteriaBuilder builder = new CriteriaBuilder(OnmsAlarm.class);
            builder.in("reductionKey", reductionKeys);
            // findMatching would exepct OnmsApplications, but we need OnmsAlarms, so hack it
            HibernateCallback<List<OnmsAlarm>> callback = buildHibernateCallback(builder.toCriteria());
            List<OnmsAlarm> alarms = getHibernateTemplate().execute(callback);
            // All alarms for the current application have been determined, now get the max severity
            final Optional<OnmsAlarm> maxSeverity = alarms.stream().reduce((leftAlarm, rightAlarm) -> {
                if (leftAlarm.getSeverity().isGreaterThan(rightAlarm.getSeverity())) {
                    return leftAlarm;
                }
                return rightAlarm;
            });
            if (maxSeverity.isPresent()) {
                statusList.add(new ApplicationStatus(application, maxSeverity.get().getSeverity()));
            } else {
                // ensure that each application has a status
                statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
            }
        } else {
            // ensure that each application has a status
            statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
        }
    }
    return statusList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ApplicationStatus(org.opennms.netmgt.dao.api.ApplicationStatus) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

OnmsApplication (org.opennms.netmgt.model.OnmsApplication)42 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)20 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)14 ArrayList (java.util.ArrayList)13 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)12 Date (java.util.Date)11 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)11 LinkedList (java.util.LinkedList)8 Transactional (org.springframework.transaction.annotation.Transactional)6 HashSet (java.util.HashSet)5 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)4 StatusDetails (org.opennms.features.poller.remote.gwt.client.StatusDetails)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Test (org.junit.Test)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)3 DistributedStatusHistoryModel (org.opennms.web.svclayer.model.DistributedStatusHistoryModel)3 HashMap (java.util.HashMap)2