/** * <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); } }
/** {@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(); }
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
OnmsOutage outage = outageDao.currentOutageForService(service);
/** * 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); }
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
OnmsOutage out = outageDao.currentOutageForService(service); if (out != null) { countOutages++;
)); criteria.addRestriction(new NullRestriction("ifRegainedService")); List<OnmsOutage> outages = m_outageDao.findMatching(criteria); m_outageDao.update(outage); )); criteria.addRestriction(new NullRestriction("ifRegainedService")); outages = m_outageDao.findMatching(criteria); m_outageDao.update(outage);
private Map<Integer, List<OnmsOutage>> getOutages(List<Integer> nodeIds, List<String> serviceNames, Date start, Date end) { if (nodeIds == null || nodeIds.size() == 0) { return Maps.newHashMap(); } final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class) // The outage must have started before the end of the window .le("ifLostService", end) .or(new NullRestriction("ifRegainedService"), // The outage is ongoing new AllRestriction( // or the outage was cleared somewhere in the window new GtRestriction("ifRegainedService", start), new LeRestriction("ifRegainedService", end)) ) // Only select outages affecting our nodes .alias("monitoredService", "monitoredService") .alias("monitoredService.ipInterface", "ipInterface") .alias("ipInterface.node", "node") .eq("ipInterface.isManaged", "M") .in("node.id", nodeIds); // Only select outages affecting services with the given names, if set if (serviceNames != null && serviceNames.size() > 0) { builder.alias("monitoredService.serviceType", "serviceType") .in("serviceType.name", serviceNames); } // Retrieve the outages and group them by node id return m_outageDao.findMatching(builder.toCriteria()).stream() .collect(Collectors.groupingBy(OnmsOutage::getNodeId)); }
/** * <p>closeOutagesForInterface</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. */ @Override public void closeOutagesForInterface(Date closeDate, int eventId, int nodeId, String ipAddr) { 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 EqRestriction("ipInterface.ipAddress", addr(ipAddr))); 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); } }
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
criteria.addRestriction(new EqRestriction("serviceType.name", serviceName)); criteria.addRestriction(new NullRestriction("ifRegainedService")); List<OnmsOutage> outages = m_outageDao.findMatching(criteria); m_outageDao.update(outage); LOG.info("Calling closeOutagesForService: {}",outage);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
/** * Retrieves all of the outages (using DAOs) associated with * the given service. */ private List<OnmsOutage> getOutages(MockService svc) { OnmsMonitoredService monitoredSvc = m_monitoredServiceDao.get( svc.getNodeId(), svc.getAddress(), svc.getSvcName()); Criteria criteria = new CriteriaBuilder(OnmsOutage.class) .eq("monitoredService", monitoredSvc) .orderBy("ifLostService") .toCriteria(); return m_outageDao.findMatching(criteria); }