/** * 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; }