diff options
Diffstat (limited to 't/Nagios-Plugin-Performance.t')
| -rw-r--r-- | t/Nagios-Plugin-Performance.t | 63 | 
1 files changed, 63 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"); | ||
