Search in sources :

Example 1 with OutageSummary

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;
}
Also used : HashMap(java.util.HashMap) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) ArrayList(java.util.ArrayList)

Example 2 with OutageSummary

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);
}
Also used : OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) OutageCriteria(org.opennms.web.outage.filter.OutageCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 3 with OutageSummary

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());
}
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 4 with OutageSummary

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();
    }
}
Also used : OutageSummaryCollection(org.opennms.netmgt.model.outage.OutageSummaryCollection) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OutageSummary

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;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SQLException(java.sql.SQLException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Date(java.util.Date)

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.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedImpl (com.rometools.rome.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