diff options
author | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-14 23:47:23 +0000 |
---|---|---|
committer | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-14 23:47:23 +0000 |
commit | e5109f99c9657a1a8e9fb32b19254a417e2ccd65 (patch) | |
tree | 2fdbad42f466051ffc2e332cf0a2573976e3a56c /lib/Nagios/Plugin/Range.pm | |
parent | 489df48f9d1891b46ae4be911080ab4667058f2d (diff) | |
download | monitoring-plugin-perl-e5109f99c9657a1a8e9fb32b19254a417e2ccd65.tar.gz |
Refactor N::P::Performance; cleanups to Threshold and Range (mostly perldocs).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1640 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin/Range.pm')
-rw-r--r-- | lib/Nagios/Plugin/Range.pm | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index 691506f..dbb637c 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm | |||
@@ -10,7 +10,7 @@ use Nagios::Plugin::Functions; | |||
10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
11 | 11 | ||
12 | use overload | 12 | use overload |
13 | '""' => sub { shift->stringify }; | 13 | '""' => sub { shift->_stringify }; |
14 | 14 | ||
15 | use Class::Struct; | 15 | use Class::Struct; |
16 | struct "Nagios::Plugin::Range" => { | 16 | struct "Nagios::Plugin::Range" => { |
@@ -24,7 +24,7 @@ struct "Nagios::Plugin::Range" => { | |||
24 | use constant OUTSIDE => 0; | 24 | use constant OUTSIDE => 0; |
25 | use constant INSIDE => 1; | 25 | use constant INSIDE => 1; |
26 | 26 | ||
27 | sub stringify { | 27 | sub _stringify { |
28 | my $self = shift; | 28 | my $self = shift; |
29 | return "" unless $self->is_set; | 29 | return "" unless $self->is_set; |
30 | return (($self->alert_on) ? "@" : "") . | 30 | return (($self->alert_on) ? "@" : "") . |
@@ -37,13 +37,13 @@ sub is_set { | |||
37 | (! defined $self->alert_on) ? 0 : 1; | 37 | (! defined $self->alert_on) ? 0 : 1; |
38 | } | 38 | } |
39 | 39 | ||
40 | sub set_range_start { | 40 | sub _set_range_start { |
41 | my ($self, $value) = @_; | 41 | my ($self, $value) = @_; |
42 | $self->start($value+0); # Force scalar into number | 42 | $self->start($value+0); # Force scalar into number |
43 | $self->start_infinity(0); | 43 | $self->start_infinity(0); |
44 | } | 44 | } |
45 | 45 | ||
46 | sub set_range_end { | 46 | sub _set_range_end { |
47 | my ($self, $value) = @_; | 47 | my ($self, $value) = @_; |
48 | $self->end($value+0); # Force scalar into number | 48 | $self->end($value+0); # Force scalar into number |
49 | $self->end_infinity(0); | 49 | $self->end_infinity(0); |
@@ -71,13 +71,13 @@ sub parse_range_string { | |||
71 | } | 71 | } |
72 | if ( $string =~ m/^([\d\.-]+)?:/ ) { # '10:' | 72 | if ( $string =~ m/^([\d\.-]+)?:/ ) { # '10:' |
73 | my $start = $1; | 73 | my $start = $1; |
74 | $range->set_range_start($start) if defined $start; | 74 | $range->_set_range_start($start) if defined $start; |
75 | $range->end_infinity(1); # overridden below if there's an end specified | 75 | $range->end_infinity(1); # overridden below if there's an end specified |
76 | $string =~ s/^([-\d\.]+)?://; | 76 | $string =~ s/^([-\d\.]+)?://; |
77 | $valid++; | 77 | $valid++; |
78 | } | 78 | } |
79 | if ($string =~ /^([-\d\.]+)$/) { # 'x:10' or '10' | 79 | if ($string =~ /^([-\d\.]+)$/) { # 'x:10' or '10' |
80 | $range->set_range_end($string); | 80 | $range->_set_range_end($string); |
81 | $valid++; | 81 | $valid++; |
82 | } | 82 | } |
83 | 83 | ||
@@ -124,23 +124,41 @@ __END__ | |||
124 | 124 | ||
125 | =head1 NAME | 125 | =head1 NAME |
126 | 126 | ||
127 | Nagios::Plugin::Range - Common range functions for Nagios::Plugin | 127 | Nagios::Plugin::Range - class for handling Nagios::Plugin range data. |
128 | |||
129 | =head1 SYNOPSIS | ||
130 | |||
131 | # NB: This is an internal Nagios::Plugin class. | ||
132 | # See Nagios::Plugin itself for public interfaces. | ||
133 | |||
134 | # Instantiate an empty range object | ||
135 | $r = Nagios::Plugin::Range->new; | ||
136 | |||
137 | # Instantiate by parsing a standard nagios range string | ||
138 | $r = Nagios::Plugin::Range->parse_range_string; | ||
139 | |||
140 | # Returns true if the range is defined/non-empty | ||
141 | $r->is_set; | ||
142 | |||
143 | # Returns true if $value matches range, false otherwise | ||
144 | $r->check_range($value); | ||
145 | |||
128 | 146 | ||
129 | =head1 DESCRIPTION | 147 | =head1 DESCRIPTION |
130 | 148 | ||
131 | Handles common Nagios Plugin range data. See Nagios::Plugin for creation interfaces. | 149 | Internal Nagios::Plugin class for handling common range data. See |
150 | Nagios::Plugin for public interfaces. | ||
132 | 151 | ||
133 | =head1 AUTHOR | 152 | =head1 AUTHOR |
134 | 153 | ||
135 | This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net | 154 | This code is maintained by the Nagios Plugin Development Team: see |
155 | http://nagiosplug.sourceforge.net. | ||
136 | 156 | ||
137 | =head1 COPYRIGHT AND LICENSE | 157 | =head1 COPYRIGHT AND LICENSE |
138 | 158 | ||
139 | Copyright (C) 2006 Nagios Plugin Development Team | 159 | Copyright (C) 2006-2007 Nagios Plugin Development Team |
140 | 160 | ||
141 | This library is free software; you can redistribute it and/or modify | 161 | This library is free software; you can redistribute it and/or modify |
142 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | 162 | it under the same terms as Perl itself. |
143 | at your option, any later version of Perl 5 you may have available. | ||
144 | |||
145 | 163 | ||
146 | =cut | 164 | =cut |