Search in sources :

Example 66 with OnmsResource

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

use of org.opennms.netmgt.model.OnmsResource 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().orElse(null));
    modelAndView.addObject("showGraphType", report.getShowGraphtypeButton().orElse(null));
    modelAndView.addObject("graphsPerLine", report.getGraphsPerLine().orElse(0));
    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 68 with OnmsResource

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

the class DefaultGraphResultsService method findResults.

@Override
public GraphResults findResults(ResourceId[] resourceIds, String[] reports, long start, long end, String relativeTime) {
    if (resourceIds == null) {
        throw new IllegalArgumentException("resourceIds argument cannot be null");
    }
    if (reports == null) {
        throw new IllegalArgumentException("reports argument cannot be null");
    }
    if (end < start) {
        throw new IllegalArgumentException("end time cannot be before start time");
    }
    GraphResults graphResults = new GraphResults();
    graphResults.setStart(new Date(start));
    graphResults.setEnd(new Date(end));
    graphResults.setRelativeTime(relativeTime);
    graphResults.setRelativeTimePeriods(m_periods);
    graphResults.setReports(reports);
    HashMap<ResourceId, List<OnmsResource>> resourcesMap = new HashMap<>();
    for (ResourceId resourceId : resourceIds) {
        LOG.debug("findResults: parent, childType, childName = {}, {}, {}", resourceId.parent, resourceId.type, resourceId.name);
        OnmsResource resource = null;
        if (!resourcesMap.containsKey(resourceId.parent)) {
            List<OnmsResource> resourceList = m_resourceDao.getResourceById(resourceId).getChildResources();
            if (resourceList == null) {
                LOG.warn("findResults: zero child resources found for {}", resourceId.parent);
            } else {
                resourcesMap.put(resourceId.parent, resourceList);
                LOG.debug("findResults: add resourceList to map for {}", resourceId.parent);
            }
        }
        for (OnmsResource r : resourcesMap.get(resourceId.parent)) {
            if (resourceId.type.equals(r.getResourceType().getName()) && resourceId.name.equals(r.getName())) {
                resource = r;
                LOG.debug("findResults: found resource in map{}", r.toString());
                break;
            }
        }
        try {
            graphResults.addGraphResultSet(createGraphResultSet(resourceId, resource, reports, graphResults));
        } catch (IllegalArgumentException e) {
            LOG.warn(e.getMessage(), e);
            continue;
        }
    }
    graphResults.setGraphTopOffsetWithText(m_rrdDao.getGraphTopOffsetWithText());
    graphResults.setGraphLeftOffset(m_rrdDao.getGraphLeftOffset());
    graphResults.setGraphRightOffset(m_rrdDao.getGraphRightOffset());
    return graphResults;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) HashMap(java.util.HashMap) GraphResults(org.opennms.web.svclayer.model.GraphResults) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Date(java.util.Date)

Example 69 with OnmsResource

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

the class DefaultKscReportService method buildNodeSourceReport.

/**
 * {@inheritDoc}
 */
@Override
public Report buildNodeSourceReport(String nodeSource) {
    ResourceId resourceId = ResourceId.get("nodeSource", nodeSource);
    OnmsResource res = getResourceService().getResourceById(resourceId);
    return buildResourceReport(getResourceService(), res, "Node Report for Foreign Source:Id " + nodeSource);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId)

Example 70 with OnmsResource

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

the class DefaultKscReportService method buildNodeReport.

/**
 * {@inheritDoc}
 */
@Override
public Report buildNodeReport(int node_id) {
    ResourceId resourceId = ResourceId.get("node", Integer.toString(node_id));
    OnmsResource node = getResourceService().getResourceById(resourceId);
    return buildResourceReport(getResourceService(), node, "Node Report for Node Number " + node_id);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId)

Aggregations

OnmsResource (org.opennms.netmgt.model.OnmsResource)143 Test (org.junit.Test)54 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)28 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)23 File (java.io.File)22 ResourcePath (org.opennms.netmgt.model.ResourcePath)19 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)14 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)12 HashMap (java.util.HashMap)11 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)11 ResourceId (org.opennms.netmgt.model.ResourceId)11 Date (java.util.Date)10 Source (org.opennms.netmgt.measurements.model.Source)8 LinkedList (java.util.LinkedList)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7