Search in sources :

Example 1 with OnmsOutageCollection

use of org.opennms.netmgt.model.OnmsOutageCollection 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 2 with OnmsOutageCollection

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

the class OutageRestService method forNodeId.

/**
 * <p>forNodeId</p>
 *
 * @param nodeId a int.
 * @param dateRange a long.
 * @param startTs a java.lang.Long.
 * @param endTs a java.lang.Long.
 * @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
@Path("forNode/{nodeId}")
public OnmsOutageCollection forNodeId(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @DefaultValue("604800000") @QueryParam("dateRange") final long dateRange, @QueryParam("start") final Long startTs, @QueryParam("end") final Long endTs) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
    builder.eq("node.id", nodeId);
    builder.alias("monitoredService", "monitoredService");
    builder.alias("monitoredService.ipInterface", "ipInterface");
    builder.alias("monitoredService.ipInterface.node", "node");
    builder.alias("monitoredService.serviceType", "serviceType");
    final MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.putAll(uriInfo.getQueryParameters());
    LOG.debug("Processing outages for node {} using {}", nodeId, params);
    if (startTs != null && endTs != null) {
        params.remove("start");
        params.remove("end");
        final Date start = new Date(startTs);
        final Date end = new Date(endTs);
        LOG.debug("Getting all outages from {} to {} for node {}", start, end, nodeId);
        builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.and(Restrictions.gt("ifLostService", start), Restrictions.lt("ifLostService", end)));
    } else {
        params.remove("dateRange");
        final Date start = new Date(System.currentTimeMillis() - dateRange);
        LOG.debug("Getting all outgae from {} to current date for node {}", start, nodeId);
        builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.gt("ifLostService", start));
    }
    applyQueryFilters(params, builder);
    builder.orderBy("id").desc();
    return new OnmsOutageCollection(m_outageDao.findMatching(builder.toCriteria()));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) MultivaluedMapImpl(org.opennms.web.rest.support.MultivaluedMapImpl) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsOutageCollection

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

the class TimelineRestService method queryOutages.

private OnmsOutageCollection queryOutages(final UriInfo uriInfo, final int nodeId, final String ipAddress, final String serviceName, final long start, final long end) {
    OnmsOutageCollection onmsOutageCollection;
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
    builder.eq("node.id", nodeId);
    final Date startDate = new Date();
    startDate.setTime(start * 1000l);
    final Date endDate = new Date();
    endDate.setTime(end * 1000l);
    builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.gt("ifRegainedService", startDate));
    builder.le("ifLostService", endDate);
    builder.eq("serviceType.name", serviceName);
    builder.eq("ipInterface.ipAddress", InetAddressUtils.addr(ipAddress));
    builder.alias("monitoredService", "monitoredService");
    builder.alias("monitoredService.ipInterface", "ipInterface");
    builder.alias("monitoredService.ipInterface.node", "node");
    builder.alias("monitoredService.serviceType", "serviceType");
    applyQueryFilters(uriInfo.getQueryParameters(), builder, null);
    builder.orderBy("id").desc();
    onmsOutageCollection = new OnmsOutageCollection(m_outageDao.findMatching(builder.toCriteria()));
    return onmsOutageCollection;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) Date(java.util.Date)

Example 4 with OnmsOutageCollection

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

the class TimelineRestService method html.

@GET
@Produces("text/html")
@Transactional
@Path("html/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response html(@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);
    final StringBuilder htmlBuffer = new StringBuilder();
    htmlBuffer.append("<img src=\"/opennms/rest/timeline/image/");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("/");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("/");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("/");
    htmlBuffer.append(start);
    htmlBuffer.append("/");
    htmlBuffer.append(end);
    htmlBuffer.append("/");
    htmlBuffer.append(width);
    htmlBuffer.append("\" usemap=\"#");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("-");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("-");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("\"><map name=\"");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("-");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("-");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("\">");
    for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
        if (desc.match(delta, numLabels)) {
            for (OnmsOutage onmsOutage : onmsOutageCollection) {
                htmlBuffer.append(desc.getMapEntry(graphics2D, delta, start, width, onmsOutage));
            }
            break;
        }
    }
    htmlBuffer.append("</map>");
    return Response.ok(htmlBuffer.toString()).build();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) 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 5 with OnmsOutageCollection

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

the class OutageRestService method getOutages.

/**
 * <p>getOutages</p>
 *
 * @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public OnmsOutageCollection getOutages(@Context final UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
    builder.alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN);
    builder.alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN);
    builder.alias("ipInterface.node", "node", JoinType.LEFT_JOIN);
    builder.alias("ipInterface.node.location", "location", JoinType.LEFT_JOIN);
    builder.alias("ipInterface.snmpInterface", "snmpInterface", JoinType.LEFT_JOIN);
    builder.alias("monitoredService.serviceType", "serviceType", JoinType.LEFT_JOIN);
    builder.alias("serviceLostEvent", "serviceLostEvent", JoinType.LEFT_JOIN);
    builder.alias("serviceRegainedEvent", "serviceRegainedEvent", JoinType.LEFT_JOIN);
    applyQueryFilters(uriInfo.getQueryParameters(), builder);
    final OnmsOutageCollection coll = new OnmsOutageCollection(m_outageDao.findMatching(builder.toCriteria()));
    // For getting totalCount
    coll.setTotalCount(m_outageDao.countMatching(builder.count().toCriteria()));
    return coll;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsOutageCollection (org.opennms.netmgt.model.OnmsOutageCollection)5 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Path (javax.ws.rs.Path)3 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)3 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 Date (java.util.Date)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MultivaluedMapImpl (org.opennms.web.rest.support.MultivaluedMapImpl)1