Search in sources :

Example 1 with Report

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

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

the class CustomGraphEditDetailsController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String resourceId = request.getParameter(Parameters.resourceId.toString());
    if (resourceId == null) {
        throw new MissingParameterException(Parameters.resourceId.toString());
    }
    //optional parameter graphtype
    String prefabReportName = request.getParameter(Parameters.graphtype.toString());
    KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), true);
    Report report = editor.getWorkingReport();
    org.opennms.netmgt.config.kscReports.Graph sample_graph = editor.getWorkingGraph();
    if (sample_graph == null) {
        throw new IllegalArgumentException("Invalid working graph argument -- null pointer. Possibly missing prefab report in snmp-graph.properties?");
    }
    // Set the resourceId in the working graph in case it changed
    sample_graph.setResourceId(resourceId);
    OnmsResource resource = getKscReportService().getResourceFromGraph(sample_graph);
    PrefabGraph[] graph_options = getResourceService().findPrefabGraphsForResource(resource);
    PrefabGraph display_graph = null;
    if (graph_options.length > 0) {
        if (prefabReportName == null) {
            display_graph = graph_options[0];
        } else {
            display_graph = getPrefabGraphFromList(graph_options, sample_graph.getGraphtype());
        }
    }
    Calendar begin_time = Calendar.getInstance();
    Calendar end_time = Calendar.getInstance();
    KSC_PerformanceReportFactory.getBeginEndTime(sample_graph.getTimespan(), begin_time, end_time);
    KscResultSet resultSet = new KscResultSet(sample_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
    ModelAndView modelAndView = new ModelAndView("KSC/customGraphEditDetails");
    modelAndView.addObject("resultSet", resultSet);
    modelAndView.addObject("prefabGraphs", graph_options);
    modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(false));
    modelAndView.addObject("timeSpan", sample_graph.getTimespan());
    int graph_index = editor.getWorkingGraphIndex();
    int max_graphs = report.getGraphs().size();
    if (graph_index == -1) {
        graph_index = max_graphs++;
    }
    modelAndView.addObject("graphIndex", graph_index);
    modelAndView.addObject("maxGraphIndex", max_graphs);
    return modelAndView;
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report) KscResultSet(org.opennms.web.graph.KscResultSet) Calendar(java.util.Calendar) ModelAndView(org.springframework.web.servlet.ModelAndView) OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 3 with Report

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

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

the class KscReportEditor method getNewReport.

/** Create a new blank report & initialize it */
private static Report getNewReport() {
    Report new_report = new Report();
    new_report.setTitle("New Report Title");
    new_report.setShowGraphtypeButton(false);
    new_report.setShowTimespanButton(false);
    return new_report;
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report)

Example 5 with Report

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

the class KSC_PerformanceReportFactory method setIdsOnAllReports.

private void setIdsOnAllReports() {
    int i = 0;
    // Make sure that i is larger than the highest report ID
    for (Report report : m_config.getReports()) {
        if (report.getId() != null && report.getId().get() >= i) {
            i = report.getId().get() + 1;
        }
    }
    // Set IDs for any report lacking one.
    for (Report report : m_config.getReports()) {
        if (!(report.getId() != null)) {
            report.setId(i);
            i++;
        }
    }
}
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