Search in sources :

Example 46 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetTitle.

@Test
public void testGetTitle() {
    PrefabGraph bits = m_graphs.get("mib2.bits").getObject();
    ;
    assertEquals("getTitle", "Bits In/Out", bits.getTitle());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Test(org.junit.Test)

Example 47 with PrefabGraph

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

the class DefaultGraphResultsService method createGraphResultSet.

/**
     * <p>createGraphResultSet</p>
     *
     * @param resourceId a {@link java.lang.String} object.
     * @param resource a {@link org.opennms.netmgt.model.OnmsResource} object.
     * @param reports an array of {@link java.lang.String} objects.
     * @param graphResults a {@link org.opennms.web.svclayer.model.GraphResults} object.
     * @return a {@link org.opennms.web.svclayer.model.GraphResults.GraphResultSet}
     * object.
     */
private GraphResultSet createGraphResultSet(ResourceId resourceId, OnmsResource resource, String[] reports, GraphResults graphResults) throws IllegalArgumentException {
    if (resource == null) {
        resource = m_resourceDao.getResourceById(resourceId);
        if (resource == null) {
            throw new IllegalArgumentException("Could not find resource \"" + resourceId + "\"");
        }
    }
    GraphResultSet rs = graphResults.new GraphResultSet();
    rs.setResource(resource);
    if (reports.length == 1 && "all".equals(reports[0])) {
        PrefabGraph[] queries = m_graphDao.getPrefabGraphsForResource(resource);
        List<String> queryNames = new ArrayList<String>(queries.length);
        for (PrefabGraph query : queries) {
            queryNames.add(query.getName());
        }
        reports = queryNames.toArray(new String[queryNames.size()]);
    }
    List<Graph> graphs = new ArrayList<Graph>(reports.length);
    List<String> filesToPromote = new LinkedList<String>();
    for (String report : reports) {
        PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report);
        Graph graph = new Graph(prefabGraph, resource, graphResults.getStart(), graphResults.getEnd());
        getAttributeFiles(graph, filesToPromote);
        graphs.add(graph);
    }
    sendEvent(filesToPromote);
    /*
         * Sort the graphs by their order in the properties file. PrefabGraph
         * implements the Comparable interface.
         */
    Collections.sort(graphs);
    rs.setGraphs(graphs);
    return rs;
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Graph(org.opennms.web.svclayer.model.Graph) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ArrayList(java.util.ArrayList) GraphResultSet(org.opennms.web.svclayer.model.GraphResults.GraphResultSet) LinkedList(java.util.LinkedList)

Example 48 with PrefabGraph

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

the class DefaultKscReportService method buildResourceReport.

private static Report buildResourceReport(ResourceService service, OnmsResource parentResource, String title) {
    Report report = new Report();
    report.setTitle(title);
    report.setShowTimespanButton(true);
    report.setShowGraphtypeButton(true);
    List<OnmsResource> resources = service.findChildResources(parentResource, "interfaceSnmp");
    for (OnmsResource resource : resources) {
        PrefabGraph[] graphs = service.findPrefabGraphsForResource(resource);
        if (graphs.length == 0) {
            continue;
        }
        Graph graph = new Graph();
        graph.setTitle("");
        graph.setResourceId(resource.getId().toString());
        graph.setTimespan("7_day");
        graph.setGraphtype(graphs[0].getName());
        report.addGraph(graph);
    }
    return report;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report)

Example 49 with PrefabGraph

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

the class GraphResultsControllerTest method setUp.

/**
	 * Sets the up.
	 *
	 * @throws Exception the exception
	 */
@Before
public void setUp() throws Exception {
    m_service = EasyMock.createMock(GraphResultsService.class);
    PropertiesGraphDao graphDao = new PropertiesGraphDao();
    graphDao.loadProperties("performance", new FileSystemResource(new File("src/test/resources/etc/snmp-graph.properties")));
    List<PrefabGraph> prefabs = graphDao.getAllPrefabGraphs();
    Assert.assertNotNull(prefabs);
    Assert.assertFalse(prefabs.isEmpty());
    EasyMock.expect(m_service.getAllPrefabGraphs(ResourceId.get("node", "1").resolve("nodeSnmp", ""))).andReturn(prefabs.toArray(new PrefabGraph[prefabs.size()])).anyTimes();
    m_controller = new GraphResultsController();
    m_controller.setGraphResultsService(m_service);
    EasyMock.replay(m_service);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) GraphResultsService(org.opennms.web.svclayer.api.GraphResultsService) PropertiesGraphDao(org.opennms.netmgt.dao.support.PropertiesGraphDao) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Before(org.junit.Before)

Example 50 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetPrefabGraphsForResourceWithSuppress.

@Test
public void testGetPrefabGraphsForResourceWithSuppress() {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interface");
    HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
    attributes.add(new RrdGraphAttribute("ifInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifOutOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifHCInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifHCOutOctets", "", ""));
    attributes.add(new ExternalValueAttribute("ifSpeed", ""));
    OnmsResource resource = new OnmsResource("node", "1", resourceType, attributes, ResourcePath.get("foo"));
    PrefabGraph[] graphs = m_dao.getPrefabGraphsForResource(resource);
    assertEquals("prefab graph array size", 1, graphs.length);
    assertEquals("prefab graph[0] name", "mib2.HCbits", graphs[0].getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet) Test(org.junit.Test)

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