diff options
Diffstat (limited to 'lib/Nagios')
| -rw-r--r-- | lib/Nagios/Plugin.pm | 160 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Base.pm | 65 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 119 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Range.pm | 126 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 96 |
5 files changed, 566 insertions, 0 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm new file mode 100644 index 0000000..3c6e8d7 --- /dev/null +++ b/lib/Nagios/Plugin.pm | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | # This is only because Class::Struct doesn't allow subclasses | ||
| 2 | # Trick stolen from Class::DBI | ||
| 3 | package Nagios::__::Plugin; | ||
| 4 | |||
| 5 | use 5.008004; | ||
| 6 | use Class::Struct; | ||
| 7 | struct "Nagios::__::Plugin" => { | ||
| 8 | perfdata => '@', | ||
| 9 | }; | ||
| 10 | |||
| 11 | package Nagios::Plugin; | ||
| 12 | |||
| 13 | use Nagios::Plugin::Base; | ||
| 14 | use Nagios::Plugin::Performance; | ||
| 15 | use Nagios::Plugin::Threshold; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | |||
| 20 | use Carp; | ||
| 21 | |||
| 22 | use Exporter; | ||
| 23 | our @ISA = qw(Exporter Nagios::__::Plugin); | ||
| 24 | our @EXPORT_OK = qw(%ERRORS); | ||
| 25 | |||
| 26 | our $VERSION = '0.10'; | ||
| 27 | |||
| 28 | sub add_perfdata { | ||
| 29 | my ($self, %args) = @_; | ||
| 30 | my $perf = Nagios::Plugin::Performance->new(%args); | ||
| 31 | push @{$self->perfdata}, $perf; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub all_perfoutput { | ||
| 35 | my $self = shift; | ||
| 36 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } | ||
| 40 | |||
| 41 | my $shortname; | ||
| 42 | sub shortname { shift; @_ ? $shortname = shift : $shortname } | ||
| 43 | |||
| 44 | sub die { | ||
| 45 | my $self = shift; | ||
| 46 | my %args = @_; | ||
| 47 | Nagios::Plugin::Base->die(\%args, $self); | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | __END__ | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | Nagios::Plugin - Object oriented helper routines for your Nagios plugin | ||
| 56 | |||
| 57 | =head1 SYNOPSIS | ||
| 58 | |||
| 59 | use Nagios::Plugin qw(%ERRORS); | ||
| 60 | $p = Nagios::Plugin->new( shortname => "PAGESIZE" ); | ||
| 61 | |||
| 62 | $threshold = $p->set_thresholds( warning => "10:25", critical => "25:" ); | ||
| 63 | |||
| 64 | # ... collect current metric into $value | ||
| 65 | if ($trouble_getting_metric) { | ||
| 66 | $p->die( return_code => $ERRORS{UNKNOWN}, message => "Could not retrieve page"); | ||
| 67 | # Output: PAGESIZE UNKNOWN Could not retrieve page | ||
| 68 | # Return code: 3 | ||
| 69 | } | ||
| 70 | |||
| 71 | $p->add_perfdata( label => "size", | ||
| 72 | value => $value, | ||
| 73 | uom => "kB", | ||
| 74 | threshold => $threshold, | ||
| 75 | ); | ||
| 76 | $p->add_perfdata( label => "time", ... ); | ||
| 77 | |||
| 78 | $p->die( return_code => $threshold->get_status($value), message => "page size at http://... was ${value}kB" ); | ||
| 79 | # Output: PAGESIZE OK: page size at http://... was 36kB | size=36kB;10:25;25: time=... | ||
| 80 | # Return code: 0 | ||
| 81 | |||
| 82 | =head1 DESCRIPTION | ||
| 83 | |||
| 84 | This is the place for common routines when writing Nagios plugins. The idea is to make it as | ||
| 85 | easy as possible for developers to conform to the plugin guidelines | ||
| 86 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). | ||
| 87 | |||
| 88 | =head1 DESIGN | ||
| 89 | |||
| 90 | To facilitate object oriented classes, there are multiple perl modules, each reflecting a type of data | ||
| 91 | (ie, thresholds, ranges, performance). However, a plugin developer does not need to know about the | ||
| 92 | different types - a "use Nagios::Plugin" should be sufficient. | ||
| 93 | |||
| 94 | There is a Nagios::Plugin::Export. This holds all internals variables. You can specify these variables | ||
| 95 | when use'ing Nagios::Plugin | ||
| 96 | |||
| 97 | use Nagios::Plugin qw(%ERRORS) | ||
| 98 | print $ERRORS{WARNING} # prints 1 | ||
| 99 | |||
| 100 | =head1 VERSIONING | ||
| 101 | |||
| 102 | Only methods listed in the documentation for each module is public. | ||
| 103 | |||
| 104 | These modules are experimental and so the interfaces may change up until Nagios::Plugin | ||
| 105 | hits version 1.0, but every attempt will be made to make backwards compatible. | ||
| 106 | |||
| 107 | =over 4 | ||
| 108 | |||
| 109 | =head1 STARTING | ||
| 110 | |||
| 111 | =item use Nagios::Plugin qw(%ERRORS) | ||
| 112 | |||
| 113 | Imports the %ERRORS hash. This is currently the only symbol that can be imported. | ||
| 114 | |||
| 115 | =head1 CLASS METHODS | ||
| 116 | |||
| 117 | =item Nagios::Plugin->new( shortname => $$ ) | ||
| 118 | |||
| 119 | Initializes a new Nagios::Plugin object. Can specify the shortname here. | ||
| 120 | |||
| 121 | =head1 OBJECT METHODS | ||
| 122 | |||
| 123 | =item set_thresholds( warning => "10:25", critical => "25:" ) | ||
| 124 | |||
| 125 | Sets the thresholds, based on the range specification at | ||
| 126 | http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT. | ||
| 127 | Returns a Nagios::Plugin::Threshold object, which can be used to input a value to see which threshold | ||
| 128 | is crossed. | ||
| 129 | |||
| 130 | =item add_perfdata( label => "size", value => $value, uom => "kB", threshold => $threshold ) | ||
| 131 | |||
| 132 | Adds to an array a Nagios::Plugin::Performance object with the specified values. | ||
| 133 | |||
| 134 | This needs to be done separately to allow multiple perfdata output. | ||
| 135 | |||
| 136 | =item die( return_code => $ERRORS{CRITICAL}, message => "Output" ) | ||
| 137 | |||
| 138 | Exits the plugin and prints to STDOUT a Nagios plugin compatible output. Exits with the specified | ||
| 139 | return code. Also prints performance data if any have been added in. | ||
| 140 | |||
| 141 | =back | ||
| 142 | |||
| 143 | =head1 SEE ALSO | ||
| 144 | |||
| 145 | http://nagiosplug.sourceforge.net | ||
| 146 | |||
| 147 | =head1 AUTHOR | ||
| 148 | |||
| 149 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
| 150 | |||
| 151 | =head1 COPYRIGHT AND LICENSE | ||
| 152 | |||
| 153 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
| 154 | |||
| 155 | This library is free software; you can redistribute it and/or modify | ||
| 156 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
| 157 | at your option, any later version of Perl 5 you may have available. | ||
| 158 | |||
| 159 | |||
| 160 | =cut | ||
diff --git a/lib/Nagios/Plugin/Base.pm b/lib/Nagios/Plugin/Base.pm new file mode 100644 index 0000000..f3a7f7c --- /dev/null +++ b/lib/Nagios/Plugin/Base.pm | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | # This module holds all exported variables | ||
| 2 | # and base functions | ||
| 3 | package Nagios::Plugin::Base; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Exporter; | ||
| 9 | our @ISA = qw(Exporter); | ||
| 10 | our @EXPORT = qw(%ERRORS); | ||
| 11 | |||
| 12 | our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); | ||
| 13 | |||
| 14 | our %STATUS_TEXT = reverse %ERRORS; | ||
| 15 | |||
| 16 | my $exit_on_die = 1; | ||
| 17 | sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; | ||
| 18 | my $print_on_die = 1; | ||
| 19 | sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; | ||
| 20 | |||
| 21 | sub die { | ||
| 22 | my ($class, $args, $plugin) = @_; | ||
| 23 | my $return_code = $args->{return_code} || 3; | ||
| 24 | my $message = $args->{message} || "Internal error"; | ||
| 25 | my $output = join(" ", $STATUS_TEXT{$return_code}, $message); | ||
| 26 | if ($plugin) { | ||
| 27 | $output = $plugin->shortname." $output" if $plugin->shortname; | ||
| 28 | $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; | ||
| 29 | } | ||
| 30 | if ($print_on_die) { | ||
| 31 | print $output, $/; | ||
| 32 | } | ||
| 33 | if ($exit_on_die) { | ||
| 34 | exit $return_code; | ||
| 35 | } else { | ||
| 36 | return $output; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | __END__ | ||
| 42 | |||
| 43 | =head1 NAME | ||
| 44 | |||
| 45 | Nagios::Plugin::Base - Base functions for Nagios::Plugins | ||
| 46 | |||
| 47 | =head1 DESCRIPTION | ||
| 48 | |||
| 49 | See Nagios::Plugin for public interfaces. This module is for Nagios::Plugin developers to incorporate | ||
| 50 | common backend functionality. | ||
| 51 | |||
| 52 | =head1 AUTHOR | ||
| 53 | |||
| 54 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
| 55 | |||
| 56 | =head1 COPYRIGHT AND LICENSE | ||
| 57 | |||
| 58 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
| 59 | |||
| 60 | This library is free software; you can redistribute it and/or modify | ||
| 61 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
| 62 | at your option, any later version of Perl 5 you may have available. | ||
| 63 | |||
| 64 | |||
| 65 | =cut | ||
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm new file mode 100644 index 0000000..eee1bee --- /dev/null +++ b/lib/Nagios/Plugin/Performance.pm | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | package Nagios::Plugin::Performance; | ||
| 2 | |||
| 3 | use 5.008004; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Carp; | ||
| 9 | use Nagios::Plugin::Threshold; | ||
| 10 | use Class::Struct; | ||
| 11 | struct "Nagios::Plugin::Performance" => { | ||
| 12 | label => '$', | ||
| 13 | value => '$', | ||
| 14 | uom => '$', | ||
| 15 | threshold => 'Nagios::Plugin::Threshold', | ||
| 16 | min => '$', | ||
| 17 | max => '$', | ||
| 18 | }; | ||
| 19 | |||
| 20 | sub perfoutput { | ||
| 21 | my $self = shift; | ||
| 22 | my $output = $self->label."=".$self->value.$self->uom.";".$self->threshold->warning.";".$self->threshold->critical; | ||
| 23 | return $output; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub _parse { | ||
| 27 | my $class = shift; | ||
| 28 | my $string = shift; | ||
| 29 | my $p = $class->new; | ||
| 30 | $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)? *//; | ||
| 31 | return undef unless ($1 && $2); | ||
| 32 | $p->label($1); | ||
| 33 | $p->value($2+0); | ||
| 34 | $p->uom($3); | ||
| 35 | $p->threshold(Nagios::Plugin::Threshold->set_thresholds(warning => $4, critical => $5)); | ||
| 36 | $p->min($6); | ||
| 37 | $p->max($7); | ||
| 38 | return ($p, $string); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub parse_perfstring { | ||
| 42 | my ($class, $perfstring) = @_; | ||
| 43 | my @perfs; | ||
| 44 | my $obj; | ||
| 45 | while ($perfstring) { | ||
| 46 | ($obj, $perfstring) = $class->_parse($perfstring); | ||
| 47 | return undef unless $obj; | ||
| 48 | push @perfs, $obj; | ||
| 49 | } | ||
| 50 | return undef unless @perfs; | ||
| 51 | return @perfs; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 | __END__ | ||
| 56 | |||
| 57 | =head1 NAME | ||
| 58 | |||
| 59 | Nagios::Plugin::Performance - Performance information in a perl object | ||
| 60 | |||
| 61 | =head1 SYNOPSIS | ||
| 62 | |||
| 63 | use Nagios::Plugin::Performance; | ||
| 64 | |||
| 65 | @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | ||
| 66 | print "1st label = ", $p[0]->label, $/; | ||
| 67 | print "1st uom = ", $p[0]->uom, $/; | ||
| 68 | print "2nd crit = ", $p[1]->threshold->critical, $/; | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | Handles common Nagios Plugin performance data. This has a public interface because it could be | ||
| 73 | used by performance graphing routines, such as nagiostat (http://nagiostat.sourceforge.net), | ||
| 74 | perfparse (http://perfparse.sourceforge.net), nagiosgraph (http://nagiosgraph.sourceforge.net) or | ||
| 75 | NagiosGrapher (http://www.nagiosexchange.org/NagiosGrapher.84.0.html). | ||
| 76 | |||
| 77 | Once the performance string has been parsed, you can query the label, value, uom, or thresholds. | ||
| 78 | |||
| 79 | =head1 CLASS METHODS | ||
| 80 | |||
| 81 | =over 4 | ||
| 82 | |||
| 83 | =item Nagios::Plugin::Performance->parse_perfstring($string) | ||
| 84 | |||
| 85 | Returns an array of Nagios::Plugin::Performance objects based on the string entered. | ||
| 86 | If there is an error parsing the string, undef is returned. | ||
| 87 | |||
| 88 | =head1 OBJECT METHODS | ||
| 89 | |||
| 90 | =item label, value, uom, min, max | ||
| 91 | |||
| 92 | These all return scalars. min and max are not well supported yet. | ||
| 93 | |||
| 94 | =item threshold | ||
| 95 | |||
| 96 | This returns a Nagios::Plugin::Threshold object. | ||
| 97 | |||
| 98 | =back | ||
| 99 | |||
| 100 | =head1 SEE ALSO | ||
| 101 | |||
| 102 | Nagios::Plugin for information about versioning. | ||
| 103 | |||
| 104 | http://nagiosplug.sourceforge.net | ||
| 105 | |||
| 106 | =head1 AUTHOR | ||
| 107 | |||
| 108 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
| 109 | |||
| 110 | =head1 COPYRIGHT AND LICENSE | ||
| 111 | |||
| 112 | Copyright (C) 2006 by Altinity Limited | ||
| 113 | |||
| 114 | This library is free software; you can redistribute it and/or modify | ||
| 115 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
| 116 | at your option, any later version of Perl 5 you may have available. | ||
| 117 | |||
| 118 | |||
| 119 | =cut | ||
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm new file mode 100644 index 0000000..3d6f613 --- /dev/null +++ b/lib/Nagios/Plugin/Range.pm | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | package Nagios::Plugin::Range; | ||
| 2 | |||
| 3 | use 5.008004; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use overload | ||
| 9 | '""' => sub { shift->stringify }; | ||
| 10 | |||
| 11 | use Class::Struct; | ||
| 12 | struct "Nagios::Plugin::Range" => { | ||
| 13 | start => '$', | ||
| 14 | end => '$', | ||
| 15 | start_infinity => '$', # TRUE / FALSE | ||
| 16 | end_infinity => '$', # TRUE / FALSE | ||
| 17 | alert_on => '$', # OUTSIDE 0, INSIDE 1 | ||
| 18 | }; | ||
| 19 | |||
| 20 | my $outside = 0; | ||
| 21 | my $inside = 1; | ||
| 22 | |||
| 23 | sub stringify { | ||
| 24 | my $self = shift; | ||
| 25 | return (($self->alert_on) ? "@" : "") . | ||
| 26 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . | ||
| 27 | (($self->end_infinity == 1) ? "" : $self->end); | ||
| 28 | } | ||
| 29 | |||
| 30 | sub set_range_start { | ||
| 31 | my ($self, $value) = @_; | ||
| 32 | $self->start($value+0); # Force scalar into number | ||
| 33 | $self->start_infinity(0); | ||
| 34 | } | ||
| 35 | |||
| 36 | sub set_range_end { | ||
| 37 | my ($self, $value) = @_; | ||
| 38 | $self->end($value+0); # Force scalar into number | ||
| 39 | $self->end_infinity(0); | ||
| 40 | } | ||
| 41 | |||
| 42 | # Returns a N::P::Range object if the string is a conforms to a Nagios Plugin range string, otherwise null | ||
| 43 | sub parse_range_string { | ||
| 44 | my ($class, $string) = @_; | ||
| 45 | my $valid = 0; | ||
| 46 | my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => $outside); | ||
| 47 | |||
| 48 | if ($string =~ s/^\@//) { | ||
| 49 | $range->alert_on($inside); | ||
| 50 | } | ||
| 51 | if ($string =~ s/^~//) { | ||
| 52 | $range->start_infinity(1); | ||
| 53 | } | ||
| 54 | if (($_) = $string =~ /^([-\d\.]+)?:/) { | ||
| 55 | $range->set_range_start($_) if defined $_; | ||
| 56 | $string =~ s/^([-\d\.]+)?://; | ||
| 57 | $valid++ | ||
| 58 | } | ||
| 59 | if ($string =~ /^([-\d\.]+)$/) { | ||
| 60 | $range->set_range_end($string); | ||
| 61 | $valid++; | ||
| 62 | } | ||
| 63 | |||
| 64 | if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) { | ||
| 65 | return $range; | ||
| 66 | } | ||
| 67 | return undef; | ||
| 68 | } | ||
| 69 | |||
| 70 | # Returns 1 if an alert should be raised, otherwise 0 | ||
| 71 | sub check_range { | ||
| 72 | my ($self, $value) = @_; | ||
| 73 | my $false = 0; | ||
| 74 | my $true = 1; | ||
| 75 | if ($self->alert_on == $inside) { | ||
| 76 | $false = 1; | ||
| 77 | $true = 0; | ||
| 78 | } | ||
| 79 | if ($self->end_infinity == 0 && $self->start_infinity == 0) { | ||
| 80 | if ($self->start <= $value && $value <= $self->end) { | ||
| 81 | return $false; | ||
| 82 | } else { | ||
| 83 | return $true; | ||
| 84 | } | ||
| 85 | } elsif ($self->start_infinity == 0 && $self->end_infinity == 1) { | ||
| 86 | if ($self->start <= $value) { | ||
| 87 | return $false; | ||
| 88 | } else { | ||
| 89 | return $true; | ||
| 90 | } | ||
| 91 | } elsif ($self->start_infinity == 1 && $self->end_infinity == 0) { | ||
| 92 | if ($value <= $self->end) { | ||
| 93 | return $false; | ||
| 94 | } else { | ||
| 95 | return $true; | ||
| 96 | } | ||
| 97 | } else { | ||
| 98 | return $false; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; | ||
| 103 | __END__ | ||
| 104 | |||
| 105 | =head1 NAME | ||
| 106 | |||
| 107 | Nagios::Plugin::Range - Common range functions for Nagios::Plugin | ||
| 108 | |||
| 109 | =head1 DESCRIPTION | ||
| 110 | |||
| 111 | Handles common Nagios Plugin range data. See Nagios::Plugin for creation interfaces. | ||
| 112 | |||
| 113 | =head1 AUTHOR | ||
| 114 | |||
| 115 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
| 116 | |||
| 117 | =head1 COPYRIGHT AND LICENSE | ||
| 118 | |||
| 119 | Copyright (C) 2006 by Altinity Limited | ||
| 120 | |||
| 121 | This library is free software; you can redistribute it and/or modify | ||
| 122 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
| 123 | at your option, any later version of Perl 5 you may have available. | ||
| 124 | |||
| 125 | |||
| 126 | =cut | ||
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 @@ | |||
| 1 | package Nagios::Plugin::Threshold; | ||
| 2 | |||
| 3 | use 5.008004; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Nagios::Plugin::Range; | ||
| 9 | use Nagios::Plugin::Base; | ||
| 10 | |||
| 11 | use Class::Struct; | ||
| 12 | struct "Nagios::Plugin::Threshold" => { | ||
| 13 | warning => 'Nagios::Plugin::Range', | ||
| 14 | critical => 'Nagios::Plugin::Range', | ||
| 15 | }; | ||
| 16 | |||
| 17 | sub set_thresholds { | ||
| 18 | my ($class, %args) = @_; | ||
| 19 | my $t = $class->new; | ||
| 20 | if (defined $args{warning}) { | ||
| 21 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); | ||
| 22 | if (defined $r) { | ||
| 23 | $t->warning($r); | ||
| 24 | } else { | ||
| 25 | Nagios::Plugin::Base->die( { | ||
| 26 | return_code => $ERRORS{UNKNOWN}, | ||
| 27 | message => "Warning range incorrect: '$args{warning}'" | ||
| 28 | } ); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | if (defined $args{critical}) { | ||
| 32 | my $r = Nagios::Plugin::Range->parse_range_string($args{critical}); | ||
| 33 | if (defined $r) { | ||
| 34 | $t->critical($r); | ||
| 35 | } else { | ||
| 36 | Nagios::Plugin::Base->die( { | ||
| 37 | return_code => $ERRORS{UNKNOWN}, | ||
| 38 | message => "Critical range incorrect: '$args{critical}'" | ||
| 39 | } ); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | return $t; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub get_status { | ||
| 46 | my ($self, $value) = @_; | ||
| 47 | if ($self->critical) { | ||
| 48 | if ($self->critical->check_range($value) == 1) { | ||
| 49 | return $ERRORS{CRITICAL}; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | if ($self->warning) { | ||
| 53 | if ($self->warning->check_range($value) == 1) { | ||
| 54 | return $ERRORS{WARNING}; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; | ||
| 60 | __END__ | ||
| 61 | |||
| 62 | =head1 NAME | ||
| 63 | |||
| 64 | Nagios::Plugin::Threshold - Threshold information in a perl object | ||
| 65 | |||
| 66 | =head1 DESCRIPTION | ||
| 67 | |||
| 68 | Handles common Nagios Plugin threshold data. See Nagios::Plugin or Nagios::Plugin::Performance for | ||
| 69 | creation of this object. | ||
| 70 | |||
| 71 | =head1 OBJECT METHODS | ||
| 72 | |||
| 73 | =over 4 | ||
| 74 | |||
| 75 | =item warning, critical | ||
| 76 | |||
| 77 | Returns the warning or critical range as a Nagios::Plugin::Range object. | ||
| 78 | |||
| 79 | =item get_status($value) | ||
| 80 | |||
| 81 | Given a value, will see if the value breeches the critical or the warning range. Returns the status code. | ||
| 82 | |||
| 83 | =head1 AUTHOR | ||
| 84 | |||
| 85 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
| 86 | |||
| 87 | =head1 COPYRIGHT AND LICENSE | ||
| 88 | |||
| 89 | Copyright (C) 2006 by Altinity Limited | ||
| 90 | |||
| 91 | This library is free software; you can redistribute it and/or modify | ||
| 92 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
| 93 | at your option, any later version of Perl 5 you may have available. | ||
| 94 | |||
| 95 | |||
| 96 | =cut | ||
