diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-15 09:11:54 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-15 09:11:54 +0000 |
commit | f948ceecba9b5f6cb0aef9aae6f6be18ba6feffe (patch) | |
tree | 687e8c72f89ae9cced849754e362f1cde19ae745 /lib/Nagios/Plugin | |
parent | e736a3c2b0a62707f12cf66fbb65ef23eeb01dd6 (diff) | |
download | monitoring-plugin-perl-f948ceecba9b5f6cb0aef9aae6f6be18ba6feffe.tar.gz |
is_set method to see if a range has been set
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1429 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin')
-rw-r--r-- | lib/Nagios/Plugin/Range.pm | 8 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index 3d6f613..c03001a 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm | |||
@@ -14,7 +14,7 @@ struct "Nagios::Plugin::Range" => { | |||
14 | end => '$', | 14 | end => '$', |
15 | start_infinity => '$', # TRUE / FALSE | 15 | start_infinity => '$', # TRUE / FALSE |
16 | end_infinity => '$', # TRUE / FALSE | 16 | end_infinity => '$', # TRUE / FALSE |
17 | alert_on => '$', # OUTSIDE 0, INSIDE 1 | 17 | alert_on => '$', # OUTSIDE 0, INSIDE 1, not defined == range not set |
18 | }; | 18 | }; |
19 | 19 | ||
20 | my $outside = 0; | 20 | my $outside = 0; |
@@ -22,11 +22,17 @@ my $inside = 1; | |||
22 | 22 | ||
23 | sub stringify { | 23 | sub stringify { |
24 | my $self = shift; | 24 | my $self = shift; |
25 | return "" unless $self->is_set; | ||
25 | return (($self->alert_on) ? "@" : "") . | 26 | return (($self->alert_on) ? "@" : "") . |
26 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . | 27 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . |
27 | (($self->end_infinity == 1) ? "" : $self->end); | 28 | (($self->end_infinity == 1) ? "" : $self->end); |
28 | } | 29 | } |
29 | 30 | ||
31 | sub is_set { | ||
32 | my $self = shift; | ||
33 | (! defined $self->alert_on) ? 0 : 1; | ||
34 | } | ||
35 | |||
30 | sub set_range_start { | 36 | sub set_range_start { |
31 | my ($self, $value) = @_; | 37 | my ($self, $value) = @_; |
32 | $self->start($value+0); # Force scalar into number | 38 | $self->start($value+0); # Force scalar into number |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 9c5d042..1b332b9 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -16,7 +16,7 @@ struct "Nagios::Plugin::Threshold" => { | |||
16 | 16 | ||
17 | sub set_thresholds { | 17 | sub set_thresholds { |
18 | my ($class, %args) = @_; | 18 | my ($class, %args) = @_; |
19 | my $t = $class->new; | 19 | my $t = $class->new( warning => Nagios::Plugin::Range->new, critical => Nagios::Plugin::Range->new ); |
20 | if (defined $args{warning}) { | 20 | if (defined $args{warning}) { |
21 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); | 21 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); |
22 | if (defined $r) { | 22 | if (defined $r) { |
@@ -44,12 +44,12 @@ sub set_thresholds { | |||
44 | 44 | ||
45 | sub get_status { | 45 | sub get_status { |
46 | my ($self, $value) = @_; | 46 | my ($self, $value) = @_; |
47 | if ($self->critical) { | 47 | if ($self->critical->is_set) { |
48 | if ($self->critical->check_range($value) == 1) { | 48 | if ($self->critical->check_range($value) == 1) { |
49 | return $ERRORS{CRITICAL}; | 49 | return $ERRORS{CRITICAL}; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | if ($self->warning) { | 52 | if ($self->warning->is_set) { |
53 | if ($self->warning->check_range($value) == 1) { | 53 | if ($self->warning->check_range($value) == 1) { |
54 | return $ERRORS{WARNING}; | 54 | return $ERRORS{WARNING}; |
55 | } | 55 | } |