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(), 0L); if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else if (outage.getIfLostService().after(periodEnd)) { LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString()); continue; } else { begin = outage.getIfLostService(); if (outage.getIfRegainedService() == null) { } else if (outage.getIfRegainedService().after(periodEnd)) { end = outage.getIfRegainedService(); LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after outage end inside period {} to {}, discarding outage: {}", periodStart, periodEnd, outage.toString()); continue; } else { Long count = map.get(outage.getMonitoredService()); count += (end.getTime() - begin.getTime()); map.put(outage.getMonitoredService(), count);
/** {@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(); }
/** * This method should be called before scheduling services with outstanding * outages for the first time. * * If an outage is open, but has no lost service event, we will mark it as closed * with the current timestamp. This can happen if the poller daemon is stopped after * creating the outage record, but before the event was received back from the event bus. * * We close the outage immediately, as opposed to marking the service's initial state * as down since we do not know the cause, and determining the cause from the current * state of the database is error prone. * * Closing the outage immediately also prevents the daemon from creating * duplicate outstanding outage records. */ private void closeOutageIfSvcLostEventIsMissing(final OnmsOutage outage) { if (outage == null || outage.getServiceLostEvent() != null || outage.getIfRegainedService() != null) { // Nothing to do return; } LOG.warn("Outage {} was left open without a lost service event. " + "The outage will be closed.", outage); final Date now = new Date(); outage.setIfRegainedService(now); m_outageDao.update(outage); }
/** * When we save an outage, make sure to add the outage to the currentOutages * property of {@link OnmsMonitoredService}. */ @Override public Integer save(final OnmsOutage entity) { Integer retval = super.save(entity); if (entity.getIfRegainedService() == null) { entity.getMonitoredService().getCurrentOutages().add(entity); } return retval; }
/** * This method is necessary for CXF to be able to introspect * the type of {@link OnmsServiceType} parameters. */ public void setServiceType(OnmsServiceType type) { OnmsMonitoredService service = getMonitoredService(); if (service == null) { service = new OnmsMonitoredService(); setMonitoredService(service); } service.setServiceType(type); }
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)); if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else { begin = outage.getIfLostService(); 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);
/** * <p>getNodeId</p> * * @return a {@link java.lang.Integer} object. */ @Transient @XmlElement(name="nodeId") public Integer getNodeId(){ return getMonitoredService().getNodeId(); }
private static double getOutageTimeInWindow(List<OnmsOutage> outages, Date start, Date end) { if (outages == null || outages.size() == 0) { return 0.0d; } final long windowStart = start.getTime(); final long windowEnd = end.getTime(); final long windowLength = windowEnd - windowStart; Preconditions.checkArgument(0 <= windowStart && windowStart < windowEnd); long downtimeInWindow = 0; for (final OnmsOutage outage : outages) { // When did the service go down? // Use the start of the window if the service went down before this final long lostAt = Math.max(windowStart, outage.getIfLostService().getTime()); // When did the service come back up? long regainedAt; if (outage.getIfRegainedService() == null) { // It's still offline - use the end of the window regainedAt = windowEnd; } else { // Use the end of the window if the service came back up after this regainedAt = Math.min(windowEnd, outage.getIfRegainedService().getTime()); } downtimeInWindow += (regainedAt - lostAt); } // Bound the downtime by the length of the window return Math.min(downtimeInWindow, windowLength); }
outage.setServiceLostEvent(null); m_outageDao.update(outage); outageIds.add(outage.getId()); if (outageIds.contains(outage.getId())) { assertNotNull(outage.getIfRegainedService()); assertNull(outage.getServiceRegainedEvent()); } else { assertNull(outage.getIfRegainedService());
assertNotNull(httpOutages.get(0).getIfRegainedService()); assertNotNull(httpOutages.get(0).getIfLostService()); assertNotNull(httpOutages.get(0).getIfRegainedService()); assertNotNull(httpOutages.get(0).getServiceRegainedEvent()); assertNotNull(httpOutages.get(1).getIfRegainedService()); assertNotNull(httpOutages.get(1).getIfLostService()); assertNotNull(httpOutages.get(1).getIfRegainedService()); assertNotNull(httpOutages.get(1).getServiceRegainedEvent());
OnmsOutage outage = new OnmsOutage(); outage.setMonitoredService(icmpService); outage.setIfLostService(oneHourAgo); outage.setIfRegainedService(thirtyMinutesAgo); m_outageDao.save(outage); m_outageDao.flush();
/** {@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(); }
assertEquals(null, smtpOutages.get(0).getIfRegainedService()); assertNotNull(smtpOutages.get(0).getIfRegainedService()); assertNotNull(smtpOutages.get(0).getServiceRegainedEvent()); assertNull(smtpOutages.get(1).getIfRegainedService());
.filter(outage -> outage.getIfRegainedService() == null) .count();
final Set<OnmsOutage> outages = service.getCurrentOutages(); final OnmsOutage outage = (outages == null || outages.size() < 1 ? null : outages.iterator().next()); final OnmsEvent event = (outage == null ? null : outage.getServiceLostEvent()); final String ipAddr = InetAddressUtils.str(iface.getIpAddress()); final String serviceName = service.getServiceName(); boolean active = "A".equals(service.getStatus()); final Number svcLostEventId = event == null ? null : event.getId(); final Date ifLostService = outage == null ? null : outage.getIfLostService(); final String svcLostUei = event == null ? null : event.getEventUei();
/** * <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); } }
@Override protected Integer getId(final OnmsOutage outage) { return outage.getId(); }
final OnmsOutage resolved = new OnmsOutage(new Date(1436881548292L), new Date(1436881548292L), event, event, svc, null, null); getOutageDao().save(resolved); getOutageDao().flush(); final OnmsOutage unresolved = new OnmsOutage(new Date(1436881548292L), event, svc); getOutageDao().save(unresolved); getOutageDao().flush();
/** {@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); }
outage.setIfRegainedService(closeDate); m_outageDao.update(outage); outage.setIfRegainedService(closeDate); m_outageDao.update(outage);