Search in sources :

Example 11 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 12 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 13 with OnmsOutage

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

the class QueryManagerDaoImpl method updateResolvedOutageWithEventId.

/**
 * {@inheritDoc}
 */
@Override
public void updateResolvedOutageWithEventId(int outageId, int regainedEventId) {
    LOG.info("updating resolved outage {} with event id {}", outageId, regainedEventId);
    final OnmsEvent event = m_eventDao.get(regainedEventId);
    final OnmsOutage outage = m_outageDao.get(outageId);
    if (outage == null) {
        LOG.warn("Failed to update outage {} with event id {}. The outage no longer exists.", outageId, regainedEventId);
        return;
    }
    // Update the outage
    outage.setServiceRegainedEvent(event);
    m_outageDao.saveOrUpdate(outage);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage)

Example 14 with OnmsOutage

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

the class QueryManagerDaoImpl method closeOutagesForNode.

/**
 * <p>closeOutagesForNode</p>
 *
 * @param closeDate a {@link java.util.Date} object.
 * @param eventId a int.
 * @param nodeId a int.
 */
@Override
public void closeOutagesForNode(Date closeDate, int eventId, int nodeId) {
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
    for (OnmsOutage outage : outages) {
        outage.setIfRegainedService(closeDate);
        outage.setServiceRegainedEvent(m_eventDao.get(eventId));
        m_outageDao.update(outage);
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 15 with OnmsOutage

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

the class OutageRestService method getOutage.

/**
 * <p>getOutage</p>
 *
 * @param outageId a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsOutage} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{outageId}")
@Transactional
public Response getOutage(@Context final UriInfo uriInfo, @PathParam("outageId") final String outageId) {
    if ("summaries".equals(outageId)) {
        final MultivaluedMap<String, String> parms = uriInfo.getQueryParameters(true);
        int limit = 10;
        if (parms.containsKey("limit")) {
            limit = Integer.parseInt(parms.getFirst("limit"));
        }
        final List<OutageSummary> collection = m_outageDao.getNodeOutageSummaries(limit);
        return collection == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(new OutageSummaryCollection(collection)).build();
    } else {
        final OnmsOutage outage = m_outageDao.get(Integer.valueOf(outageId));
        return outage == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(outage).build();
    }
}
Also used : OutageSummaryCollection(org.opennms.netmgt.model.outage.OutageSummaryCollection) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsOutage (org.opennms.netmgt.model.OnmsOutage)47 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)26 Date (java.util.Date)23 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)16 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 Alias (org.opennms.core.criteria.Alias)5 Criteria (org.opennms.core.criteria.Criteria)5 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)5 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)5 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Before (org.junit.Before)3 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)3 Font (java.awt.Font)2