#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

#2477 in Rust patterns

Download history 53/week @ 2024-08-19 38/week @ 2024-08-26 88/week @ 2024-09-02 8/week @ 2024-09-09 23/week @ 2024-09-16 39/week @ 2024-09-23 23/week @ 2024-09-30 9/week @ 2024-10-07 45/week @ 2024-10-14 43/week @ 2024-10-21 42/week @ 2024-10-28 14/week @ 2024-11-04 26/week @ 2024-11-11 9/week @ 2024-11-18 7/week @ 2024-11-25 34/week @ 2024-12-02

77 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