summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Range.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Nagios/Plugin/Range.pm')
-rw-r--r--lib/Nagios/Plugin/Range.pm44
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;
10our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 10our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
11 11
12use overload 12use overload
13 '""' => sub { shift->stringify }; 13 '""' => sub { shift->_stringify };
14 14
15use Class::Struct; 15use Class::Struct;
16struct "Nagios::Plugin::Range" => { 16struct "Nagios::Plugin::Range" => {
@@ -24,7 +24,7 @@ struct "Nagios::Plugin::Range" => {
24use constant OUTSIDE => 0; 24use constant OUTSIDE => 0;
25use constant INSIDE => 1; 25use constant INSIDE => 1;
26 26
27sub stringify { 27sub _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
40sub set_range_start { 40sub _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
46sub set_range_end { 46sub _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
127Nagios::Plugin::Range - Common range functions for Nagios::Plugin 127Nagios::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
131Handles common Nagios Plugin range data. See Nagios::Plugin for creation interfaces. 149Internal Nagios::Plugin class for handling common range data. See
150Nagios::Plugin for public interfaces.
132 151
133=head1 AUTHOR 152=head1 AUTHOR
134 153
135This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net 154This code is maintained by the Nagios Plugin Development Team: see
155http://nagiosplug.sourceforge.net.
136 156
137=head1 COPYRIGHT AND LICENSE 157=head1 COPYRIGHT AND LICENSE
138 158
139Copyright (C) 2006 Nagios Plugin Development Team 159Copyright (C) 2006-2007 Nagios Plugin Development Team
140 160
141This library is free software; you can redistribute it and/or modify 161This library is free software; you can redistribute it and/or modify
142it under the same terms as Perl itself, either Perl version 5.8.4 or, 162it under the same terms as Perl itself.
143at your option, any later version of Perl 5 you may have available.
144
145 163
146=cut 164=cut