pub struct NagiosRange { /* private fields */ }
Expand description
A parsed Nagios range built from a literal string.
A Nagios range works similar to std::ops::RangeInclusive
in that it is bounded by the lower and upper bounds inclusively
(start..=end
).
However it differs slightly in how it is used. It contains some
logic to determine if an alert should be raised when it is
compared to some value (either when inside or outside of the range).
Implementations§
Source§impl NagiosRange
impl NagiosRange
Sourcepub fn from(input: &str) -> Result<Self, Error>
pub fn from(input: &str) -> Result<Self, Error>
Creates a NagiosRange from a literal string.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@-10:10");
assert!(range.is_ok());
Ok(())
}
Sourcepub fn new(check_type: CheckType, start: f64, end: f64) -> Result<Self, Error>
pub fn new(check_type: CheckType, start: f64, end: f64) -> Result<Self, Error>
Creates a NagiosRange from a CheckType, lower and (inclusive) upper bounds.
use nagios_range::{NagiosRange, CheckType};
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::new(CheckType::Inside, f64::NEG_INFINITY, 20.0);
assert!(range.is_ok());
assert_eq!(range?, NagiosRange::from("@~:20")?);
Ok(())
}
Sourcepub fn start(&self) -> &f64
pub fn start(&self) -> &f64
Returns the lower bound of the range.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@-10:10")?;
assert_eq!(range.start(), &-10.0);
Ok(())
}
Sourcepub fn end(&self) -> &f64
pub fn end(&self) -> &f64
Returns the upper bound of the range.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@-10:10")?;
assert_eq!(range.end(), &10.0);
Ok(())
}
Sourcepub fn start_is_infinite(&self) -> bool
pub fn start_is_infinite(&self) -> bool
Returns true
if the lower bound is negative infinity.
This is just a convenience method that calls f64::is_infinite()
on start
.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@~:10")?;
assert!(range.start_is_infinite());
assert_eq!(range.start_is_infinite(), range.start().is_infinite());
Ok(())
}
Sourcepub fn end_is_infinite(&self) -> bool
pub fn end_is_infinite(&self) -> bool
Returns true
if the upper bound is positive infinity.
This is just a convenience method that calls f64::is_infinite()
on end
.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@10:")?;
assert!(range.end_is_infinite());
assert_eq!(range.end_is_infinite(), range.end().is_infinite());
Ok(())
}
Sourcepub fn contains(&self, item: f64) -> bool
pub fn contains(&self, item: f64) -> bool
Returns true
if item
is contained in the range irregardless
of the type of the NagiosRange. So this behaves just like
std::ops::RangeInclusive::contains().
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@~:10")?;
assert!(range.contains(-50.0));
assert!(range.contains(10.0));
assert!(!range.contains(20.0));
Ok(())
}
Sourcepub fn check(&self, item: f64) -> bool
pub fn check(&self, item: f64) -> bool
Returns true
if a value is either inside or outside
of the range depending on the type of Nagios range.
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
// When it is an "inside" range...
let range = NagiosRange::from("@10:20")?;
assert!(range.check(15.0));
// ...inverted behaviour when it is an "outside" range...
let range = NagiosRange::from("10:20")?;
assert!(range.check(30.0));
Ok(())
}
Sourcepub fn checks_inside(&self) -> bool
pub fn checks_inside(&self) -> bool
Returns true
if NagiosRange::check() checks
if a value lies inside the range (start <= item <= end
).
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("@~:10")?;
assert!(range.checks_inside());
Ok(())
}
Sourcepub fn checks_outside(&self) -> bool
pub fn checks_outside(&self) -> bool
Returns true
if NagiosRange::check() checks
if a value lies outside the range (start > item > end
).
use nagios_range::NagiosRange;
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("10:50")?;
assert!(range.checks_outside());
Ok(())
}
Sourcepub fn into_inner(self) -> (CheckType, f64, f64)
pub fn into_inner(self) -> (CheckType, f64, f64)
Destructures the NagiosRange into a CheckType and the lower and (inclusive) upper bounds.
use nagios_range::{NagiosRange, CheckType};
fn main() -> Result<(), nagios_range::Error> {
let range = NagiosRange::from("10:50")?;
let (check_type, start, end) = range.into_inner();
assert_eq!(check_type, CheckType::Outside);
assert_eq!(start, 10.0);
let new_range = NagiosRange::new(check_type, start, end);
assert!(new_range.is_ok());
Ok(())
}
Trait Implementations§
Source§impl Clone for NagiosRange
impl Clone for NagiosRange
Source§fn clone(&self) -> NagiosRange
fn clone(&self) -> NagiosRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more