summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-06-08 12:27:44 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-06-08 12:27:44 (GMT)
commit2c6651034f76e2bccb549a867485f8fabbf07cb1 (patch)
tree8de53d7efe4564017e1ebce73353c7e3a3c8b548 /t
parent83e29d795dddf34a652cda8665179b77372ddcfe (diff)
downloadmonitoring-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.t63
-rw-r--r--t/Nagios-Plugin-Range.t84
-rw-r--r--t/Nagios-Plugin-Threshold.t32
-rw-r--r--t/Nagios-Plugin.t32
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
2use strict;
3use Test::More tests => 42;
4BEGIN { use_ok('Nagios::Plugin::Performance') };
5
6use Nagios::Plugin::Base;
7Nagios::Plugin::Base->exit_on_die(0);
8
9my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
10cmp_ok( $p[0]->label, 'eq', "/", "label okay");
11cmp_ok( $p[0]->value, '==', 382, "value okay");
12cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay");
13cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay");
14cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay");
15ok( ! defined $p[0]->min, "min okay");
16ok( ! defined $p[0]->max, "max okay");
17
18cmp_ok( $p[1]->label, 'eq', "/var", "label okay");
19cmp_ok( $p[1]->value, '==', 218, "value okay");
20cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay");
21cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay");
22cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay");
23
24ok( ! defined Nagios::Plugin::Performance->parse_perfstring("rubbish"), "Errors correctly");
25ok( ! 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");
29cmp_ok( $p[0]->label, "eq", "time", "label okay");
30cmp_ok( $p[0]->value, "==", 0.001229, "value okay");
31cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
32cmp_ok( $p[0]->threshold->warning, "eq", "0", "warn okay");
33cmp_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;");
37cmp_ok( $p[0]->label, "eq", "load1", "label okay");
38cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string");
39cmp_ok( $p[0]->uom, "eq", "", "uom empty");
40cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay");
41cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay");
42cmp_ok( $p[1]->label, "eq", "load5", "label okay");
43cmp_ok( $p[2]->label, "eq", "load15", "label okay");
44
45@p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" );
46cmp_ok( $p[0]->label, "eq", "users", "label okay");
47cmp_ok( $p[0]->value, "==", 4, "value okay");
48cmp_ok( $p[0]->uom, "eq", "", "uom empty");
49cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay");
50cmp_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" );
54cmp_ok( $p[0]->label, "eq", "time", "label okay");
55cmp_ok( $p[0]->value, "eq", "0.2153", "value okay");
56cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
57cmp_ok( $p[0]->threshold->warning, 'eq', "5", "warn okay");
58cmp_ok( $p[0]->threshold->critical, 'eq', "10", "crit okay");
59cmp_ok( $p[1]->label, "eq", "size", "label okay");
60cmp_ok( $p[1]->value, "==", 426, "value okay");
61cmp_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
2use strict;
3use Test::More tests => 60;
4BEGIN { use_ok('Nagios::Plugin::Range') };
5
6
7my $r = Nagios::Plugin::Range->parse_range_string("6");
8isa_ok( $r, "Nagios::Plugin::Range");
9ok( defined $r, "'6' is valid range");
10cmp_ok( $r->start, '==', 0, "Start correct");
11cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
12cmp_ok( $r->end, '==', 6, "End correct");
13cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
14cmp_ok( $r, 'eq', "6", "Stringification back to original");
15
16$r = Nagios::Plugin::Range->parse_range_string("-7:23");
17ok( defined $r, "'-7:23' is valid range");
18cmp_ok( $r->start, '==', -7, "Start correct");
19cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
20cmp_ok( $r->end, '==', 23, "End correct");
21cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
22cmp_ok( $r, 'eq', "-7:23", "Stringification back to original");
23
24$r = Nagios::Plugin::Range->parse_range_string(":5.75");
25ok( defined $r, "':5.75' is valid range");
26cmp_ok( $r->start, '==', 0, "Start correct");
27cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
28cmp_ok( $r->end, '==', 5.75, "End correct");
29cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
30cmp_ok( $r, 'eq', "5.75", "Stringification to simplification");
31
32$r = Nagios::Plugin::Range->parse_range_string("~:-95.99");
33ok( defined $r, "'~:-95.99' is valid range");
34cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
35cmp_ok( $r->end, '==', -95.99, "End correct");
36cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
37cmp_ok( $r, 'eq', "~:-95.99", "Stringification back to original");
38
39$r = Nagios::Plugin::Range->parse_range_string("123456789012345:");
40ok( defined $r, "'123456789012345:' is valid range");
41cmp_ok( $r->start, '==', 123456789012345, "Start correct");
42cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
43cmp_ok( $r->end_infinity, '==', 1, "Using positive infinity");
44cmp_ok( $r, 'eq', "123456789012345:", "Stringification back to original");
45
46$r = Nagios::Plugin::Range->parse_range_string("~:0");
47ok( defined $r, "'~:0' is valid range");
48cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
49cmp_ok( $r->end, '==', 0, "End correct");
50cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
51cmp_ok( $r->alert_on, '==', 0, "Will alert on outside of range");
52cmp_ok( $r, 'eq', "~:0", "Stringification back to original");
53ok( $r->check_range(0.5) == 1, "0.5 - alert");
54ok( $r->check_range(-10) == 0, "-10 - no alert");
55ok( $r->check_range(0) == 0, "0 - no alert");
56
57$r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567');
58ok( defined $r, '"@0:657.8210567" is a valid range');
59cmp_ok( $r->start, '==', 0, "Start correct");
60cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
61cmp_ok( $r->end, '==', 657.8210567, "End correct");
62cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
63cmp_ok( $r->alert_on, '==', 1, "Will alert on inside of range");
64cmp_ok( $r, 'eq', '@657.8210567', "Stringification to simplified version");
65ok( $r->check_range(32.88) == 1, "32.88 - alert");
66ok( $r->check_range(-2) == 0, "-2 - no alert");
67ok( $r->check_range(657.8210567) == 1, "657.8210567 - alert");
68ok( $r->check_range(0) == 1, "0 - alert");
69
70$r = Nagios::Plugin::Range->parse_range_string('1:1');
71ok( defined $r, '"1:1" is a valid range');
72cmp_ok( $r->start, '==', 1, "Start correct");
73cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
74cmp_ok( $r->end, '==', 1, "End correct");
75cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
76cmp_ok( $r, 'eq', "1:1", "Stringification to simplified version");
77ok( $r->check_range(0.5) == 1, "0.5 - alert");
78ok( $r->check_range(1) == 0, "1 - no alert");
79ok( $r->check_range(5.2) == 1, "5.2 - alert");
80
81$r = Nagios::Plugin::Range->parse_range_string('2:1');
82ok( ! 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
2use strict;
3use Test::More tests => 18;
4BEGIN { use_ok('Nagios::Plugin::Threshold'); use_ok('Nagios::Plugin::Base') };
5
6Nagios::Plugin::Base->exit_on_die(0);
7Nagios::Plugin::Base->print_on_die(0);
8
9my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80");
10ok( defined $t, "Threshold ('', '80') set");
11ok( ! defined $t->warning, "Warning not set");
12cmp_ok( $t->critical->end, '==', 80, "Critical set correctly");
13
14$t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "");
15ok( defined $t, "Threshold ('5:33', '') set");
16cmp_ok( $t->warning->start, '==', 5, "Warning start set");
17cmp_ok( $t->warning->end, '==', 33, "Warning end set");
18ok( ! defined $t->critical, "Critical not set");
19
20$t = Nagios::Plugin::Threshold->set_thresholds(warning => "30", critical => "60");
21ok( defined $t, "Threshold ('30', '60') set");
22cmp_ok( $t->warning->end, '==', 30, "Warning end set");
23cmp_ok( $t->critical->end, '==',60, "Critical end set");
24cmp_ok( $t->get_status(15.3), '==', $ERRORS{OK}, "15.3 - ok");
25cmp_ok( $t->get_status(30.0001), '==', $ERRORS{WARNING}, "30.0001 - warning");
26cmp_ok( $t->get_status(69), '==', $ERRORS{CRITICAL}, "69 - critical");
27
28$t = Nagios::Plugin::Threshold->set_thresholds(warning => "total", critical => "rubbish");
29ok( defined $t, "Threshold object created although ...");
30ok( ! defined $t->warning, "Warning not set");
31ok( ! 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
2use strict;
3use Test::More tests => 5;
4BEGIN { use_ok('Nagios::Plugin') };
5
6use Nagios::Plugin::Base;
7Nagios::Plugin::Base->exit_on_die(0);
8Nagios::Plugin::Base->print_on_die(0);
9
10my $p = Nagios::Plugin->new;
11isa_ok( $p, "Nagios::Plugin");
12
13$p->shortname("PAGESIZE");
14
15my $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
24cmp_ok( $p->all_perfoutput, 'eq', "size=1kB;10:25;25:", "Perfdata correct");
25
26my $o = $p->die( return_code => $t->get_status(1), message => "page size at http://... was 1kB" );
27cmp_ok( $o, "eq", 'PAGESIZE CRITICAL page size at http://... was 1kB | size=1kB;10:25;25:', "Output okay");
28
29cmp_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