Search in sources :

Example 6 with Report

use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.

the class KscRestService method addKscReport.

@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addKscReport(@Context final UriInfo uriInfo, final KscReport kscReport) {
    writeLock();
    try {
        LOG.debug("addKscReport: Adding KSC Report {}", kscReport);
        Report report = m_kscReportFactory.getReportByIndex(kscReport.getId());
        if (report != null) {
            throw getException(Status.CONFLICT, "Invalid request: Existing KSC report found with ID: {}.", Integer.toString(kscReport.getId()));
        }
        report = new Report();
        report.setId(kscReport.getId());
        report.setTitle(kscReport.getLabel());
        if (kscReport.getShowGraphtypeButton() != null) {
            report.setShowGraphtypeButton(kscReport.getShowGraphtypeButton());
        }
        if (kscReport.getShowTimespanButton() != null) {
            report.setShowTimespanButton(kscReport.getShowTimespanButton());
        }
        if (kscReport.getGraphsPerLine() != null) {
            report.setGraphsPerLine(kscReport.getGraphsPerLine());
        }
        if (kscReport.hasGraphs()) {
            for (KscGraph kscGraph : kscReport.getGraphs()) {
                final Graph graph = kscGraph.buildGraph();
                report.addGraph(graph);
            }
        }
        m_kscReportFactory.addReport(report);
        try {
            m_kscReportFactory.saveCurrent();
        } catch (final Exception e) {
            throw getException(Status.BAD_REQUEST, e.getMessage());
        }
        return Response.created(getRedirectUri(uriInfo, kscReport.getId())).build();
    } finally {
        writeUnlock();
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) ParseException(java.text.ParseException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 7 with Report

use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.

the class KscRestService method addGraph.

@PUT
@Path("{kscReportId}")
@Transactional
public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) {
    writeLock();
    try {
        if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") {
            throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!");
        }
        final Report report = m_kscReportFactory.getReportByIndex(kscReportId);
        if (report == null) {
            throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(kscReportId));
        }
        final Graph graph = new Graph();
        if (title != null) {
            graph.setTitle(title);
        }
        boolean found = false;
        for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) {
            if (valid.equals(timespan)) {
                found = true;
                break;
            }
        }
        if (!found) {
            LOG.debug("invalid timespan ('{}'), setting to '7_day' instead.", timespan);
            timespan = "7_day";
        }
        graph.setGraphtype(reportName);
        graph.setResourceId(resourceId);
        graph.setTimespan(timespan);
        report.addGraph(graph);
        m_kscReportFactory.setReport(kscReportId, report);
        try {
            m_kscReportFactory.saveCurrent();
        } catch (final Exception e) {
            throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) ParseException(java.text.ParseException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Report

use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.

the class RrdDashletConfigurationWindow method importKscReport.

/**
     * Import the KSC report with the given name
     */
private void importKscReport(int reportId) {
    Report report = kscPerformanceReportFactory.getReportByIndex(reportId);
    int columns = report.getGraphsPerLine().orElse(1);
    int rows = report.getGraphs().size() / columns;
    if (rows == 0) {
        rows = 1;
    }
    if (report.getGraphs().size() % columns > 0) {
        rows++;
    }
    for (int y = 0; y < m_gridLayout.getRows(); y++) {
        for (int x = 0; x < m_gridLayout.getColumns(); x++) {
            if (x >= columns || y >= rows) {
                m_gridLayout.removeComponent(x, y);
            }
        }
    }
    m_columnsSelect.setValue(columns);
    m_rowsSelect.setValue(rows);
    m_gridLayout.setColumns(columns);
    m_gridLayout.setRows(rows);
    int timeFrameValue = 1;
    int timeFrameType = Calendar.HOUR;
    int i = 0;
    for (int y = 0; y < m_gridLayout.getRows(); y++) {
        for (int x = 0; x < m_gridLayout.getColumns(); x++) {
            if (m_gridLayout.getComponent(x, y) == null) {
                RrdGraphEntry rrdGraphEntry = new RrdGraphEntry(m_nodeDao, m_rrdGraphHelper, x, y);
                rrdGraphEntry.setPreviewTimeFrame(timeFrameType, timeFrameValue);
                m_gridLayout.addComponent(rrdGraphEntry, x, y);
            }
            RrdGraphEntry rrdGraphEntry = (RrdGraphEntry) m_gridLayout.getComponent(x, y);
            /**
                 * setting the values if defined in the KSC report
                 */
            if (i < report.getGraphs().size()) {
                final int index = i;
                setRrdGraphEntryFromKscReportGraph(rrdGraphEntry, report.getGraphs().get(index));
            }
            rrdGraphEntry.update();
            i++;
        }
    }
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report)

Example 9 with Report

use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.

the class KSC_PerformanceReportFactory method getReportList.

/**
     * <p>getReportList</p>
     *
     * @return a {@link java.util.Map} object.
     */
public Map<Integer, String> getReportList() {
    LinkedHashMap<Integer, String> reports = new LinkedHashMap<Integer, String>(m_config.getReports().size());
    List<Report> reportList = m_config.getReports();
    Collections.sort(reportList, new Comparator<Report>() {

        @Override
        public int compare(Report o1, Report o2) {
            return o1.getTitle().compareTo(o2.getTitle());
        }
    });
    for (Report report : reportList) {
        reports.put(report.getId().get(), report.getTitle());
    }
    return Collections.unmodifiableMap(reports);
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with Report

use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.

the class KSC_PerformanceReportFactory method deleteReportAndSave.

/**
     * Deletes the indexed report and updates file configuration
     *
     * @param index a int.
     * @throws java.lang.ArrayIndexOutOfBoundsException if any.
     * @throws java.io.IOException if any.
     * @throws java.io.FileNotFoundException if any.
     */
public void deleteReportAndSave(int index) throws ArrayIndexOutOfBoundsException, IOException, FileNotFoundException {
    Report report = getReportByIndex(index);
    if (report == null) {
        throw new ArrayIndexOutOfBoundsException("Reports List index to be deleted is out of bounds: " + index);
    }
    m_config.removeReport(report);
    saveCurrent();
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report)

Aggregations

Report (org.opennms.netmgt.config.kscReports.Report)16 Graph (org.opennms.netmgt.config.kscReports.Graph)8 OnmsResource (org.opennms.netmgt.model.OnmsResource)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)4 Calendar (java.util.Calendar)3 ServletException (javax.servlet.ServletException)3 KscResultSet (org.opennms.web.graph.KscResultSet)3 MissingParameterException (org.opennms.web.servlet.MissingParameterException)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Path (javax.ws.rs.Path)2 Transactional (org.springframework.transaction.annotation.Transactional)2 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1