use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method updateOpenOutageWithEventId.
/**
* {@inheritDoc}
*/
@Override
public void updateOpenOutageWithEventId(int outageId, int lostEventId) {
LOG.info("updating open outage {} with event id {}", outageId, lostEventId);
final OnmsEvent event = m_eventDao.get(lostEventId);
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, lostEventId);
return;
}
// Update the outage
outage.setServiceLostEvent(event);
m_outageDao.saveOrUpdate(outage);
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForService.
/**
* <p>closeOutagesForService</p>
*
* @param closeDate a {@link java.util.Date} object.
* @param eventId a int.
* @param nodeId a int.
* @param ipAddr a {@link java.lang.String} object.
* @param serviceName a {@link java.lang.String} object.
*/
@Override
public void closeOutagesForService(Date closeDate, int eventId, int nodeId, String ipAddr, String serviceName) {
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("monitoredService.serviceType", "serviceType", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
criteria.addRestriction(new EqRestriction("serviceType.name", serviceName));
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);
LOG.info("Calling closeOutagesForService: {}", outage);
}
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method resolveOutagePendingRegainEventId.
/**
* {@inheritDoc}
*/
@Override
public Integer resolveOutagePendingRegainEventId(int nodeId, String ipAddr, String svcName, Date regainedTime) {
LOG.info("resolving outage for {}:{}:{} @ {}", nodeId, ipAddr, svcName, regainedTime);
final OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, InetAddressUtils.addr(ipAddr), svcName);
if (service == null) {
LOG.warn("Failed to resolve the pending outage for {}:{}:{} @ {}. The service could not be found.", nodeId, ipAddr, svcName, regainedTime);
return null;
}
final OnmsOutage outage = m_outageDao.currentOutageForService(service);
if (outage == null) {
return null;
}
// Update the outage
outage.setIfRegainedService(new Timestamp(regainedTime.getTime()));
m_outageDao.saveOrUpdate(outage);
return outage.getId();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method openOutagePendingLostEventId.
/**
* {@inheritDoc}
*/
@Override
public Integer openOutagePendingLostEventId(int nodeId, String ipAddr, String svcName, Date lostTime) {
LOG.info("opening outage for {}:{}:{} @ {}", nodeId, ipAddr, svcName, lostTime);
final OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, InetAddressUtils.addr(ipAddr), svcName);
final OnmsOutage outage = new OnmsOutage(lostTime, service);
m_outageDao.saveOrUpdate(outage);
return outage.getId();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class AvailabilityServiceHibernateImpl method getEuiLevel.
/**
* Optimized method for calculating the category statistics.
*
* We start off by retrieving outages affecting the nodes and services
* in the given category, and group these by node id.
*
* Using the outages, we calculate node-level statistics
* and tally the values to calculate the category statistics.
*/
@Override
@Transactional(readOnly = true)
public synchronized EuiLevel getEuiLevel(RTCCategory category) {
final Header header = new Header();
header.setVer("1.9a");
header.setMstation("");
// current time
final Date curDate = new Date();
final long curTime = curDate.getTime();
// get the rolling window
final long rWindow = 24L * 60L * 60L * 1000L;
LOG.debug("Retrieving availability statistics for {} with current date: {} and rolling window: {}", category.getLabel(), curDate, rWindow);
// create the data
final EuiLevel level = new EuiLevel();
// set created in m_header and add to level
header.setCreated(EventConstants.formatToString(curDate));
level.setHeader(header);
final Category levelCat = new Category();
// category label
levelCat.setCatlabel(category.getLabel());
double outageTimeInCategory = 0.0;
int numServicesInCategory = 0;
// window bounds
final Date windowStart = new Date(curTime - rWindow);
final Date windowEnd = new Date(curTime);
// category specifics
final List<Integer> nodeIds = getNodes(category);
final List<String> serviceNames = category.getServices();
// retrieve the outages associated with the given nodes, only retrieving those that affect our window
final Map<Integer, List<OnmsOutage>> outagesByNode = getOutages(nodeIds, serviceNames, windowStart, windowEnd);
// calculate the node level statistics
for (final int nodeId : nodeIds) {
List<OnmsOutage> outages = outagesByNode.get(nodeId);
if (outages == null) {
outages = Lists.newArrayList();
}
// sum the outage time
final double outageTime = getOutageTimeInWindow(outages, windowStart, windowEnd);
// determine the number of services
final int numServices = getNumServices(nodeId, serviceNames);
// count the number of outstanding outages
final long numServicesDown = outages.stream().filter(outage -> outage.getIfRegainedService() == null).count();
final Node levelNode = new Node();
levelNode.setNodeid(nodeId);
// value for this node for this category
levelNode.setNodevalue(RTCUtils.getOutagePercentage(outageTime, rWindow, numServices));
// node service count
levelNode.setNodesvccount(numServices);
// node service down count
levelNode.setNodesvcdowncount(numServicesDown);
// add the node
levelCat.getNode().add(levelNode);
// update the category statistics
numServicesInCategory += numServices;
outageTimeInCategory += outageTime;
}
// calculate the outage percentage using tallied values
levelCat.setCatvalue(RTCUtils.getOutagePercentage(outageTimeInCategory, rWindow, numServicesInCategory));
// add category
level.getCategory().add(levelCat);
LOG.debug("Done retrieving availability statistics for {} with {} services.", category.getLabel(), numServicesInCategory);
return level;
}
Aggregations