diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
commit | 2c6651034f76e2bccb549a867485f8fabbf07cb1 (patch) | |
tree | 8de53d7efe4564017e1ebce73353c7e3a3c8b548 /lib/Nagios/Plugin/Threshold.pm | |
parent | 83e29d795dddf34a652cda8665179b77372ddcfe (diff) | |
download | monitoring-plugin-perl-2c6651034f76e2bccb549a867485f8fabbf07cb1.tar.gz |
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1419 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin/Threshold.pm')
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 96 |
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 @@ | |||
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 | ||