Search in sources :

Example 1 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.

the class OutageDaoHibernate method matchingCurrentOutages.

/** {@inheritDoc} */
@Override
public Collection<OnmsOutage> matchingCurrentOutages(final ServiceSelector selector) {
    final Set<InetAddress> matchingAddrs = new HashSet<InetAddress>(m_filterDao.getIPAddressList(selector.getFilterRule()));
    final Set<String> matchingSvcs = new HashSet<String>(selector.getServiceNames());
    final List<OnmsOutage> matchingOutages = new LinkedList<OnmsOutage>();
    final Collection<OnmsOutage> outages = currentOutages();
    for (final OnmsOutage outage : outages) {
        final OnmsMonitoredService svc = outage.getMonitoredService();
        if ((matchingSvcs.contains(svc.getServiceName()) || matchingSvcs.isEmpty()) && matchingAddrs.contains(svc.getIpAddress())) {
            matchingOutages.add(outage);
        }
    }
    return matchingOutages;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) InetAddress(java.net.InetAddress) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 2 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.

the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.

protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
    OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
    if (onmsMonitoringLocation == null) {
        onmsMonitoringLocation = new OnmsMonitoringLocation();
        onmsMonitoringLocation.setLocationName(location);
        onmsMonitoringLocation.setLatitude(1.0f);
        onmsMonitoringLocation.setLongitude(1.0f);
        onmsMonitoringLocation.setMonitoringArea(location);
        onmsMonitoringLocation.setPriority(1L);
        m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
    }
    List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
    OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
    if (node == null) {
        node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
        node.setForeignSource(location);
        node.setForeignId(label);
        m_dbPopulator.getNodeDao().save(node);
    }
    int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
    OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
    if (ipInterface == null) {
        ipInterface = new OnmsIpInterface(addr(ip), node);
    }
    OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
    if (monitoredService == null) {
        monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
        m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
    }
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setEventUei("uei.opennms.org/" + location + "/" + label);
    event.setEventTime(new Date());
    event.setEventSource(location + "/" + label);
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("N");
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
    OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
    outage.setServiceLostEvent(event);
    m_dbPopulator.getOutageDao().save(outage);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 3 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.

the class TimelineRestService method image.

@GET
@Produces("image/png")
@Transactional
@Path("image/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response image(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @PathParam("ipAddress") final String ipAddress, @PathParam("serviceName") final String serviceName, @PathParam("start") final long start, @PathParam("end") final long end, @PathParam("width") final int width) throws IOException {
    long delta = end - start;
    OnmsOutageCollection onmsOutageCollection = queryOutages(uriInfo, nodeId, ipAddress, serviceName, start, end);
    BufferedImage bufferedImage = new BufferedImage(width, 20, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();
    graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    graphics2D.setColor(Color.BLACK);
    int numLabels = TimescaleDescriptor.computeNumberOfLabels(graphics2D, delta, width);
    for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
        if (desc.match(delta, numLabels)) {
            desc.drawGreen(graphics2D, width);
            for (OnmsOutage onmsOutage : onmsOutageCollection) {
                desc.drawEvent(graphics2D, delta, start, width, onmsOutage);
            }
            desc.drawLine(graphics2D, delta, start, width);
            break;
        }
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);
    byte[] imageData = baos.toByteArray();
    return Response.ok(imageData).build();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.

the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.

public void testGetCategoriesStatus() {
    View view = new View();
    Section section = new Section();
    section.setSectionName("Section One");
    section.addCategory("Category One");
    OnmsOutage outage = new OnmsOutage();
    Collection<OnmsOutage> outages = new ArrayList<OnmsOutage>();
    outage.setId(300);
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("superLabel");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    //iface.setId(9);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    outage.setMonitoredService(monSvc);
    outages.add(outage);
    view.addSection(section);
    List<String> services = new ArrayList<String>();
    services.add("HTTP");
    //		ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
    expect(viewDisplayDao.getView()).andReturn(view);
    expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
    expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
    replay(categoryDao);
    replay(viewDisplayDao);
    replay(outageDao);
    Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
    verify(viewDisplayDao);
    verify(categoryDao);
    verify(outageDao);
    assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
    for (StatusSection statusSection : statusSections) {
        assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
        Collection<StatusCategory> statusCategorys = statusSection.getCategories();
        for (StatusCategory statusCategory : statusCategorys) {
            assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
            //assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());				
            assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
            for (StatusNode statusNode : statusCategory.getNodes()) {
                assertEquals("Label does not match", "superLabel", statusNode.getLabel());
            }
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) StatusNode(org.opennms.web.svclayer.catstatus.model.StatusNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) View(org.opennms.netmgt.config.viewsdisplay.View) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) Section(org.opennms.netmgt.config.viewsdisplay.Section) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Aggregations

OnmsOutage (org.opennms.netmgt.model.OnmsOutage)44 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)24 Date (java.util.Date)20 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)15 OnmsNode (org.opennms.netmgt.model.OnmsNode)11 Test (org.junit.Test)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 Transactional (org.springframework.transaction.annotation.Transactional)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