Search in sources :

Example 36 with OnmsMonitoredService

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

the class DefaultLocationDataService method getApplicationDetails.

/**
 * <p>getApplicationDetails</p>
 *
 * @param app a {@link org.opennms.netmgt.model.OnmsApplication} object.
 * @return a {@link org.opennms.features.poller.remote.gwt.client.ApplicationDetails} object.
 */
@Transactional
@Override
public ApplicationDetails getApplicationDetails(final OnmsApplication app) {
    waitForGeocoding("getApplicationDetails");
    final ApplicationInfo applicationInfo = getApplicationInfo(app, StatusDetails.unknown());
    List<GWTLocationSpecificStatus> statuses = new ArrayList<GWTLocationSpecificStatus>();
    final Date to = new Date();
    final Date from = new Date(to.getTime() - AVAILABILITY_MS);
    final Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(app);
    final List<GWTLocationMonitor> monitors = new ArrayList<GWTLocationMonitor>();
    for (final OnmsLocationMonitor monitor : m_locationDao.findByApplication(app)) {
        monitors.add(transformLocationMonitor(monitor));
        for (final OnmsLocationSpecificStatus locationSpecificStatus : m_locationDao.getStatusChangesForLocationBetween(from, to, monitor.getLocation())) {
            if (services.contains(locationSpecificStatus.getMonitoredService())) {
                statuses.add(transformLocationSpecificStatus(locationSpecificStatus));
            }
        }
    }
    ApplicationDetails details = new ApplicationDetails(applicationInfo, from, to, monitors, statuses);
    LOG.warn("getApplicationDetails({}) returning {}", app.getName(), details);
    return details;
}
Also used : GWTLocationSpecificStatus(org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ApplicationInfo(org.opennms.features.poller.remote.gwt.client.ApplicationInfo) ArrayList(java.util.ArrayList) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) ApplicationDetails(org.opennms.features.poller.remote.gwt.client.ApplicationDetails) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with OnmsMonitoredService

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

the class DefaultLocationDataService method getStatusDetailsForApplication.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public StatusDetails getStatusDetailsForApplication(final OnmsApplication app) {
    waitForGeocoding("getStatusDetailsForApplication");
    List<GWTLocationSpecificStatus> statuses = new ArrayList<GWTLocationSpecificStatus>();
    final Date to = new Date();
    final Date from = new Date(to.getTime() - AVAILABILITY_MS);
    final Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(app);
    final Set<GWTLocationMonitor> monitors = new LinkedHashSet<GWTLocationMonitor>();
    final Set<GWTMonitoredService> gwtServices = new LinkedHashSet<GWTMonitoredService>(services.size());
    for (final OnmsMonitoredService service : services) {
        gwtServices.add(transformMonitoredService(service));
    }
    for (OnmsLocationSpecificStatus status : m_locationDao.getStatusChangesForApplicationBetween(to, from, app.getName())) {
        monitors.add(transformLocationMonitor(status.getLocationMonitor()));
        statuses.add(transformLocationSpecificStatus(status));
    }
    StatusDetails statusDetails = new AppStatusDetailsComputer(from, to, monitors, gwtServices, statuses).compute();
    LOG.warn("getStatusDetailsForApplication({}) returning {}", app.getName(), statusDetails);
    return statusDetails;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) GWTMonitoredService(org.opennms.features.poller.remote.gwt.client.GWTMonitoredService) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) AppStatusDetailsComputer(org.opennms.features.poller.remote.gwt.client.AppStatusDetailsComputer) GWTLocationSpecificStatus(org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with OnmsMonitoredService

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

the class DefaultSurveillanceViewService method calculateServiceDownTime.

/**
 * Calculates and returns a map of service/downtime for a given period of time.
 *
 * @param periodEnd   the end of the period
 * @param periodStart the start of the period
 * @param outages     the outages encountered
 * @return a mapping of service/downtime
 */
private static Map<OnmsMonitoredService, Long> calculateServiceDownTime(Date periodEnd, Date periodStart, List<OnmsOutage> outages) {
    Map<OnmsMonitoredService, Long> map = new HashMap<OnmsMonitoredService, Long>();
    for (OnmsOutage outage : outages) {
        if (map.get(outage.getMonitoredService()) == null) {
            map.put(outage.getMonitoredService(), Long.valueOf(0));
        }
        Date begin;
        if (outage.getIfLostService().before(periodStart)) {
            begin = periodStart;
        } else {
            begin = outage.getIfLostService();
        }
        Date end;
        if (outage.getIfRegainedService() == null || !outage.getIfRegainedService().before(periodEnd)) {
            end = periodEnd;
        } else {
            end = outage.getIfRegainedService();
        }
        Long count = map.get(outage.getMonitoredService());
        count += (end.getTime() - begin.getTime());
        map.put(outage.getMonitoredService(), count);
    }
    return map;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 39 with OnmsMonitoredService

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

the class PathOutageStatusProviderIT method createOutage.

/**
 * This method creates an outage with a given parameters for the specified node
 * @param uie Event UIE
 * @param ipaddress IP-address (in dot-format)
 * @param node Node
 * @param severity Severity
 * @return Resulting outage
 * @throws UnknownHostException
 */
private OnmsOutage createOutage(String uie, String ipaddress, OnmsNode node, OnmsSeverity severity) throws UnknownHostException {
    OnmsEvent event = createEvent(uie, ipaddress, node, severity);
    eventDao.save(event);
    OnmsMonitoredService service = createService(node);
    monitoredServiceDao.save(service);
    OnmsOutage outage = new OnmsOutage(new Date(), event, service);
    return outage;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 40 with OnmsMonitoredService

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

the class QueryManagerDaoImpl method getNodeServices.

@Override
public List<String[]> getNodeServices(int nodeId) {
    final LinkedList<String[]> servicemap = new LinkedList<>();
    Criteria criteria = new Criteria(OnmsMonitoredService.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    // Ignore forced-unmanaged
    criteria.addRestriction(new NeRestriction("status", "F"));
    for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
        servicemap.add(new String[] { service.getIpAddressAsString(), service.getServiceName() });
    }
    return servicemap;
}
Also used : Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NeRestriction(org.opennms.core.criteria.restrictions.NeRestriction) Criteria(org.opennms.core.criteria.Criteria) LinkedList(java.util.LinkedList) 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