diff options
| author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
|---|---|---|
| committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
| commit | 2c6651034f76e2bccb549a867485f8fabbf07cb1 (patch) | |
| tree | 8de53d7efe4564017e1ebce73353c7e3a3c8b548 /t | |
| parent | 83e29d795dddf34a652cda8665179b77372ddcfe (diff) | |
| download | monitoring-plugin-perl-2c6651034f76e2bccb549a867485f8fabbf07cb1.tar.gz | |
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1419 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 't')
| -rw-r--r-- | t/Nagios-Plugin-Performance.t | 63 | ||||
| -rw-r--r-- | t/Nagios-Plugin-Range.t | 84 | ||||
| -rw-r--r-- | t/Nagios-Plugin-Threshold.t | 32 | ||||
| -rw-r--r-- | t/Nagios-Plugin.t | 32 |
4 files changed, 211 insertions, 0 deletions
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t new file mode 100644 index 0000000..2fe2326 --- /dev/null +++ b/t/Nagios-Plugin-Performance.t | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 42; | ||
| 4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | ||
| 5 | |||
| 6 | use Nagios::Plugin::Base; | ||
| 7 | Nagios::Plugin::Base->exit_on_die(0); | ||
| 8 | |||
| 9 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | ||
| 10 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | ||
| 11 | cmp_ok( $p[0]->value, '==', 382, "value okay"); | ||
| 12 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); | ||
| 13 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); | ||
| 14 | cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); | ||
| 15 | ok( ! defined $p[0]->min, "min okay"); | ||
| 16 | ok( ! defined $p[0]->max, "max okay"); | ||
| 17 | |||
| 18 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); | ||
| 19 | cmp_ok( $p[1]->value, '==', 218, "value okay"); | ||
| 20 | cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); | ||
| 21 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); | ||
| 22 | cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); | ||
| 23 | |||
| 24 | ok( ! defined Nagios::Plugin::Performance->parse_perfstring("rubbish"), "Errors correctly"); | ||
| 25 | ok( ! defined Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); | ||
| 26 | |||
| 27 | @p = Nagios::Plugin::Performance->parse_perfstring( | ||
| 28 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); | ||
| 29 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | ||
| 30 | cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); | ||
| 31 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | ||
| 32 | cmp_ok( $p[0]->threshold->warning, "eq", "0", "warn okay"); | ||
| 33 | cmp_ok( $p[0]->threshold->critical, "eq", "0", "crit okay"); | ||
| 34 | |||
| 35 | @p = Nagios::Plugin::Performance->parse_perfstring( | ||
| 36 | "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); | ||
| 37 | cmp_ok( $p[0]->label, "eq", "load1", "label okay"); | ||
| 38 | cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); | ||
| 39 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | ||
| 40 | cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); | ||
| 41 | cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); | ||
| 42 | cmp_ok( $p[1]->label, "eq", "load5", "label okay"); | ||
| 43 | cmp_ok( $p[2]->label, "eq", "load15", "label okay"); | ||
| 44 | |||
| 45 | @p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); | ||
| 46 | cmp_ok( $p[0]->label, "eq", "users", "label okay"); | ||
| 47 | cmp_ok( $p[0]->value, "==", 4, "value okay"); | ||
| 48 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | ||
| 49 | cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); | ||
| 50 | cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); | ||
| 51 | |||
| 52 | @p = Nagios::Plugin::Performance->parse_perfstring( | ||
| 53 | "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); | ||
| 54 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | ||
| 55 | cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); | ||
| 56 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | ||
| 57 | cmp_ok( $p[0]->threshold->warning, 'eq', "5", "warn okay"); | ||
| 58 | cmp_ok( $p[0]->threshold->critical, 'eq', "10", "crit okay"); | ||
| 59 | cmp_ok( $p[1]->label, "eq", "size", "label okay"); | ||
| 60 | cmp_ok( $p[1]->value, "==", 426, "value okay"); | ||
| 61 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); | ||
| 62 | ok( ! defined $p[1]->threshold->warning, "warn okay"); | ||
| 63 | ok( ! defined $p[1]->threshold->critical, "crit okay"); | ||
diff --git a/t/Nagios-Plugin-Range.t b/t/Nagios-Plugin-Range.t new file mode 100644 index 0000000..13667de --- /dev/null +++ b/t/Nagios-Plugin-Range.t | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 60; | ||
| 4 | BEGIN { use_ok('Nagios::Plugin::Range') }; | ||
| 5 | |||
| 6 | |||
| 7 | my $r = Nagios::Plugin::Range->parse_range_string("6"); | ||
| 8 | isa_ok( $r, "Nagios::Plugin::Range"); | ||
| 9 | ok( defined $r, "'6' is valid range"); | ||
| 10 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
| 11 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 12 | cmp_ok( $r->end, '==', 6, "End correct"); | ||
| 13 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 14 | cmp_ok( $r, 'eq', "6", "Stringification back to original"); | ||
| 15 | |||
| 16 | $r = Nagios::Plugin::Range->parse_range_string("-7:23"); | ||
| 17 | ok( defined $r, "'-7:23' is valid range"); | ||
| 18 | cmp_ok( $r->start, '==', -7, "Start correct"); | ||
| 19 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 20 | cmp_ok( $r->end, '==', 23, "End correct"); | ||
| 21 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 22 | cmp_ok( $r, 'eq', "-7:23", "Stringification back to original"); | ||
| 23 | |||
| 24 | $r = Nagios::Plugin::Range->parse_range_string(":5.75"); | ||
| 25 | ok( defined $r, "':5.75' is valid range"); | ||
| 26 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
| 27 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 28 | cmp_ok( $r->end, '==', 5.75, "End correct"); | ||
| 29 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 30 | cmp_ok( $r, 'eq', "5.75", "Stringification to simplification"); | ||
| 31 | |||
| 32 | $r = Nagios::Plugin::Range->parse_range_string("~:-95.99"); | ||
| 33 | ok( defined $r, "'~:-95.99' is valid range"); | ||
| 34 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | ||
| 35 | cmp_ok( $r->end, '==', -95.99, "End correct"); | ||
| 36 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 37 | cmp_ok( $r, 'eq', "~:-95.99", "Stringification back to original"); | ||
| 38 | |||
| 39 | $r = Nagios::Plugin::Range->parse_range_string("123456789012345:"); | ||
| 40 | ok( defined $r, "'123456789012345:' is valid range"); | ||
| 41 | cmp_ok( $r->start, '==', 123456789012345, "Start correct"); | ||
| 42 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 43 | cmp_ok( $r->end_infinity, '==', 1, "Using positive infinity"); | ||
| 44 | cmp_ok( $r, 'eq', "123456789012345:", "Stringification back to original"); | ||
| 45 | |||
| 46 | $r = Nagios::Plugin::Range->parse_range_string("~:0"); | ||
| 47 | ok( defined $r, "'~:0' is valid range"); | ||
| 48 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | ||
| 49 | cmp_ok( $r->end, '==', 0, "End correct"); | ||
| 50 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 51 | cmp_ok( $r->alert_on, '==', 0, "Will alert on outside of range"); | ||
| 52 | cmp_ok( $r, 'eq', "~:0", "Stringification back to original"); | ||
| 53 | ok( $r->check_range(0.5) == 1, "0.5 - alert"); | ||
| 54 | ok( $r->check_range(-10) == 0, "-10 - no alert"); | ||
| 55 | ok( $r->check_range(0) == 0, "0 - no alert"); | ||
| 56 | |||
| 57 | $r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567'); | ||
| 58 | ok( defined $r, '"@0:657.8210567" is a valid range'); | ||
| 59 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
| 60 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 61 | cmp_ok( $r->end, '==', 657.8210567, "End correct"); | ||
| 62 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 63 | cmp_ok( $r->alert_on, '==', 1, "Will alert on inside of range"); | ||
| 64 | cmp_ok( $r, 'eq', '@657.8210567', "Stringification to simplified version"); | ||
| 65 | ok( $r->check_range(32.88) == 1, "32.88 - alert"); | ||
| 66 | ok( $r->check_range(-2) == 0, "-2 - no alert"); | ||
| 67 | ok( $r->check_range(657.8210567) == 1, "657.8210567 - alert"); | ||
| 68 | ok( $r->check_range(0) == 1, "0 - alert"); | ||
| 69 | |||
| 70 | $r = Nagios::Plugin::Range->parse_range_string('1:1'); | ||
| 71 | ok( defined $r, '"1:1" is a valid range'); | ||
| 72 | cmp_ok( $r->start, '==', 1, "Start correct"); | ||
| 73 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
| 74 | cmp_ok( $r->end, '==', 1, "End correct"); | ||
| 75 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
| 76 | cmp_ok( $r, 'eq', "1:1", "Stringification to simplified version"); | ||
| 77 | ok( $r->check_range(0.5) == 1, "0.5 - alert"); | ||
| 78 | ok( $r->check_range(1) == 0, "1 - no alert"); | ||
| 79 | ok( $r->check_range(5.2) == 1, "5.2 - alert"); | ||
| 80 | |||
| 81 | $r = Nagios::Plugin::Range->parse_range_string('2:1'); | ||
| 82 | ok( ! defined $r, '"2:1" is rejected'); | ||
| 83 | |||
| 84 | # TODO: Need more tests for invalid data | ||
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t new file mode 100644 index 0000000..764f7b0 --- /dev/null +++ b/t/Nagios-Plugin-Threshold.t | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 18; | ||
| 4 | BEGIN { use_ok('Nagios::Plugin::Threshold'); use_ok('Nagios::Plugin::Base') }; | ||
| 5 | |||
| 6 | Nagios::Plugin::Base->exit_on_die(0); | ||
| 7 | Nagios::Plugin::Base->print_on_die(0); | ||
| 8 | |||
| 9 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); | ||
| 10 | ok( defined $t, "Threshold ('', '80') set"); | ||
| 11 | ok( ! defined $t->warning, "Warning not set"); | ||
| 12 | cmp_ok( $t->critical->end, '==', 80, "Critical set correctly"); | ||
| 13 | |||
| 14 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => ""); | ||
| 15 | ok( defined $t, "Threshold ('5:33', '') set"); | ||
| 16 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | ||
| 17 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | ||
| 18 | ok( ! defined $t->critical, "Critical not set"); | ||
| 19 | |||
| 20 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "30", critical => "60"); | ||
| 21 | ok( defined $t, "Threshold ('30', '60') set"); | ||
| 22 | cmp_ok( $t->warning->end, '==', 30, "Warning end set"); | ||
| 23 | cmp_ok( $t->critical->end, '==',60, "Critical end set"); | ||
| 24 | cmp_ok( $t->get_status(15.3), '==', $ERRORS{OK}, "15.3 - ok"); | ||
| 25 | cmp_ok( $t->get_status(30.0001), '==', $ERRORS{WARNING}, "30.0001 - warning"); | ||
| 26 | cmp_ok( $t->get_status(69), '==', $ERRORS{CRITICAL}, "69 - critical"); | ||
| 27 | |||
| 28 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "total", critical => "rubbish"); | ||
| 29 | ok( defined $t, "Threshold object created although ..."); | ||
| 30 | ok( ! defined $t->warning, "Warning not set"); | ||
| 31 | ok( ! defined $t->critical, "Critical not set"); | ||
| 32 | |||
diff --git a/t/Nagios-Plugin.t b/t/Nagios-Plugin.t new file mode 100644 index 0000000..38e792d --- /dev/null +++ b/t/Nagios-Plugin.t | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 5; | ||
| 4 | BEGIN { use_ok('Nagios::Plugin') }; | ||
| 5 | |||
| 6 | use Nagios::Plugin::Base; | ||
| 7 | Nagios::Plugin::Base->exit_on_die(0); | ||
| 8 | Nagios::Plugin::Base->print_on_die(0); | ||
| 9 | |||
| 10 | my $p = Nagios::Plugin->new; | ||
| 11 | isa_ok( $p, "Nagios::Plugin"); | ||
| 12 | |||
| 13 | $p->shortname("PAGESIZE"); | ||
| 14 | |||
| 15 | my $t = $p->set_thresholds( warning => "10:25", critical => "25:" ); | ||
| 16 | |||
| 17 | $p->add_perfdata( | ||
| 18 | label => "size", | ||
| 19 | value => 1, | ||
| 20 | uom => "kB", | ||
| 21 | threshold => $t, | ||
| 22 | ); | ||
| 23 | |||
| 24 | cmp_ok( $p->all_perfoutput, 'eq', "size=1kB;10:25;25:", "Perfdata correct"); | ||
| 25 | |||
| 26 | my $o = $p->die( return_code => $t->get_status(1), message => "page size at http://... was 1kB" ); | ||
| 27 | cmp_ok( $o, "eq", 'PAGESIZE CRITICAL page size at http://... was 1kB | size=1kB;10:25;25:', "Output okay"); | ||
| 28 | |||
| 29 | cmp_ok( $p->die( return_code => $t->get_status(30), message => "page size at http://... was 30kB" ), | ||
| 30 | "eq", 'PAGESIZE WARNING page size at http://... was 30kB | size=1kB;10:25;25:', "Output okay"); | ||
| 31 | |||
| 32 | |||
