/**
   * {@inheritDoc}
   *
   * <p>Perform threshold checking.
   */
  public int check(ThresholdNetworkInterface iface, EventProxy eproxy, Map<?, ?> parameters) {
    LatencyInterface latIface = new LatencyInterface(iface, m_svcName);
    LatencyParameters latParms = new LatencyParameters(parameters, m_svcName);

    try {

      // Get configuration parameters
      //
      // NodeId attribute
      if (log().isDebugEnabled())
        log()
            .debug(
                "check: service= "
                    + m_svcName
                    + " interface= "
                    + latIface.getHostAddress()
                    + " nodeId= "
                    + latIface.getNodeId()
                    + " thresholding-group="
                    + latParms.getGroupName()
                    + " interval="
                    + latParms.getInterval()
                    + "ms");

      // RRD Repository attribute
      //
      // Create empty Events object to hold any threshold
      // events generated during the thresholding check...
      Events events = checkRrdDir(latIface, latParms);

      // Send created events
      //
      sendEvents(eproxy, events);

      // return the status of the threshold check
      //
      return THRESHOLDING_SUCCEEDED;

    } catch (ThresholdingException e) {
      log().error(e.getMessage());
      return e.getFailureCode();
    } catch (EventProxyException e) {
      log().error("check: Failed sending threshold events via event proxy...", e);
      return THRESHOLDING_FAILED;
    }
  }
  /**
   * fetchLastValue
   *
   * @param latIface a {@link org.opennms.netmgt.threshd.LatencyInterface} object.
   * @param latParms a {@link org.opennms.netmgt.threshd.LatencyParameters} object.
   * @return a {@link java.lang.Double} object.
   * @throws org.opennms.netmgt.threshd.ThresholdingException if any.
   */
  public Double fetchLastValue(LatencyInterface latIface, LatencyParameters latParms)
      throws ThresholdingException {
    // Assume that this only happens on a simple "Threshold", not an "Expression"
    // If it is an Expression, then we don't yet know what to do - this will likely just fail with
    // some sort of exception.
    // perhaps we should figure out how to expand it (or at least use code elsewhere to do so
    // sensibly)
    String datasource = getDataSourceExpression();

    // Use RRD strategy to "fetch" value of the datasource from the RRD file
    Double dsValue = null;
    try {
      if (getDatasourceType().equals("if")) {
        if (log().isDebugEnabled()) {
          log().debug("Fetching last value from dataSource '" + datasource + "'");
        }

        File rrdFile = new File(latIface.getLatencyDir(), datasource + RrdUtils.getExtension());
        if (!rrdFile.exists()) {
          log().info("rrd file " + rrdFile + " does not exist");
          return null;
        }

        if (!rrdFile.canRead()) {
          log().error("Unable to read existing rrd file " + rrdFile);
          return null;
        }

        if (latParms.getRange() == 0) {
          dsValue =
              RrdUtils.fetchLastValue(
                  rrdFile.getAbsolutePath(), datasource, latParms.getInterval());
        } else {
          dsValue =
              RrdUtils.fetchLastValueInRange(
                  rrdFile.getAbsolutePath(),
                  datasource,
                  latParms.getInterval(),
                  latParms.getRange());
        }
      } else {
        throw new ThresholdingException(
            "expr types not yet implemented", LatencyThresholder.THRESHOLDING_FAILED);
      }

      if (log().isDebugEnabled()) {
        log().debug("Last value from dataSource '" + datasource + "' was " + dsValue);
      }
    } catch (NumberFormatException nfe) {
      log()
          .warn(
              "Unable to convert retrieved value for datasource '"
                  + datasource
                  + "' to a double, skipping evaluation.");
    } catch (RrdException e) {
      log()
          .error(
              "An error occurred retriving the last value for datasource '"
                  + datasource
                  + "': "
                  + e,
              e);
    }

    return dsValue;
  }