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());
}
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;
}
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;
}
Aggregations