Search in sources :

Example 1 with OnmsPathOutage

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

the class PollContextIT method testPathOutages.

@Test
public void testPathOutages() throws Exception {
    Assert.assertNotNull(m_nodeDao);
    Assert.assertNotNull(m_pathOutageDao);
    Assert.assertNotNull(m_pathOutageManager);
    OnmsNode node = m_nodeDao.get(1);
    Assert.assertNotNull(node);
    OnmsPathOutage pathOutage = new OnmsPathOutage(node, InetAddressUtils.addr("169.254.0.1"), "ICMP");
    m_pathOutageDao.save(pathOutage);
    m_pathOutageDao.flush();
    m_pollerConfig.setPathOutageEnabled(true);
    CriticalPath path = m_pathOutageManager.getCriticalPath(1);
    Assert.assertEquals(InetAddrUtils.addr("169.254.0.1"), path.getIpAddress());
    Event nodeEvent = m_pollContext.createEvent(EventConstants.NODE_DOWN_EVENT_UEI, 1, null, null, new Date(), String.valueOf(PollStatus.SERVICE_UNAVAILABLE));
    Assert.assertNotNull(nodeEvent);
    Assert.assertEquals("169.254.0.1", nodeEvent.getParm(EventConstants.PARM_CRITICAL_PATH_IP).getValue().getContent());
    Assert.assertEquals(EventConstants.PARM_VALUE_PATHOUTAGE, nodeEvent.getParm(EventConstants.PARM_LOSTSERVICE_REASON).getValue().getContent());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) Event(org.opennms.netmgt.xml.event.Event) CriticalPath(org.opennms.netmgt.dao.api.CriticalPath) OnmsPathOutage(org.opennms.netmgt.model.OnmsPathOutage) Date(java.util.Date) Test(org.junit.Test)

Example 2 with OnmsPathOutage

use of org.opennms.netmgt.model.OnmsPathOutage 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)

Example 3 with OnmsPathOutage

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

the class PathOutageManagerDaoImpl method getCriticalPath.

@Override
public CriticalPath getCriticalPath(int nodeId) {
    //"SELECT criticalpathip, criticalpathservicename FROM pathoutage WHERE nodeid=?";
    String location = null;
    InetAddress pathIp = serverConfig.getDefaultCriticalPathIp();
    String serviceName = "ICMP";
    final OnmsNode node = nodeDao.get(nodeId);
    if (node != null) {
        location = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node);
    }
    final OnmsPathOutage out = pathOutageDao.get(nodeId);
    if (out != null) {
        if (out.getCriticalPathIp() != null) {
            pathIp = out.getCriticalPathIp();
        }
        if (out.getCriticalPathServiceName() != null && !"".equals(out.getCriticalPathServiceName().trim())) {
            serviceName = out.getCriticalPathServiceName();
        }
    }
    return new CriticalPath(location, pathIp, serviceName);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) CriticalPath(org.opennms.netmgt.dao.api.CriticalPath) OnmsPathOutage(org.opennms.netmgt.model.OnmsPathOutage)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsPathOutage (org.opennms.netmgt.model.OnmsPathOutage)3 Test (org.junit.Test)2 CriticalPath (org.opennms.netmgt.dao.api.CriticalPath)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1 PollEvent (org.opennms.netmgt.poller.pollables.PollEvent)1 Event (org.opennms.netmgt.xml.event.Event)1 Transactional (org.springframework.transaction.annotation.Transactional)1