Search in sources :

Example 1 with NullPinger

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

the class Main method initializePinger.

public void initializePinger() {
    final AbstractPingerFactory pingerFactory = new BestMatchPingerFactory();
    if (m_disableIcmp) {
        LOG.info("Disabling ICMP by user request.");
        System.setProperty("org.opennms.netmgt.icmp.pingerClass", "org.opennms.netmgt.icmp.NullPinger");
        pingerFactory.setInstance(0, true, new NullPinger());
        return;
    }
    final String pingerClass = System.getProperty("org.opennms.netmgt.icmp.pingerClass");
    if (pingerClass == null) {
        LOG.info("System property org.opennms.netmgt.icmp.pingerClass is not set; using JnaPinger by default");
        System.setProperty("org.opennms.netmgt.icmp.pingerClass", "org.opennms.netmgt.icmp.jna.JnaPinger");
    }
    LOG.info("Pinger class: {}", System.getProperty("org.opennms.netmgt.icmp.pingerClass"));
    try {
        final Pinger pinger = pingerFactory.getInstance();
        pinger.ping(InetAddress.getLoopbackAddress());
    } catch (final Throwable t) {
        LOG.warn("Unable to get pinger instance.  Setting pingerClass to NullPinger.  For details, see: http://www.opennms.org/wiki/ICMP_could_not_be_initialized");
        System.setProperty("org.opennms.netmgt.icmp.pingerClass", "org.opennms.netmgt.icmp.NullPinger");
        pingerFactory.setInstance(0, true, new NullPinger());
        if (m_gui) {
            final String message = "ICMP (ping) could not be initialized: " + t.getMessage() + "\nDisabling ICMP and using the NullPinger instead." + "\nFor details, see: http://www.opennms.org/wiki/ICMP_could_not_be_initialized";
            JOptionPane.showMessageDialog(null, message, "ICMP Not Available", JOptionPane.WARNING_MESSAGE);
        }
    }
}
Also used : NullPinger(org.opennms.netmgt.icmp.NullPinger) Pinger(org.opennms.netmgt.icmp.Pinger) NullPinger(org.opennms.netmgt.icmp.NullPinger) AbstractPingerFactory(org.opennms.netmgt.icmp.AbstractPingerFactory) BestMatchPingerFactory(org.opennms.netmgt.icmp.best.BestMatchPingerFactory)

Aggregations

AbstractPingerFactory (org.opennms.netmgt.icmp.AbstractPingerFactory)1 NullPinger (org.opennms.netmgt.icmp.NullPinger)1 Pinger (org.opennms.netmgt.icmp.Pinger)1 BestMatchPingerFactory (org.opennms.netmgt.icmp.best.BestMatchPingerFactory)1