Search in sources :

Example 16 with PrefabGraph

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

the class PropertiesGraphDaoIT method testIncludeDirectoryIncludeMissingReportId.

@Test
public void testIncludeDirectoryIncludeMissingReportId() throws Exception {
    //We're expecting an ERROR log, and will be most disappointed if
    // we don't get it.  Turn off the default check in runTest
    m_testSpecificLoggingTest = true;
    File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
    File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
    File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
    m_outputStream = new FileOutputStream(rootFile);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_baseIncludePrefab);
    m_writer.close();
    m_outputStream.close();
    graphDirectory.mkdir();
    m_outputStream = new FileOutputStream(graphBits);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_separateBitsGraph.replace("report.id", "report.noid"));
    m_writer.close();
    m_outputStream.close();
    HashMap<String, Resource> perfConfig = new HashMap<String, Resource>();
    perfConfig.put("performance", new FileSystemResource(rootFile));
    PropertiesGraphDao dao = createPropertiesGraphDao(perfConfig, s_emptyMap);
    try {
        PrefabGraph graph = dao.getPrefabGraph("mib2.bits");
        fail("Shouldn't have gotten here; expecting an exception fetching " + graph);
    } catch (ObjectRetrievalFailureException e) {
    //Expected; no such graph
    }
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 17 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetOrder.

@Test
public void testGetOrder() {
    PrefabGraph bits = m_graphs.get("mib2.HCbits").getObject();
    ;
    assertEquals("getOrder", 0, bits.getOrder());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Test(org.junit.Test)

Example 18 with PrefabGraph

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

the class DefaultDistributedStatusServiceTest method expectResourceDaoCall.

private void expectResourceDaoCall(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> services) {
    PrefabGraph httpGraph = new PrefabGraph("http", "title", new String[] { "http" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    PrefabGraph httpsGraph = new PrefabGraph("https", "title", new String[] { "https" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    for (OnmsMonitoredService service : services) {
        OnmsResource resource = new OnmsResource("foo", "even more foo", new MockResourceType(), new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
        expect(m_resourceDao.getResourceForIpInterface(service.getIpInterface(), monitor)).andReturn(resource);
        expect(m_graphDao.getPrefabGraphsForResource(resource)).andReturn(new PrefabGraph[] { httpGraph, httpsGraph });
    }
    expect(m_graphDao.getPrefabGraph(httpGraph.getName())).andReturn(httpGraph).anyTimes();
    expect(m_graphDao.getPrefabGraph(httpsGraph.getName())).andReturn(httpsGraph).atLeastOnce();
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 19 with PrefabGraph

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

use of org.opennms.netmgt.model.PrefabGraph 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)

Aggregations

PrefabGraph (org.opennms.netmgt.model.PrefabGraph)50 Test (org.junit.Test)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)16 File (java.io.File)8 ArrayList (java.util.ArrayList)8 FileSystemResource (org.springframework.core.io.FileSystemResource)8 HashMap (java.util.HashMap)7 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)5 Resource (org.springframework.core.io.Resource)5 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 HashSet (java.util.HashSet)4 Report (org.opennms.netmgt.config.kscReports.Report)4 MockResourceType (org.opennms.netmgt.mock.MockResourceType)4 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)4 Calendar (java.util.Calendar)3 LinkedHashMap (java.util.LinkedHashMap)3 Graph (org.opennms.netmgt.config.kscReports.Graph)3