Search in sources :

Example 1 with PingerFactoryImpl

use of org.opennms.netmgt.icmp.PingerFactoryImpl in project opennms by OpenNMS.

the class Manager method testPinger.

private void testPinger() {
    final PingerFactoryImpl pingerFactory = new PingerFactoryImpl();
    final Pinger pinger = pingerFactory.getInstance();
    boolean hasV4 = pinger.isV4Available();
    boolean hasV6 = pinger.isV6Available();
    LOG.info("Using ICMP implementation: {}", pinger.getClass().getName());
    LOG.info("IPv4 ICMP available? {}", hasV4);
    LOG.info("IPv6 ICMP available? {}", hasV6);
    if (!hasV4) {
        try {
            pinger.initialize4();
            hasV4 = true;
        } catch (final Exception e) {
            LOG.warn("Failed to initialize IPv4 stack.", e);
        }
    }
    if (!hasV6) {
        try {
            pinger.initialize6();
            hasV6 = true;
        } catch (final Exception e) {
            LOG.warn("Failed to initialize IPv6 stack.", e);
        }
    }
    if (!hasV4 && !hasV6) {
        throwPingError("Neither IPv4 nor IPv6 are avaialable.  Bailing.");
    }
    final String requireV4String = System.getProperty("org.opennms.netmgt.icmp.requireV4");
    final String requireV6String = System.getProperty("org.opennms.netmgt.icmp.requireV6");
    if ("true".equalsIgnoreCase(requireV4String) && !hasV4) {
        throwPingError("org.opennms.netmgt.icmp.requireV4 is true, but IPv4 ICMP could not be initialized.");
    }
    if ("true".equalsIgnoreCase(requireV6String) && !hasV6) {
        throwPingError("org.opennms.netmgt.icmp.requireV6 is true, but IPv6 ICMP could not be initialized.");
    }
    // at least one is initialized, and we haven't said otherwise, so barrel ahead
    // but first, reset the pinger factory so we can let auto-detection happen
    pingerFactory.reset();
}
Also used : Pinger(org.opennms.netmgt.icmp.Pinger) PingerFactoryImpl(org.opennms.netmgt.icmp.PingerFactoryImpl) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) UnknownHostException(java.net.UnknownHostException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 UnknownHostException (java.net.UnknownHostException)1 Pinger (org.opennms.netmgt.icmp.Pinger)1 PingerFactoryImpl (org.opennms.netmgt.icmp.PingerFactoryImpl)1