Пример #1
0
  @Override
  public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    NetworkInterface<InetAddress> iface = svc.getNetInterface();

    // Get interface address from NetworkInterface
    //
    if (iface.getType() != NetworkInterface.TYPE_INET)
      throw new NetworkInterfaceNotSupportedException(
          "Unsupported interface type, only TYPE_INET currently supported");

    /*
     * TODO: Use it or loose it.
     * Commented out because it is not currently used in this monitor
     */
    // get parameters
    // int retry = ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY);
    // int timeout = ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT);

    // Extract the address
    //
    InetAddress ipv4Addr = (InetAddress) iface.getAddress();

    // Default is a failed status
    //
    PollStatus serviceStatus = PollStatus.unavailable();

    // Attempt to retrieve NetBIOS name of this interface in order
    // to determine if SMB is supported.
    //
    NbtAddress nbtAddr = null;

    /*
     * This try block was updated to reflect the behavior of the plugin.
     */
    final String hostAddress = InetAddressUtils.str(ipv4Addr);

    final boolean doNodeStatus =
        ParameterMap.getKeyedBoolean(parameters, DO_NODE_STATUS, DO_NODE_STATUS_DEFAULT);

    try {
      nbtAddr = NbtAddress.getByName(hostAddress);

      if (doNodeStatus) {
        nbtAddr.getNodeType();
      }

      if (!nbtAddr.getHostName().equals(hostAddress)) serviceStatus = PollStatus.available();

    } catch (UnknownHostException uhE) {
      serviceStatus =
          logDown(
              Level.DEBUG,
              "Unknown host exception generated for "
                  + hostAddress
                  + ", reason: "
                  + uhE.getLocalizedMessage());
    } catch (RuntimeException rE) {
      serviceStatus = logDown(Level.ERROR, "Unexpected runtime exception", rE);
    } catch (Throwable e) {
      serviceStatus = logDown(Level.DEBUG, "Unexpected exception", e);
    }

    //
    // return the status of the service
    //
    return serviceStatus;
  }