use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.
the class DaoWebOutageRepository method elimenateDuplicates.
private List<OutageSummary> elimenateDuplicates(final List<OutageSummary> outagesSummaries) {
final Map<Integer, OutageSummary> uniqueSummaries = new HashMap<Integer, OutageSummary>();
for (final OutageSummary outageSum : outagesSummaries) {
if (!uniqueSummaries.containsKey(outageSum.getNodeId())) {
uniqueSummaries.put(outageSum.getNodeId(), outageSum);
}
}
List<OutageSummary> uniqueList = new ArrayList<OutageSummary>(uniqueSummaries.values());
Collections.sort(uniqueList);
return uniqueList;
}
use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.
the class DaoWebOutageRepositoryIT method testGetOutageSummaries.
@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testGetOutageSummaries() {
OutageSummary[] summaries = m_daoOutageRepo.getMatchingOutageSummaries(new OutageCriteria());
assertEquals("there should be 2 outage summary in the default (current) outage criteria match", 2, summaries.length);
}
use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.
the class OutageDaoIT method testDuplicateOutages.
@Test
@Transactional
public void testDuplicateOutages() {
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(0);
System.err.println(outages);
assertEquals(3, outages.size());
}
use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.
the class OutageRestService method getOutage.
/**
* <p>getOutage</p>
*
* @param outageId a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsOutage} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{outageId}")
@Transactional
public Response getOutage(@Context final UriInfo uriInfo, @PathParam("outageId") final String outageId) {
if ("summaries".equals(outageId)) {
final MultivaluedMap<String, String> parms = uriInfo.getQueryParameters(true);
int limit = 10;
if (parms.containsKey("limit")) {
limit = Integer.parseInt(parms.getFirst("limit"));
}
final List<OutageSummary> collection = m_outageDao.getNodeOutageSummaries(limit);
return collection == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(new OutageSummaryCollection(collection)).build();
} else {
final OnmsOutage outage = m_outageDao.get(Integer.valueOf(outageId));
return outage == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(outage).build();
}
}
use of org.opennms.netmgt.model.outage.OutageSummary in project opennms by OpenNMS.
the class OutageFeed method getFeed.
/**
* <p>getFeed</p>
*
* @return a {@link com.rometools.rome.feed.synd.SyndFeed} object.
*/
@Override
public SyndFeed getFeed() {
SyndFeed feed = new SyndFeedImpl();
feed.setTitle("Nodes with Outages");
feed.setDescription("OpenNMS Nodes with Outages");
feed.setLink(getUrlBase() + "outage/list.htm");
List<SyndEntry> entries = new ArrayList<>();
try {
Date date = new Date();
date.setTime(date.getTime() - (1000 * 60 * 60 * 24));
OutageSummary[] summaries = OutageModel.getAllOutageSummaries(date);
SyndEntry entry;
int count = 0;
for (OutageSummary summary : summaries) {
if (count++ == this.getMaxEntries()) {
break;
}
String link = getUrlBase() + "element/node.jsp?node=" + summary.getNodeId();
entry = new SyndEntryImpl();
entry.setPublishedDate(summary.getTimeDown());
if (summary.getTimeUp() == null) {
entry.setTitle(sanitizeTitle(summary.getNodeLabel()));
entry.setUpdatedDate(summary.getTimeDown());
} else {
entry.setTitle(sanitizeTitle(summary.getNodeLabel()) + " (Resolved)");
entry.setUpdatedDate(summary.getTimeUp());
}
entry.setLink(link);
entry.setAuthor("OpenNMS");
entries.add(entry);
}
} catch (SQLException e) {
LOG.warn("unable to get current outages", e);
}
feed.setEntries(entries);
return feed;
}
Aggregations