use of org.opennms.netmgt.dao.api.CriticalPath in project opennms by OpenNMS.
the class DefaultPollContext method testCriticalPath.
private boolean testCriticalPath(CriticalPath criticalPath) {
if (!"ICMP".equalsIgnoreCase(criticalPath.getServiceName())) {
LOG.warn("Critical paths using services other than ICMP are not currently supported." + " ICMP will be used for testing {}.", criticalPath);
}
final InetAddress ipAddress = criticalPath.getIpAddress();
final int retries = OpennmsServerConfigFactory.getInstance().getDefaultCriticalPathRetries();
final int timeout = OpennmsServerConfigFactory.getInstance().getDefaultCriticalPathTimeout();
boolean available = false;
try {
final PingSummary pingSummary = m_locationAwarePingClient.ping(ipAddress).withLocation(criticalPath.getLocationName()).withTimeout(timeout, TimeUnit.MILLISECONDS).withRetries(retries).execute().get();
// We consider the path to be available if any of the requests were successful
available = pingSummary.getSequences().stream().filter(s -> s.isSuccess()).count() > 0;
} catch (InterruptedException e) {
LOG.warn("Interrupted while testing {}. Marking the path as available.", criticalPath);
available = true;
} catch (Throwable e) {
final Throwable cause = e.getCause();
if (cause != null && cause instanceof RequestTimedOutException) {
LOG.warn("No response was received when remotely testing {}." + " Marking the path as available.", criticalPath);
available = true;
} else if (cause != null && cause instanceof RequestRejectedException) {
LOG.warn("Request was rejected when attemtping to test the remote path {}." + " Marking the path as available.", criticalPath);
available = true;
}
LOG.warn("An unknown error occured while testing the critical path: {}." + " Marking the path as unavailable.", criticalPath, e);
available = false;
}
LOG.debug("testCriticalPath: checking {}@{}, available ? {}", criticalPath.getServiceName(), ipAddress, available);
return available;
}
use of org.opennms.netmgt.dao.api.CriticalPath 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.dao.api.CriticalPath in project opennms by OpenNMS.
the class DefaultPollContext method createEvent.
/* (non-Javadoc)
* @see org.opennms.netmgt.poller.pollables.PollContext#createEvent(java.lang.String, int, java.net.InetAddress, java.lang.String, java.util.Date)
*/
/** {@inheritDoc} */
@Override
public Event createEvent(String uei, int nodeId, InetAddress address, String svcName, Date date, String reason) {
LOG.debug("createEvent: uei = {} nodeid = {}", uei, nodeId);
EventBuilder bldr = new EventBuilder(uei, this.getName(), date);
bldr.setNodeid(nodeId);
if (address != null) {
bldr.setInterface(address);
}
if (svcName != null) {
bldr.setService(svcName);
}
bldr.setHost(this.getLocalHostName());
if (uei.equals(EventConstants.NODE_DOWN_EVENT_UEI) && this.getPollerConfig().isPathOutageEnabled()) {
final CriticalPath criticalPath = PathOutageManagerDaoImpl.getInstance().getCriticalPath(nodeId);
if (criticalPath != null && criticalPath.getIpAddress() != null) {
if (!testCriticalPath(criticalPath)) {
LOG.debug("Critical path test failed for node {}", nodeId);
bldr.addParam(EventConstants.PARM_LOSTSERVICE_REASON, EventConstants.PARM_VALUE_PATHOUTAGE);
bldr.addParam(EventConstants.PARM_CRITICAL_PATH_IP, InetAddrUtils.str(criticalPath.getIpAddress()));
bldr.addParam(EventConstants.PARM_CRITICAL_PATH_SVC, criticalPath.getServiceName());
} else {
LOG.debug("Critical path test passed for node {}", nodeId);
}
} else {
LOG.debug("No Critical path to test for node {}", nodeId);
}
} else if (uei.equals(EventConstants.NODE_LOST_SERVICE_EVENT_UEI)) {
bldr.addParam(EventConstants.PARM_LOSTSERVICE_REASON, (reason == null ? "Unknown" : reason));
}
// node's nodeLabel value and add it as a parm
if (uei.equals(EventConstants.NODE_UP_EVENT_UEI) || uei.equals(EventConstants.NODE_DOWN_EVENT_UEI)) {
String nodeLabel = this.getNodeLabel(nodeId);
bldr.addParam(EventConstants.PARM_NODE_LABEL, nodeLabel);
}
return bldr.getEvent();
}
use of org.opennms.netmgt.dao.api.CriticalPath in project opennms by OpenNMS.
the class PathOutageManagerDaoIT method test.
@Test
public void test() throws SQLException, UnknownHostException {
final Connection conn = m_db.getConnection();
String[] ar = getPathOutageManager().getLabelAndStatus("1", conn);
assertEquals("Router", ar[0]);
assertEquals("Normal", ar[1]);
assertEquals("All Services Up", ar[2]);
String[] cr = getPathOutageManager().getLabelAndStatus("3", conn);
assertEquals("Firewall", cr[0]);
assertEquals("Normal", cr[1]);
assertEquals("All Services Up", cr[2]);
Set<Integer> lno = getPathOutageManager().getNodesInPath("192.168.1.1", "ICMP");
assertEquals(new Integer(1), lno.iterator().next());
Set<Integer> vno = getPathOutageManager().getNodesInPath("192.168.1.4", "SMTP");
assertEquals(new Integer(3), vno.iterator().next());
// This list should order by node label so Firewall should precede Router
List<String[]> all = getPathOutageManager().getAllCriticalPaths();
assertEquals(2, all.size());
assertEquals("Firewall", all.get(0)[0]);
assertEquals("192.168.1.4", all.get(0)[1]);
assertEquals("SMTP", all.get(0)[2]);
assertEquals("Router", all.get(1)[0]);
assertEquals("192.168.1.1", all.get(1)[1]);
assertEquals("ICMP", all.get(1)[2]);
String[] dat = getPathOutageManager().getCriticalPathData("192.168.1.1", "ICMP");
assertEquals("Router", dat[0]);
assertEquals("1", dat[1]);
assertEquals("1", dat[2]);
assertEquals("Normal", dat[3]);
String mm = getPathOutageManager().getPrettyCriticalPath(1);
assertEquals("192.168.1.1 ICMP", mm);
String nn = getPathOutageManager().getPrettyCriticalPath(3);
assertEquals("192.168.1.4 SMTP", nn);
CriticalPath pa = getPathOutageManager().getCriticalPath(1);
assertEquals(InetAddress.getByName("192.168.1.1"), pa.getIpAddress());
assertEquals("ICMP", pa.getServiceName());
CriticalPath nc = getPathOutageManager().getCriticalPath(3);
assertEquals(InetAddress.getByName("192.168.1.4"), nc.getIpAddress());
assertEquals("SMTP", nc.getServiceName());
Set<Integer> test = getPathOutageManager().getAllNodesDependentOnAnyServiceOnInterface("192.168.1.1");
assertEquals(1, test.size());
Set<Integer> less = getPathOutageManager().getAllNodesDependentOnAnyServiceOnNode(3);
assertEquals(1, less.size());
conn.close();
}
use of org.opennms.netmgt.dao.api.CriticalPath 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