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;
}
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;
}
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);
}
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);
}
}
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();
}
}
Aggregations