Search in sources :

Example 6 with OutageSummary

use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.

the class OutageDaoIT method testLimitDuplicateOutages.

@Test
@Transactional
public void testLimitDuplicateOutages() {
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "shoes");
    m_nodeDao.save(node);
    insertEntitiesAndOutage("172.16.1.1", "ICMP", node);
    insertEntitiesAndOutage("192.0.2.1", "ICMP", node);
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "megaphone");
    m_nodeDao.save(node);
    insertEntitiesAndOutage("172.16.1.2", "ICMP", node);
    insertEntitiesAndOutage("172.17.1.2", "ICMP", node);
    insertEntitiesAndOutage("172.18.1.2", "ICMP", node);
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "grunties");
    m_nodeDao.save(node);
    insertEntitiesAndOutage("172.16.1.3", "ICMP", node);
    List<OutageSummary> outages = m_outageDao.getNodeOutageSummaries(2);
    System.err.println(outages);
    assertEquals(2, outages.size());
    outages = m_outageDao.getNodeOutageSummaries(3);
    System.err.println(outages);
    assertEquals(3, outages.size());
    outages = m_outageDao.getNodeOutageSummaries(4);
    System.err.println(outages);
    assertEquals(3, outages.size());
    outages = m_outageDao.getNodeOutageSummaries(5);
    System.err.println(outages);
    assertEquals(3, outages.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with OutageSummary

use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.

the class OutageModel method getAllOutageSummaries.

/**
     * Return a list of IP addresses, the number of services down on each IP
     * address, and the longest time a service has been down for each IP
     * address. The list will be sorted by the amount of time it has been down.
     *
     * @param date the starting date for the query
     * @return an array of {@link org.opennms.netmgt.model.outage.OutageSummary} objects.
     * @throws java.sql.SQLException if any.
     */
public static OutageSummary[] getAllOutageSummaries(Date date) throws SQLException {
    OutageSummary[] summaries = new OutageSummary[0];
    final DBUtils d = new DBUtils(OutageModel.class);
    try {
        Connection conn = DataSourceFactory.getInstance().getConnection();
        d.watch(conn);
        PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT node.nodeid, node.location, outages.iflostservice as timeDown, outages.ifregainedservice as timeUp, node.nodelabel " + "FROM outages, node, ipinterface, ifservices " + "WHERE node.nodeid=ipinterface.nodeid " + "AND ipinterface.id=ifservices.ipinterfaceid AND ifservices.id=outages.ifserviceid " + "AND node.nodeType != 'D' " + "AND ipinterface.ismanaged != 'D' " + "AND ifservices.status != 'D' " + "AND outages.iflostservice >= ? " + "ORDER BY timeDown DESC;");
        d.watch(stmt);
        stmt.setTimestamp(1, new Timestamp(date.getTime()));
        ResultSet rs = stmt.executeQuery();
        d.watch(rs);
        List<OutageSummary> list = new ArrayList<OutageSummary>();
        while (rs.next()) {
            int nodeId = rs.getInt("nodeID");
            Timestamp timeDown = rs.getTimestamp("timeDown");
            Date downDate = new Date(timeDown.getTime());
            Timestamp timeUp = rs.getTimestamp("timeUp");
            Date upDate = null;
            if (timeUp != null) {
                upDate = new Date(timeUp.getTime());
            }
            String nodeLabel = rs.getString("nodelabel");
            list.add(new OutageSummary(nodeId, nodeLabel, downDate, upDate));
        }
        summaries = list.toArray(new OutageSummary[list.size()]);
    } finally {
        d.cleanUp();
    }
    return summaries;
}
Also used : OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 8 with OutageSummary

use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.

the class OutageBoxController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int rows = Integer.getInteger("opennms.nodesWithOutages.count", ROWS);
    final String parm = request.getParameter("outageCount");
    if (parm != null) {
        try {
            rows = Integer.valueOf(parm);
        } catch (NumberFormatException e) {
        // ignore, and let it fall back to the defaults
        }
    }
    OutageSummary[] summaries = m_webOutageRepository.getCurrentOutages(rows);
    int outagesRemaining = (m_webOutageRepository.countCurrentOutages() - summaries.length);
    ModelAndView modelAndView = new ModelAndView(getSuccessView());
    modelAndView.addObject("summaries", summaries);
    modelAndView.addObject("moreCount", outagesRemaining);
    return modelAndView;
}
Also used : OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) ModelAndView(org.springframework.web.servlet.ModelAndView)

Aggregations

OutageSummary (org.opennms.netmgt.model.outage.OutageSummary)8 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1