Search in sources :

Example 91 with OnmsNode

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);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) TopNAttributeStatisticVisitor(org.opennms.netmgt.dao.support.TopNAttributeStatisticVisitor) RrdStatisticAttributeVisitor(org.opennms.netmgt.dao.support.RrdStatisticAttributeVisitor) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 92 with OnmsNode

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) TreeMap(java.util.TreeMap) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 93 with OnmsNode

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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) After(org.junit.After)

Example 94 with OnmsNode

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);
}
Also used : GenericType(javax.ws.rs.core.GenericType) OnmsNode(org.opennms.netmgt.model.OnmsNode) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 95 with OnmsNode

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));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Properties(java.util.Properties) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23