Search in sources :

Example 86 with OnmsMonitoredService

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

the class DefaultDistributedStatusServiceTest method expectEverything.

public void expectEverything() {
    expect(m_applicationDao.findByName("Application 1")).andReturn(m_application1);
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(Collections.singleton(m_locationMonitor1_1));
    OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpService)).andReturn(new OnmsLocationSpecificStatus(m_locationMonitor1_1, httpService, PollStatus.available()));
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpsService)).andReturn(null);
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 87 with OnmsMonitoredService

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

the class IpInterfaceDaoIT method testGetByService.

@Test
@Transactional
public void testGetByService() {
    List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findByServiceType("SNMP");
    Collections.sort(ifaces, new Comparator<OnmsIpInterface>() {

        @Override
        public int compare(OnmsIpInterface o1, OnmsIpInterface o2) {
            return Integer.valueOf(o1.getNode().getId()).compareTo(o2.getNode().getId());
        }
    });
    assertEquals(6, ifaces.size());
    OnmsIpInterface iface = ifaces.iterator().next();
    assertEquals("node1", iface.getNode().getLabel());
    assertEquals(2, iface.getMonitoredServices().size());
    assertEquals("192.168.1.1", InetAddressUtils.str(iface.getIpAddress()));
    OnmsMonitoredService service = iface.getMonitoredServiceByServiceType("SNMP");
    assertNotNull(service);
    assertEquals(addr("192.168.1.1"), service.getIpAddress());
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 88 with OnmsMonitoredService

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

the class IpInterfaceDaoIT method testGetByIpAddress.

@Test
@Transactional
public void testGetByIpAddress() {
    Collection<OnmsIpInterface> ifaces = m_ipInterfaceDao.findByIpAddress("192.168.1.1");
    assertEquals(1, ifaces.size());
    OnmsIpInterface iface = ifaces.iterator().next();
    assertEquals("node1", iface.getNode().getLabel());
    int count = 0;
    for (Iterator<OnmsMonitoredService> it = iface.getMonitoredServices().iterator(); it.hasNext(); ) {
        it.next();
        count++;
    }
    assertEquals(2, count);
    assertEquals(2, iface.getMonitoredServices().size());
    assertEquals("192.168.1.1", InetAddressUtils.str(iface.getIpAddress()));
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with OnmsMonitoredService

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

the class OutageDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
    m_nodeDao.save(node);
    OnmsIpInterface ipInterface = new OnmsIpInterface(addr("172.16.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("ICMP");
    assertNotNull(serviceType);
    OnmsMonitoredService monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
    OnmsEvent event = new OnmsEvent();
    OnmsOutage outage = new OnmsOutage(new Date(), monitoredService);
    outage.setServiceLostEvent(event);
    m_outageDao.save(outage);
    // it works we're so smart! hehe
    outage = m_outageDao.load(outage.getId());
    assertEquals("ICMP", outage.getMonitoredService().getServiceType().getName());
// outage.setEventBySvcRegainedEvent();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with OnmsMonitoredService

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

the class PathOutageDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    final OnmsServiceType serviceType = m_serviceTypeDao.findByName("ICMP");
    assertNotNull(serviceType);
    // This will be our router with one IP address
    OnmsNode router = new OnmsNode(m_locationDao.getDefaultLocation(), "router");
    m_nodeDao.save(router);
    OnmsIpInterface routerIpInterface = new OnmsIpInterface(addr("172.16.1.1"), router);
    routerIpInterface.setIsManaged("M");
    OnmsMonitoredService routerService = new OnmsMonitoredService(routerIpInterface, serviceType);
    routerService.setStatus("A");
    // Add a node that will be routed through the router
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
    m_nodeDao.save(node);
    OnmsIpInterface nodeIpInterface = new OnmsIpInterface(addr("172.16.1.2"), node);
    nodeIpInterface.setIsManaged("M");
    OnmsMonitoredService nodeMonitoredService = new OnmsMonitoredService(nodeIpInterface, serviceType);
    nodeMonitoredService.setStatus("A");
    // Make another node with an interface that is initially marked as deleted
    OnmsNode newNode = new OnmsNode(m_locationDao.getDefaultLocation(), "newnode");
    m_nodeDao.save(newNode);
    OnmsIpInterface newIpInterface = new OnmsIpInterface(addr("172.16.1.3"), newNode);
    newIpInterface.setIsManaged("D");
    OnmsMonitoredService newMonitoredService = new OnmsMonitoredService(newIpInterface, serviceType);
    newMonitoredService.setStatus("A");
    OnmsPathOutage outage = new OnmsPathOutage(node, routerIpInterface.getIpAddress(), routerService.getServiceName());
    m_pathOutageDao.save(outage);
    // it works we're so smart! hehe
    OnmsPathOutage temp = m_pathOutageDao.get(outage.getNode().getId());
    assertEquals(1, m_pathOutageDao.countAll());
    // Make sure that the path outage points from the node to the router interface/service
    assertEquals(node.getLabel(), temp.getNode().getLabel());
    assertEquals(routerIpInterface.getIpAddress(), temp.getCriticalPathIp());
    assertEquals(routerService.getServiceName(), temp.getCriticalPathServiceName());
    List<Integer> nodes = m_pathOutageDao.getNodesForPathOutage(temp);
    assertEquals(1, nodes.size());
    assertEquals(node.getId(), nodes.get(0));
    nodes = m_pathOutageDao.getNodesForPathOutage(routerIpInterface.getIpAddress(), routerService.getServiceName());
    assertEquals(1, nodes.size());
    assertEquals(node.getId(), nodes.get(0));
    // Make sure that nothing is using either node as a path outage
    nodes = m_pathOutageDao.getNodesForPathOutage(nodeIpInterface.getIpAddress(), nodeMonitoredService.getServiceName());
    assertEquals(0, nodes.size());
    nodes = m_pathOutageDao.getNodesForPathOutage(newIpInterface.getIpAddress(), newMonitoredService.getServiceName());
    assertEquals(0, nodes.size());
    assertEquals(1, m_pathOutageDao.countAll());
    OnmsPathOutage newOutage = new OnmsPathOutage(newNode, routerIpInterface.getIpAddress(), routerService.getServiceName());
    m_pathOutageDao.save(newOutage);
    assertEquals(2, m_pathOutageDao.countAll());
    // Should return zero results because the interface is marked as 'D' for deleted
    nodes = m_pathOutageDao.getNodesForPathOutage(routerIpInterface.getIpAddress(), routerService.getServiceName());
    assertEquals(2, nodes.size());
    nodes = m_pathOutageDao.getAllNodesDependentOnAnyServiceOnInterface(routerIpInterface.getIpAddress());
    assertEquals(2, nodes.size());
    // After we mark it as managed, the node should appear in the path outage list
    newIpInterface.setIsManaged("M");
    nodes = m_pathOutageDao.getNodesForPathOutage(routerIpInterface.getIpAddress(), routerService.getServiceName());
    assertEquals(2, nodes.size());
    assertTrue(nodes.contains(node.getId()));
    assertTrue(nodes.contains(newNode.getId()));
    assertEquals(2, m_pathOutageDao.countAll());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsPathOutage(org.opennms.netmgt.model.OnmsPathOutage) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)119 Date (java.util.Date)37 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)27 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)25 Transactional (org.springframework.transaction.annotation.Transactional)22 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 HashSet (java.util.HashSet)9 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5