summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Threshold.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Nagios/Plugin/Threshold.pm')
-rw-r--r--lib/Nagios/Plugin/Threshold.pm96
1 files changed, 96 insertions, 0 deletions
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 @@
1package Nagios::Plugin::Threshold;
2
3use 5.008004;
4
5use strict;
6use warnings;
7
8use Nagios::Plugin::Range;
9use Nagios::Plugin::Base;
10
11use Class::Struct;
12struct "Nagios::Plugin::Threshold" => {
13 warning => 'Nagios::Plugin::Range',
14 critical => 'Nagios::Plugin::Range',
15 };
16
17sub 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
45sub 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
591;
60__END__
61
62=head1 NAME
63
64Nagios::Plugin::Threshold - Threshold information in a perl object
65
66=head1 DESCRIPTION
67
68Handles common Nagios Plugin threshold data. See Nagios::Plugin or Nagios::Plugin::Performance for
69creation of this object.
70
71=head1 OBJECT METHODS
72
73=over 4
74
75=item warning, critical
76
77Returns the warning or critical range as a Nagios::Plugin::Range object.
78
79=item get_status($value)
80
81Given a value, will see if the value breeches the critical or the warning range. Returns the status code.
82
83=head1 AUTHOR
84
85Ton Voon, E<lt>ton.voon@altinity.comE<gt>
86
87=head1 COPYRIGHT AND LICENSE
88
89Copyright (C) 2006 by Altinity Limited
90
91This library is free software; you can redistribute it and/or modify
92it under the same terms as Perl itself, either Perl version 5.8.4 or,
93at your option, any later version of Perl 5 you may have available.
94
95
96=cut