[][src]Struct nagiosplugin::Resource

pub struct Resource { /* fields omitted */ }

A Resource basically represents a single service if you view it from the perspective of nagios. If you init it without a state it will determine one from the given metrics.

You can also create a Resource filled with metrics via the resource! macro, which is much like the vec! macro.

let m1 = SimpleMetric::new("test", Some(State::Ok), 12, None, None, None, None);
let m2 = SimpleMetric::new("other", None, true, None, None, None, None);
let resource = resource![m1, m2];
assert_eq!(&resource.to_nagios_string(), "OK | test=12 other=true");

// Prints "OK | test=12 other=true" and exits with an exit code of 0 in this case
resource.print_and_exit();

Methods

impl Resource[src]

pub fn new(state: Option<State>, description: Option<&str>) -> Resource[src]

If state is set to Some(State) then it will always use this instead of determining it from the given metrics.

If you want to create a Resource from some metrics with automatic determination of the state you can use the resource! macro.

pub fn push<M>(&mut self, metric: M) where
    M: 'static + ResourceMetric
[src]

Pushes a single ResourceMetric into the resource.

pub fn metrics(&self) -> &[Box<dyn ResourceMetric>][src]

Returns a slice of the pushed metrics.

pub fn set_state(&mut self, state: State)[src]

Manually set the state for this resource. This disabled the automatic state determination based on the included metrics of this resource.

pub fn set_name(&mut self, name: &str)[src]

Set the name of this resource. Will be included in the final string output.

pub fn to_nagios_string(&self) -> String[src]

Returns a string which nagios understands to determine the service state.

This function will automatically determine which service state is appropriate based on the included metrics. If state has been set manually it will always use the manually set state.

pub fn get_state(&self) -> State[src]

Will determine a State by the given metrics.

In case a state is manually set for this resource, it will return the manually set state instead.

pub fn get_description(&self) -> Option<&String>[src]

Get the description of this resource.

pub fn set_description(&mut self, description: &str)[src]

Set the description of this resource.

pub fn exit_code(&self) -> i32[src]

Will return the exit code of the determined state via Self::state.

pub fn print_and_exit(&self)[src]

Will print Self::to_nagios_string and exit with the exit code from Self::exit_code

Trait Implementations

impl Default for Resource[src]

Auto Trait Implementations

impl !Send for Resource

impl Unpin for Resource

impl !Sync for Resource

impl !UnwindSafe for Resource

impl !RefUnwindSafe for Resource

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]