use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class StatsdValuesIT method testValue.
@Test
@Transactional
public void testValue() throws Exception {
final OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "node1");
node.setId(1);
m_nodeDao.save(node);
m_nodeDao.flush();
final OnmsResource resource = Iterables.getOnlyElement(m_resourceDao.getResourceForNode(node).getChildResources());
final OnmsAttribute attribute = resource.getRrdGraphAttributes().get("ifInOctets");
final double statistic = m_rrdDao.getPrintValue(attribute, "AVERAGE", 1414602000000L, 1417046400000L);
final TopNAttributeStatisticVisitor result = new TopNAttributeStatisticVisitor();
result.setCount(1);
final RrdStatisticAttributeVisitor visitor = new RrdStatisticAttributeVisitor();
visitor.setFetchStrategy(m_fetchStrategy);
visitor.setConsolidationFunction("AVERAGE");
visitor.setStartTime(1414602000000L);
visitor.setEndTime(1417046400000L);
visitor.setStatisticVisitor(result);
visitor.afterPropertiesSet();
visitor.visit(attribute);
Assert.assertNotNull(result.getResults());
Assert.assertEquals(1, result.getResults().size());
Assert.assertNotNull(result.getResults().first());
Assert.assertEquals(attribute, result.getResults().first().getAttribute());
Assert.assertEquals(statistic, result.getResults().first().getStatistic(), 0.5);
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class ReportDefinitionTest method testFilteredResourceAttributeFilteringWithNoMatch.
public void testFilteredResourceAttributeFilteringWithNoMatch() throws Exception {
final OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("Node One");
EasyMock.expect(m_nodeDao.load(1)).andReturn(node);
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
ReportDefinition def = createReportDefinition();
def.getReport().getPackage().setFilter("");
def.setResourceAttributeKey("ifSpeed");
def.setResourceAttributeValueMatch("100000000");
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
SortedMap<Integer, String> sortedNodeMap = new TreeMap<Integer, String>();
sortedNodeMap.put(node.getId(), node.getLabel());
EasyMock.expect(m_filterDao.getNodeMap("")).andReturn(sortedNodeMap);
EasyMock.expect(m_resourceDao.getResourceForNode(node)).andReturn(resource);
m_mocks.replayAll();
report.walk();
assertEquals("results size", 0, report.getResults().size());
}
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;
}
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());
modelAndView.addObject("showGraphType", report.getShowGraphtypeButton());
modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
modelAndView.addObject("title", report.getTitle());
modelAndView.addObject("resultSets", resultSets);
return modelAndView;
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testGetTopLevelResourceNodeExistsNoChildResources.
@Test
public void testGetTopLevelResourceNodeExistsNoChildResources() throws Exception {
OnmsNode node = createNode(2, "Node Two");
expect(m_nodeDao.get(node.getId().toString())).andReturn(node).times(1);
m_easyMockUtils.replayAll();
OnmsResource resource = m_resourceDao.getResourceById(ResourceId.get("node", "2"));
m_easyMockUtils.verifyAll();
assertNotNull("Resource should not be null", resource);
}
Aggregations