Search in sources :

Example 31 with OnmsOutage

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);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage)

Example 32 with OnmsOutage

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);
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 33 with OnmsOutage

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();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Timestamp(java.sql.Timestamp) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 34 with OnmsOutage

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();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 35 with OnmsOutage

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;
}
Also used : NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) AllRestriction(org.opennms.core.criteria.restrictions.AllRestriction) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventConstants(org.opennms.netmgt.events.api.EventConstants) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Lists(com.google.common.collect.Lists) Map(java.util.Map) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Node(org.opennms.netmgt.xml.rtc.Node) Header(org.opennms.netmgt.xml.rtc.Header) GtRestriction(org.opennms.core.criteria.restrictions.GtRestriction) Logger(org.slf4j.Logger) OutageDao(org.opennms.netmgt.dao.api.OutageDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) Category(org.opennms.netmgt.xml.rtc.Category) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) LeRestriction(org.opennms.core.criteria.restrictions.LeRestriction) List(java.util.List) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Preconditions(com.google.common.base.Preconditions) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Transactional(org.springframework.transaction.annotation.Transactional) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) Node(org.opennms.netmgt.xml.rtc.Node) Date(java.util.Date) Header(org.opennms.netmgt.xml.rtc.Header) List(java.util.List) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsOutage (org.opennms.netmgt.model.OnmsOutage)47 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)26 Date (java.util.Date)23 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)16 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 Alias (org.opennms.core.criteria.Alias)5 Criteria (org.opennms.core.criteria.Criteria)5 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)5 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)5 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Before (org.junit.Before)3 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)3 Font (java.awt.Font)2