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); }
/** * 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; }
/** * 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; }
if (outage.getIfRegainedService() == null || !outage.getIfRegainedService().before(periodEnd)) { end = periodEnd; } else { end = outage.getIfRegainedService();
if (outage.getIfRegainedService() == null || !outage.getIfRegainedService().before(periodEnd)) { end = periodEnd; } else { end = outage.getIfRegainedService();
if (outage.getIfRegainedService() == null) { } else if (outage.getIfRegainedService().after(periodEnd)) { end = outage.getIfRegainedService();
if (outage.getIfRegainedService() == null) { } else if (outage.getIfRegainedService().after(periodEnd)) { end = outage.getIfRegainedService();
/** * 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); }
.filter(outage -> outage.getIfRegainedService() == null) .count();
assertEquals(null, smtpOutages.get(0).getIfRegainedService()); assertNotNull(smtpOutages.get(0).getIfRegainedService()); assertNotNull(smtpOutages.get(0).getServiceRegainedEvent()); assertNull(smtpOutages.get(1).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());
assertNotNull(outage.getIfRegainedService()); assertNull(outage.getServiceRegainedEvent()); } else { assertNull(outage.getIfRegainedService());