7 releases
0.2.5 | Feb 26, 2022 |
---|---|
0.2.4 | Feb 1, 2022 |
0.2.3 | Jan 25, 2022 |
0.1.0 | Jan 7, 2022 |
#2422 in Rust patterns
142 downloads per month
Used in 3 crates
18KB
289 lines
nagios-range
This is a very small Rust library that simply parses a Nagios range as defined in the Nagios development guidelines.
Example
use nagios_range::{NagiosRange, Error};
fn main() -> Result<(), Error>{
let range = NagiosRange::from("@~:10");
assert!(range.is_ok());
assert!(range?.checks_inside());
assert!(range?.start_is_infinite());
assert!(range?.check(5.0));
}
lib.rs
:
This crate provides simple types to parse and operate on a Nagios range as described in the Nagios Development Guidelines.
The main type [NagiosRange] behaves similar to a std::ops::RangeInclusive but also provides methods that implement the extended behaviour of a Nagios range, i.e. checking if a value is inside or outside the range which is basically the same as the [std::ops::RangeInclusive::contains()] method but extends it with the inverse behaviour.
Examples
Create a NagiosRange
from a literal string.
use nagios_range::{NagiosRange, Error};
fn main() -> Result<(), Error> {
let range = NagiosRange::from("@0:10");
assert!(range.is_ok());
Ok(())
}
Look if a NagiosRange
checks for values inside
or outside of its range.
use nagios_range::{NagiosRange, Error};
fn main() -> Result<(), Error> {
// This is an "inside" range.
let range = NagiosRange::from("@0:10")?;
assert!(range.checks_inside());
assert!(!range.checks_outside());
Ok(())
}
Look if the start point of a NagiosRange
(the lower bound)
is negatively infinite.
use nagios_range::{NagiosRange, Error};
fn main() -> Result<(), Error> {
let range = NagiosRange::from("@~:10")?;
assert!(range.start_is_infinite());
Ok(())
}
Probably the most important function when working with Nagios check plugins: Check if a value is "contained" by the range in respect to its [CheckType].
use nagios_range::{NagiosRange, Error};
fn main() -> Result<(), Error> {
let range = NagiosRange::from("@~:10")?;
assert!(range.check(5.0));
let range = NagiosRange::from("20")?;
assert!(range.check(30.0));
Ok(())
}