diff options
Diffstat (limited to 't/Monitoring-Plugin-01.t')
| -rw-r--r-- | t/Monitoring-Plugin-01.t | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-01.t b/t/Monitoring-Plugin-01.t new file mode 100644 index 0000000..f5882a5 --- /dev/null +++ b/t/Monitoring-Plugin-01.t | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | # Monitoring::Plugin original test cases | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Test::More tests => 15; | ||
| 5 | |||
| 6 | BEGIN { use_ok('Monitoring::Plugin') }; | ||
| 7 | |||
| 8 | use Monitoring::Plugin::Functions; | ||
| 9 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
| 10 | |||
| 11 | diag "\nusing Monitoring::Plugin revision ". $Monitoring::Plugin::VERSION . "\n" | ||
| 12 | if $ENV{TEST_VERBOSE}; | ||
| 13 | |||
| 14 | my $p = Monitoring::Plugin->new(); | ||
| 15 | isa_ok( $p, "Monitoring::Plugin"); | ||
| 16 | |||
| 17 | $p->shortname("PAGESIZE"); | ||
| 18 | is($p->shortname, "PAGESIZE", "shortname explicitly set correctly"); | ||
| 19 | |||
| 20 | $p = Monitoring::Plugin->new(); | ||
| 21 | is($p->shortname, "MONITORING-PLUGIN-01", "shortname should default on new"); | ||
| 22 | |||
| 23 | $p = Monitoring::Plugin->new( shortname => "SIZE", () ); | ||
| 24 | is($p->shortname, "SIZE", "shortname set correctly on new"); | ||
| 25 | |||
| 26 | $p = Monitoring::Plugin->new( plugin => "check_stuff", () ); | ||
| 27 | is($p->shortname, "STUFF", "shortname uses plugin name as default"); | ||
| 28 | |||
| 29 | $p = Monitoring::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () ); | ||
| 30 | is($p->shortname, "SIZE", "shortname is not overriden by default"); | ||
| 31 | |||
| 32 | diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; | ||
| 33 | my $t = $p->set_thresholds( warning => "10:25", critical => "~:25" ); | ||
| 34 | |||
| 35 | use Data::Dumper; | ||
| 36 | #diag "dumping p: ". Dumper $p; | ||
| 37 | #diag "dumping perfdata: ". Dumper $p->perfdata; | ||
| 38 | |||
| 39 | |||
| 40 | $p->add_perfdata( | ||
| 41 | label => "size", | ||
| 42 | value => 1, | ||
| 43 | uom => "kB", | ||
| 44 | threshold => $t, | ||
| 45 | ); | ||
| 46 | |||
| 47 | cmp_ok( $p->all_perfoutput, 'eq', "size=1kB;10:25;~:25", "Perfdata correct"); | ||
| 48 | #diag "dumping perfdata: ". Dumper ($p->perfdata); | ||
| 49 | |||
| 50 | $p->add_perfdata( | ||
| 51 | label => "time", | ||
| 52 | value => "3.52", | ||
| 53 | threshold => $t, | ||
| 54 | ); | ||
| 55 | |||
| 56 | is( $p->all_perfoutput, "size=1kB;10:25;~:25 time=3.52;10:25;~:25", "Perfdata correct when no uom specified"); | ||
| 57 | |||
| 58 | my $expected = {qw( | ||
| 59 | -1 WARNING | ||
| 60 | 1 WARNING | ||
| 61 | 20 OK | ||
| 62 | 25 OK | ||
| 63 | 26 CRITICAL | ||
| 64 | 30 CRITICAL | ||
| 65 | )}; | ||
| 66 | |||
| 67 | foreach (sort {$a<=>$b} keys %$expected) { | ||
| 68 | like $p->die( return_code => $t->get_status($_), message => "page size at http://... was ${_}kB" ), | ||
| 69 | qr/$expected->{$_}/, | ||
| 70 | "Output okay. $_ = $expected->{$_}" ; | ||
| 71 | } | ||
