Function evaluate_thresholds

Source
pub fn evaluate_thresholds(
    aggr_method: AggregationMethod,
    value: f64,
    thresholds: &Thresholds,
) -> Status<'_>
Expand description

Evaluate the jitter against the thresholds and return the appropriate status.

This function will evaluate the jitter against the provided thresholds and return the appropriate status. It will match against the critical threshold first and then the warning threshold, returning the first match or Status::Ok if no thresholds are matched.

§Arguments

  • jitter - The jitter to evaluate as a 64 bit floating point number.
  • thresholds - A reference to the Thresholds to evaluate against.

§Returns

The Status of the jitter against the thresholds.

§Example

use check_jitter::{evaluate_thresholds, AggregationMethod, Thresholds, Status};
use nagios_range::NagiosRange as ThresholdRange;
use std::time::Duration;

let jitter = 0.1;
let thresholds = Thresholds {
    warning: Some(ThresholdRange::from("0:0.5").unwrap()),
    critical: Some(ThresholdRange::from("0:1").unwrap()),
};

let status = evaluate_thresholds(AggregationMethod::Average, jitter, &thresholds);

match status {
    Status::Ok(_, _, _) => println!("Jitter is OK"),
    Status::Warning(_, _, _) => println!("Jitter is warning"),
    Status::Critical(_, _, _) => println!("Jitter is critical"),
    Status::Unknown(_) => println!("Unknown status"),
}