use of org.opennms.netmgt.model.OnmsNode 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.OnmsNode 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.OnmsNode in project opennms by OpenNMS.
the class PollContextIT method tearDown.
@After
public void tearDown() throws Exception {
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
m_nodeDao.flush();
MockLogAppender.assertNoWarningsOrGreater();
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class RestClient method getNodes.
public List<OnmsNode> getNodes() {
GenericType<List<OnmsNode>> nodes = new GenericType<List<OnmsNode>>() {
};
final WebTarget target = getTarget().path("nodes");
return getBuilder(target).get(nodes);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class LocationDataServiceIT method setUp.
@Before
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("log4j.logger.org.hibernate", "INFO");
p.setProperty("log4j.logger.org.hibernate.SQL", "DEBUG");
MockLogAppender.setupLogging(p);
OnmsMonitoringLocation location = new OnmsMonitoringLocation("RDU", "East Coast", new String[] { "example1" }, new String[0], "Research Triangle Park, NC", 35.715751f, -79.16262f, 1L, "odd");
m_monitoringLocationDao.saveOrUpdate(location);
OnmsApplication app = new OnmsApplication();
app.setName("TestApp1");
m_applicationDao.saveOrUpdate(app);
OnmsNode localhostNode = new OnmsNode(location, "localhost");
m_nodeDao.saveOrUpdate(localhostNode);
OnmsNode googleNode = new OnmsNode(location, "google");
m_nodeDao.saveOrUpdate(googleNode);
OnmsIpInterface localhostIpInterface = new OnmsIpInterface(addr("127.0.0.1"), localhostNode);
m_ipInterfaceDao.saveOrUpdate(localhostIpInterface);
OnmsIpInterface googleIpInterface = new OnmsIpInterface(addr("66.249.80.104"), googleNode);
m_ipInterfaceDao.saveOrUpdate(googleIpInterface);
OnmsServiceType httpServiceType = new OnmsServiceType("HTTP");
m_serviceTypeDao.saveOrUpdate(httpServiceType);
m_localhostHttpService = createService(app, localhostIpInterface, httpServiceType);
m_googleHttpService = createService(app, googleIpInterface, httpServiceType);
m_rduMonitor1 = new OnmsLocationMonitor();
m_rduMonitor1.setId(UUID.randomUUID().toString());
m_rduMonitor1.setLocation("RDU");
m_rduMonitor1.setLastUpdated(m_pollingEnd);
m_rduMonitor1.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.saveOrUpdate(m_rduMonitor1);
m_rduMonitor2 = new OnmsLocationMonitor();
m_rduMonitor2.setId(UUID.randomUUID().toString());
m_rduMonitor2.setLocation("RDU");
m_rduMonitor2.setLastUpdated(m_pollingEnd);
m_rduMonitor2.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.saveOrUpdate(m_rduMonitor2);
m_applicationDao.flush();
m_distPollerDao.flush();
m_nodeDao.flush();
m_ipInterfaceDao.flush();
m_serviceTypeDao.flush();
m_monitoredServiceDao.flush();
m_locationMonitorDao.flush();
OnmsApplication onmsApp = m_applicationDao.findByName("TestApp1");
assertTrue(onmsApp.equals(app));
assertEquals("Count of applications associated with services is wrong", 1, m_localhostHttpService.getApplications().size());
assertEquals("Count of applications associated with services is wrong", 1, m_googleHttpService.getApplications().size());
assertEquals("Count of services associated with application is wrong", 2, app.getMonitoredServices().size());
m_pollingEnd = new Date();
m_pollingStart = new Date(m_pollingEnd.getTime() - (1000 * 60 * 60 * 24));
}
Aggregations