#range #nagios #parser #operate #error #literals #icinga

nagios-range

Provides types to parse and operate on Nagios ranges

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

Download history 27/week @ 2024-07-20 50/week @ 2024-07-27 17/week @ 2024-08-03 45/week @ 2024-08-10 52/week @ 2024-08-17 24/week @ 2024-08-24 99/week @ 2024-08-31 14/week @ 2024-09-07 20/week @ 2024-09-14 39/week @ 2024-09-21 25/week @ 2024-09-28 11/week @ 2024-10-05 42/week @ 2024-10-12 41/week @ 2024-10-19 43/week @ 2024-10-26 15/week @ 2024-11-02

142 downloads per month
Used in 3 crates

MIT license

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(())
}

No runtime deps