[Nagiosplug-checkins] Nagios-Plugin/lib/Nagios/Plugin Base.pm, 1.1.1.1, 1.2 Performance.pm, 1.3, 1.4 Range.pm, 1.2, 1.3 Threshold.pm, 1.2, 1.3
Ton Voon
tonvoon at users.sourceforge.net
Fri Aug 4 22:22:33 CEST 2006
- Previous message: [Nagiosplug-checkins] Nagios-Plugin Changes,1.6,1.7
- Next message: [Nagiosplug-checkins] Nagios-Plugin/t Nagios-Plugin-Performance.t, 1.4, 1.5 Nagios-Plugin-Range.t, 1.1.1.1, 1.2 Nagios-Plugin-Threshold.t, 1.2, 1.3 Nagios-Plugin.t, 1.1.1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10683/lib/Nagios/Plugin
Modified Files:
Base.pm Performance.pm Range.pm Threshold.pm
Log Message:
Lots of extra tests and subsequent fixes (Nathan Vonnahme)
Index: Base.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Base.pm,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Base.pm 8 Jun 2006 12:27:44 -0000 1.1.1.1
+++ Base.pm 4 Aug 2006 20:22:31 -0000 1.2
@@ -5,6 +5,9 @@
use strict;
use warnings;
+use Nagios::Plugin;
+our ($VERSION) = $Nagios::Plugin::VERSION;
+
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(%ERRORS);
@@ -13,28 +16,38 @@
our %STATUS_TEXT = reverse %ERRORS;
+
my $exit_on_die = 1;
sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die };
my $print_on_die = 1;
sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die };
sub die {
- my ($class, $args, $plugin) = @_;
- my $return_code = $args->{return_code} || 3;
- my $message = $args->{message} || "Internal error";
- my $output = join(" ", $STATUS_TEXT{$return_code}, $message);
- if ($plugin) {
- $output = $plugin->shortname." $output" if $plugin->shortname;
- $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata;
- }
- if ($print_on_die) {
- print $output, $/;
- }
- if ($exit_on_die) {
- exit $return_code;
- } else {
- return $output;
- }
+ my ($class, $args, $plugin) = @_;
+ my $return_code;
+
+ if ( exists $args->{return_code}
+ && exists $STATUS_TEXT{$args->{return_code}}
+ ) {
+ $return_code = $args->{return_code};
+ }
+ else {
+ $return_code = $ERRORS{UNKNOWN};
+ }
+ my $message = $args->{message} || "Internal error";
+ my $output = join(" ", $STATUS_TEXT{$return_code}, $message);
+ if ($plugin) {
+ $output = $plugin->shortname." $output" if $plugin->shortname;
+ $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata;
+ }
+ if ($print_on_die) {
+ print $output, $/;
+ }
+ if ($exit_on_die) {
+ exit $return_code;
+ } else {
+ return $output;
+ }
}
1;
Index: Performance.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Performance.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Performance.pm 15 Jun 2006 08:38:18 -0000 1.3
+++ Performance.pm 4 Aug 2006 20:22:31 -0000 1.4
@@ -7,6 +7,9 @@
use Carp;
use Nagios::Plugin::Threshold;
+use Nagios::Plugin;
+our ($VERSION) = $Nagios::Plugin::VERSION;
+
use Class::Struct;
struct "Nagios::Plugin::Performance" => {
label => '$',
Index: Threshold.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Threshold.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Threshold.pm 15 Jun 2006 09:11:54 -0000 1.2
+++ Threshold.pm 4 Aug 2006 20:22:31 -0000 1.3
@@ -7,6 +7,8 @@
use Nagios::Plugin::Range;
use Nagios::Plugin::Base;
+use Nagios::Plugin;
+our ($VERSION) = $Nagios::Plugin::VERSION;
use Class::Struct;
struct "Nagios::Plugin::Threshold" => {
@@ -44,6 +46,7 @@
sub get_status {
my ($self, $value) = @_;
+
if ($self->critical->is_set) {
if ($self->critical->check_range($value) == 1) {
return $ERRORS{CRITICAL};
@@ -54,6 +57,7 @@
return $ERRORS{WARNING};
}
}
+ return $ERRORS{OK};
}
1;
Index: Range.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Range.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Range.pm 15 Jun 2006 09:11:54 -0000 1.2
+++ Range.pm 4 Aug 2006 20:22:31 -0000 1.3
@@ -4,6 +4,10 @@
use strict;
use warnings;
+use Carp;
+
+use Nagios::Plugin;
+our ($VERSION) = $Nagios::Plugin::VERSION;
use overload
'""' => sub { shift->stringify };
@@ -17,8 +21,8 @@
alert_on => '$', # OUTSIDE 0, INSIDE 1, not defined == range not set
};
-my $outside = 0;
-my $inside = 1;
+use constant OUTSIDE => 0;
+use constant INSIDE => 1;
sub stringify {
my $self = shift;
@@ -49,22 +53,32 @@
sub parse_range_string {
my ($class, $string) = @_;
my $valid = 0;
- my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => $outside);
+ my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => OUTSIDE);
+
+ $string =~ s/\s//g; # strip out any whitespace
+ # check for valid range definition
+ unless ( $string =~ /[\d~]/ && $string =~ m/^\@?(-?[\d.]+|~)?(:(-?[\d.]+)?)?$/ ) {
+ carp "invalid range definition '$string'";
+ return undef;
+ }
if ($string =~ s/^\@//) {
- $range->alert_on($inside);
+ $range->alert_on(INSIDE);
}
- if ($string =~ s/^~//) {
- $range->start_infinity(1);
+
+ if ($string =~ s/^~//) { # '~:x'
+ $range->start_infinity(1);
}
- if (($_) = $string =~ /^([-\d\.]+)?:/) {
- $range->set_range_start($_) if defined $_;
- $string =~ s/^([-\d\.]+)?://;
- $valid++
+ if ( $string =~ m/^([\d\.-]+)?:/ ) { # '10:'
+ my $start = $1;
+ $range->set_range_start($start) if defined $start;
+ $range->end_infinity(1); # overridden below if there's an end specified
+ $string =~ s/^([-\d\.]+)?://;
+ $valid++;
}
- if ($string =~ /^([-\d\.]+)$/) {
- $range->set_range_end($string);
- $valid++;
+ if ($string =~ /^([-\d\.]+)$/) { # 'x:10' or '10'
+ $range->set_range_end($string);
+ $valid++;
}
if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) {
@@ -78,7 +92,7 @@
my ($self, $value) = @_;
my $false = 0;
my $true = 1;
- if ($self->alert_on == $inside) {
+ if ($self->alert_on == INSIDE) {
$false = 1;
$true = 0;
}
@@ -89,7 +103,7 @@
return $true;
}
} elsif ($self->start_infinity == 0 && $self->end_infinity == 1) {
- if ($self->start <= $value) {
+ if ( $value >= $self->start ) {
return $false;
} else {
return $true;
- Previous message: [Nagiosplug-checkins] Nagios-Plugin Changes,1.6,1.7
- Next message: [Nagiosplug-checkins] Nagios-Plugin/t Nagios-Plugin-Performance.t, 1.4, 1.5 Nagios-Plugin-Range.t, 1.1.1.1, 1.2 Nagios-Plugin-Threshold.t, 1.2, 1.3 Nagios-Plugin.t, 1.1.1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commits
mailing list