summaryrefslogtreecommitdiffstats
path: root/t/Nagios-Plugin-Performance.t
diff options
context:
space:
mode:
Diffstat (limited to 't/Nagios-Plugin-Performance.t')
-rw-r--r--t/Nagios-Plugin-Performance.t48
1 files changed, 44 insertions, 4 deletions
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t
index 1ae330a..0dcb800 100644
--- a/t/Nagios-Plugin-Performance.t
+++ b/t/Nagios-Plugin-Performance.t
@@ -1,6 +1,6 @@
1 1
2use strict; 2use strict;
3use Test::More tests => 49; 3use Test::More tests => 77;
4BEGIN { use_ok('Nagios::Plugin::Performance') }; 4BEGIN { use_ok('Nagios::Plugin::Performance') };
5 5
6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; 6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
@@ -8,15 +8,55 @@ diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performan
8use Nagios::Plugin::Functions; 8use Nagios::Plugin::Functions;
9Nagios::Plugin::Functions::_fake_exit(1); 9Nagios::Plugin::Functions::_fake_exit(1);
10 10
11my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); 11my (@p, $p);
12my @test = (
13 {
14 perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768,
15 }, {
16 perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef,
17 },
18);
19
20# Round-trip tests
21for my $t (@test) {
22 # Parse to components
23 ($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput});
24 for (sort keys %$t) {
25 next if m/^perfoutput$/;
26 is($p->$_(), $t->{$_}, "$_ okay (" . (defined $t->{$_} ? $t->{$_} : 'undef') . ")");
27 }
28
29 # Construct from components
30 my @construct = qw(label value uom warning critical min max);
31 $p = Nagios::Plugin::Performance->new(map { $_ => $t->{$_} } @construct);
32 is($p->perfoutput, $t->{perfoutput}, "perfoutput okay ($t->{perfoutput})");
33 # Check threshold accessor
34 is($p->threshold->warning->end, $t->{warning}, "threshold warning okay ($t->{warning})");
35 is($p->threshold->critical->end, $t->{critical}, "threshold critical okay ($t->{critical})");
36
37 # Construct using threshold
38 @construct = qw(label value uom min max);
39 $p = Nagios::Plugin::Performance->new(
40 map({ $_ => $t->{$_} } @construct),
41 threshold => Nagios::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}),
42 );
43 is($p->perfoutput, $t->{perfoutput}, "perfoutput okay ($t->{perfoutput})");
44 # Check warning/critical accessors
45 is($p->warning, $t->{warning}, "warning okay ($t->{warning})");
46 is($p->critical, $t->{critical}, "critical okay ($t->{critical})");
47}
48
49
50# Test multiple parse_perfstrings
51@p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
12cmp_ok( $p[0]->label, 'eq', "/", "label okay"); 52cmp_ok( $p[0]->label, 'eq', "/", "label okay");
13cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); 53cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay");
14cmp_ok( $p[0]->value, '==', 382, "value okay"); 54cmp_ok( $p[0]->value, '==', 382, "value okay");
15cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); 55cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay");
16cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); 56cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay");
17cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); 57cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay");
18ok( ! defined $p[0]->min, "min okay"); 58ok(! defined $p[0]->min, "min undef");
19ok( ! defined $p[0]->max, "max okay"); 59ok(! defined $p[0]->max, "max undef");
20 60
21cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); 61cmp_ok( $p[1]->label, 'eq', "/var", "label okay");
22cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); 62cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay");