From 2c6651034f76e2bccb549a867485f8fabbf07cb1 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 8 Jun 2006 12:27:44 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1419 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin/Threshold.pm | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 lib/Nagios/Plugin/Threshold.pm (limited to 'lib/Nagios/Plugin/Threshold.pm') diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm new file mode 100644 index 0000000..9c5d042 --- /dev/null +++ b/lib/Nagios/Plugin/Threshold.pm @@ -0,0 +1,96 @@ +package Nagios::Plugin::Threshold; + +use 5.008004; + +use strict; +use warnings; + +use Nagios::Plugin::Range; +use Nagios::Plugin::Base; + +use Class::Struct; +struct "Nagios::Plugin::Threshold" => { + warning => 'Nagios::Plugin::Range', + critical => 'Nagios::Plugin::Range', + }; + +sub set_thresholds { + my ($class, %args) = @_; + my $t = $class->new; + if (defined $args{warning}) { + my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); + if (defined $r) { + $t->warning($r); + } else { + Nagios::Plugin::Base->die( { + return_code => $ERRORS{UNKNOWN}, + message => "Warning range incorrect: '$args{warning}'" + } ); + } + } + if (defined $args{critical}) { + my $r = Nagios::Plugin::Range->parse_range_string($args{critical}); + if (defined $r) { + $t->critical($r); + } else { + Nagios::Plugin::Base->die( { + return_code => $ERRORS{UNKNOWN}, + message => "Critical range incorrect: '$args{critical}'" + } ); + } + } + return $t; +} + +sub get_status { + my ($self, $value) = @_; + if ($self->critical) { + if ($self->critical->check_range($value) == 1) { + return $ERRORS{CRITICAL}; + } + } + if ($self->warning) { + if ($self->warning->check_range($value) == 1) { + return $ERRORS{WARNING}; + } + } +} + +1; +__END__ + +=head1 NAME + +Nagios::Plugin::Threshold - Threshold information in a perl object + +=head1 DESCRIPTION + +Handles common Nagios Plugin threshold data. See Nagios::Plugin or Nagios::Plugin::Performance for +creation of this object. + +=head1 OBJECT METHODS + +=over 4 + +=item warning, critical + +Returns the warning or critical range as a Nagios::Plugin::Range object. + +=item get_status($value) + +Given a value, will see if the value breeches the critical or the warning range. Returns the status code. + +=head1 AUTHOR + +Ton Voon, Eton.voon@altinity.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 by Altinity Limited + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.4 or, +at your option, any later version of Perl 5 you may have available. + + +=cut -- cgit v1.2.3-74-g34f1