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());
}
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());
}
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);
}
Aggregations