Search in sources :

Example 1 with CriticalPath

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;
}
Also used : PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) RequestRejectedException(org.opennms.core.rpc.api.RequestRejectedException) InetAddrUtils(org.opennms.netmgt.snmp.InetAddrUtils) EventConstants(org.opennms.netmgt.events.api.EventConstants) PingSummary(org.opennms.netmgt.icmp.proxy.PingSummary) InetAddress(java.net.InetAddress) EventListener(org.opennms.netmgt.events.api.EventListener) SQLException(java.sql.SQLException) Event(org.opennms.netmgt.xml.event.Event) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) OpennmsServerConfigFactory(org.opennms.netmgt.config.OpennmsServerConfigFactory) EventIpcManager(org.opennms.netmgt.events.api.EventIpcManager) PollableService(org.opennms.netmgt.poller.pollables.PollableService) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) PollerConfig(org.opennms.netmgt.config.PollerConfig) PollContext(org.opennms.netmgt.poller.pollables.PollContext) TimeUnit(java.util.concurrent.TimeUnit) CriticalPath(org.opennms.netmgt.dao.api.CriticalPath) LocationAwarePingClient(org.opennms.netmgt.icmp.proxy.LocationAwarePingClient) PendingPollEvent(org.opennms.netmgt.poller.pollables.PendingPollEvent) Queue(java.util.Queue) PathOutageManagerDaoImpl(org.opennms.netmgt.dao.hibernate.PathOutageManagerDaoImpl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) PingSummary(org.opennms.netmgt.icmp.proxy.PingSummary) RequestRejectedException(org.opennms.core.rpc.api.RequestRejectedException) InetAddress(java.net.InetAddress)

Example 2 with CriticalPath

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());
}
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 3 with CriticalPath

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();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) CriticalPath(org.opennms.netmgt.dao.api.CriticalPath)

Example 4 with CriticalPath

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();
}
Also used : Connection(java.sql.Connection) CriticalPath(org.opennms.netmgt.dao.api.CriticalPath) Test(org.junit.Test)

Example 5 with CriticalPath

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

CriticalPath (org.opennms.netmgt.dao.api.CriticalPath)5 InetAddress (java.net.InetAddress)2 Date (java.util.Date)2 Test (org.junit.Test)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 OnmsPathOutage (org.opennms.netmgt.model.OnmsPathOutage)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 PollEvent (org.opennms.netmgt.poller.pollables.PollEvent)2 Event (org.opennms.netmgt.xml.event.Event)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 Queue (java.util.Queue)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 RequestRejectedException (org.opennms.core.rpc.api.RequestRejectedException)1 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)1 OpennmsServerConfigFactory (org.opennms.netmgt.config.OpennmsServerConfigFactory)1 PollerConfig (org.opennms.netmgt.config.PollerConfig)1