Search in sources :

Example 1 with Graph

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

the class KscReportsMigrator method execute.

/* (non-Javadoc)
     * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
     */
@Override
public void execute() throws OnmsUpgradeException {
    log("Fixing KSC Reports.\n");
    boolean changed = false;
    List<SnmpInterface> interfacesToMerge = getInterfacesToMerge();
    for (Integer reportId : KSC_PerformanceReportFactory.getInstance().getReportList().keySet()) {
        Report report = KSC_PerformanceReportFactory.getInstance().getReportByIndex(reportId);
        log("  Checking report %s\n", report.getTitle());
        for (Graph graph : report.getGraphs()) {
            for (SnmpInterface intf : interfacesToMerge) {
                final String resourceId = graph.getResourceId().orElse(null);
                if (intf.shouldUpdate(resourceId)) {
                    changed = true;
                    log("  replacing resource ID %s with %s for %s\n", graph.getResourceId(), intf.getNewResourceId(), graph.getTitle());
                    graph.setResourceId(intf.getNewResourceId().toString());
                }
            }
        }
    }
    if (changed) {
        log("Updating the KSC reports configuration file.\n");
        try {
            KSC_PerformanceReportFactory.getInstance().saveCurrent();
        } catch (Exception e) {
            log("Warning: can't save KSC Reports because %s\n", e.getMessage());
        }
        if (isOpennmsRunning()) {
            log("In case the OpenNMS WebUI can't see the changes, go to Reports -> KSC Performance, Nodes, Domains and click on 'Request a Reload of KSC Reports Configuration'\n");
        }
    } else {
        log("No incomplete interface names detected.\n");
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException)

Example 2 with Graph

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

the class CustomReportController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // Get Form Variables
    Report report = KscReportEditor.getFromSession(request.getSession(), true).getWorkingReport();
    if (report == null) {
        throw new IllegalStateException("There is no working report");
    }
    //        int report_index = getReportFactory().getWorkingReportIndex();      
    //        String number_graphs[] = {"1", "2", "3", "4", "5", "6"};
    ArrayList<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphs().size());
    for (int i = 0; i < report.getGraphs().size(); i++) {
        final int index = i;
        Graph current_graph = report.getGraphs().get(index);
        PrefabGraph display_graph = getResourceService().getPrefabGraph(current_graph.getGraphtype());
        OnmsResource resource = getKscReportService().getResourceFromGraph(current_graph);
        Calendar begin_time = Calendar.getInstance();
        Calendar end_time = Calendar.getInstance();
        KSC_PerformanceReportFactory.getBeginEndTime(current_graph.getTimespan(), begin_time, end_time);
        KscResultSet resultSet = new KscResultSet(current_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
        resultSets.add(resultSet);
    }
    ModelAndView modelAndView = new ModelAndView("KSC/customReport");
    modelAndView.addObject("showTimeSpan", report.getShowTimespanButton());
    modelAndView.addObject("showGraphType", report.getShowGraphtypeButton());
    modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
    modelAndView.addObject("title", report.getTitle());
    modelAndView.addObject("resultSets", resultSets);
    return modelAndView;
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Graph(org.opennms.netmgt.config.kscReports.Graph) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsResource(org.opennms.netmgt.model.OnmsResource) Report(org.opennms.netmgt.config.kscReports.Report) KscResultSet(org.opennms.web.graph.KscResultSet) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 3 with Graph

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

the class KscReportEditor method getNewGraph.

/**
     * Create a new blank graph & initialize it
     *
     * @return a {@link org.opennms.netmgt.config.kscReports.Graph} object.
     */
private static Graph getNewGraph() {
    Graph new_graph = new Graph();
    new_graph.setTitle("");
    //new_graph.setGraphtype("mib2.bits");
    new_graph.setTimespan("7_day");
    return new_graph;
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph)

Example 4 with Graph

use of org.opennms.netmgt.config.kscReports.Graph 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 5 with Graph

use of org.opennms.netmgt.config.kscReports.Graph 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)

Aggregations

Graph (org.opennms.netmgt.config.kscReports.Graph)11 Report (org.opennms.netmgt.config.kscReports.Report)8 OnmsResource (org.opennms.netmgt.model.OnmsResource)6 ModelAndView (org.springframework.web.servlet.ModelAndView)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)4 ServletException (javax.servlet.ServletException)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 KscResultSet (org.opennms.web.graph.KscResultSet)2 MissingParameterException (org.opennms.web.servlet.MissingParameterException)2 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1