From 2c6651034f76e2bccb549a867485f8fabbf07cb1 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 8 Jun 2006 12:27:44 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1419 f882894a-f735-0410-b71e-b25c423dba1c --- t/Nagios-Plugin-Performance.t | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 t/Nagios-Plugin-Performance.t (limited to 't/Nagios-Plugin-Performance.t') 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 @@ + +use strict; +use Test::More tests => 42; +BEGIN { use_ok('Nagios::Plugin::Performance') }; + +use Nagios::Plugin::Base; +Nagios::Plugin::Base->exit_on_die(0); + +my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); +cmp_ok( $p[0]->label, 'eq', "/", "label okay"); +cmp_ok( $p[0]->value, '==', 382, "value okay"); +cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); +cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); +cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); +ok( ! defined $p[0]->min, "min okay"); +ok( ! defined $p[0]->max, "max okay"); + +cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); +cmp_ok( $p[1]->value, '==', 218, "value okay"); +cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); +cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); +cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); + +ok( ! defined Nagios::Plugin::Performance->parse_perfstring("rubbish"), "Errors correctly"); +ok( ! defined Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); + +@p = Nagios::Plugin::Performance->parse_perfstring( + "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); +cmp_ok( $p[0]->label, "eq", "time", "label okay"); +cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); +cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); +cmp_ok( $p[0]->threshold->warning, "eq", "0", "warn okay"); +cmp_ok( $p[0]->threshold->critical, "eq", "0", "crit okay"); + +@p = Nagios::Plugin::Performance->parse_perfstring( + "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); +cmp_ok( $p[0]->label, "eq", "load1", "label okay"); +cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); +cmp_ok( $p[0]->uom, "eq", "", "uom empty"); +cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); +cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); +cmp_ok( $p[1]->label, "eq", "load5", "label okay"); +cmp_ok( $p[2]->label, "eq", "load15", "label okay"); + +@p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); +cmp_ok( $p[0]->label, "eq", "users", "label okay"); +cmp_ok( $p[0]->value, "==", 4, "value okay"); +cmp_ok( $p[0]->uom, "eq", "", "uom empty"); +cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); +cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); + +@p = Nagios::Plugin::Performance->parse_perfstring( + "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); +cmp_ok( $p[0]->label, "eq", "time", "label okay"); +cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); +cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); +cmp_ok( $p[0]->threshold->warning, 'eq', "5", "warn okay"); +cmp_ok( $p[0]->threshold->critical, 'eq', "10", "crit okay"); +cmp_ok( $p[1]->label, "eq", "size", "label okay"); +cmp_ok( $p[1]->value, "==", 426, "value okay"); +cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); + ok( ! defined $p[1]->threshold->warning, "warn okay"); + ok( ! defined $p[1]->threshold->critical, "crit okay"); -- cgit v1.2.3-74-g34f1