Search in sources :

Example 16 with OnmsIpInterface

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

the class PollerBackEndIT method testReportResults.

@Test
@Transactional
public void testReportResults() throws InterruptedException {
    final OnmsNode node = new OnmsNode(m_monitoringLocationDao.getDefaultLocation(), "foo");
    final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr("192.168.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("HTTP");
    if (serviceType == null) {
        serviceType = new OnmsServiceType("HTTP");
        m_serviceTypeDao.save(serviceType);
        m_serviceTypeDao.flush();
    }
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    iface.setMonitoredServices(Collections.singleton(service));
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
    final int serviceId = service.getId();
    // make sure there is no rrd data
    final File rrdFile = new File("target/test-data/distributed/" + locationMonitorId + "/" + InetAddressUtils.str(iface.getIpAddress()) + "/http" + m_rrdStrategy.getDefaultFileExtension());
    if (rrdFile.exists()) {
        rrdFile.delete();
    }
    assertFalse(rrdFile.exists());
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.available(1234.0));
    Thread.sleep(1000);
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.unavailable());
    final Collection<OnmsLocationSpecificStatus> statuses = m_locationMonitorDao.getStatusChangesForLocationBetween(new Date(0L), new Date(), "RDU");
    assertEquals(2, statuses.size());
    final Iterator<OnmsLocationSpecificStatus> statusIterator = statuses.iterator();
    final OnmsLocationSpecificStatus status1 = statusIterator.next();
    final OnmsLocationSpecificStatus status2 = statusIterator.next();
    assertEquals(Double.valueOf(1234D), status1.getPollResult().getResponseTime());
    assertNull(status2.getPollResult().getResponseTime());
    assertTrue("rrd file doesn't exist at " + rrdFile.getAbsolutePath(), rrdFile.exists());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with OnmsIpInterface

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

the class InterfaceToNodeCacheDaoImplIT method setUp.

@Before
public void setUp() throws Exception {
    m_databasePopulator.populateDatabase();
    m_cache.dataSourceSync();
    OnmsNode n = new OnmsNode(m_databasePopulator.getMonitoringLocationDao().getDefaultLocation(), "my-new-node");
    n.setForeignSource("junit");
    n.setForeignId("10001");
    OnmsIpInterface iface = new OnmsIpInterface(InetAddress.getByName("192.168.1.3"), n);
    iface.setIsManaged("M");
    iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
    OnmsSnmpInterface snmpIf = new OnmsSnmpInterface(n, 1001);
    iface.setSnmpInterface(snmpIf);
    snmpIf.getIpInterfaces().add(iface);
    n.addIpInterface(iface);
    m_databasePopulator.getNodeDao().save(n);
    m_testNodeId = n.getId();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Before(org.junit.Before)

Example 18 with OnmsIpInterface

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

the class IpInterfaceDaoHibernateIT method testNMS4822.

@Test
@Transactional
public void testNMS4822() throws Exception {
    // Verify that test IP address exists on Node1 as non-primary
    OnmsIpInterface ipIntf = m_ipInterfaceDao.findByNodeIdAndIpAddress(m_databasePopulator.getNode1().getId(), m_testAddress.getHostAddress());
    assertFalse(ipIntf.isPrimary());
    assertFalse(ipIntf.isManaged());
    // Verify that test IP address exists on Node2 as primary
    ipIntf = m_ipInterfaceDao.findByNodeIdAndIpAddress(m_databasePopulator.getNode2().getId(), m_testAddress.getHostAddress());
    assertTrue(ipIntf.isPrimary());
    assertTrue(ipIntf.isManaged());
    // Get Interfaces For Nodes Map
    Map<InetAddress, Integer> map = m_ipInterfaceDao.getInterfacesForNodes();
    assertNotNull(map);
    // Verify that the test address is associated with Node2 because primary addresses has precedence over non-primary addresses.
    assertEquals(Integer.valueOf(m_databasePopulator.getNode2().getId()), map.get(m_testAddress));
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) InetAddress(java.net.InetAddress) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with OnmsIpInterface

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

the class OutageDaoIT method insertEntitiesAndOutage.

private OnmsOutage insertEntitiesAndOutage(final String ipAddr, final String serviceName, OnmsNode node) {
    OnmsIpInterface ipInterface = getIpInterface(ipAddr, node);
    OnmsServiceType serviceType = getServiceType(serviceName);
    OnmsMonitoredService monitoredService = getMonitoredService(ipInterface, serviceType);
    OnmsEvent event = getEvent();
    OnmsOutage outage = getOutage(monitoredService, event);
    return outage;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 20 with OnmsIpInterface

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

the class RrdPersistOperationBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_rrdStrategy = new JRobinRrdStrategy();
    m_fileAnticipator = new FileAnticipator();
    m_intf = new OnmsIpInterface();
    m_node = new OnmsNode();
    m_node.setId(1);
    m_intf.setNode(m_node);
    m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1"));
    m_intf.setId(27);
    m_ifDao = EasyMock.createMock(IpInterfaceDao.class);
    EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes();
    EasyMock.replay(m_ifDao);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) FileAnticipator(org.opennms.test.FileAnticipator) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Before(org.junit.Before)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11