diff options
Diffstat (limited to 'plugins/tests')
-rw-r--r-- | plugins/tests/.cvsignore | 3 | ||||
-rw-r--r-- | plugins/tests/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/tests/README | 5 | ||||
-rw-r--r-- | plugins/tests/check_disk | 9 | ||||
-rw-r--r-- | plugins/tests/check_dns | 9 | ||||
-rw-r--r-- | plugins/tests/check_ftp | 9 | ||||
-rw-r--r-- | plugins/tests/check_hpjd | 9 | ||||
-rw-r--r-- | plugins/tests/check_http | 9 | ||||
-rw-r--r-- | plugins/tests/check_load | 9 | ||||
-rw-r--r-- | plugins/tests/check_ping | 13 | ||||
-rw-r--r-- | plugins/tests/check_procs | 23 | ||||
-rw-r--r-- | plugins/tests/check_swap | 13 | ||||
-rw-r--r-- | plugins/tests/check_users | 9 | ||||
-rw-r--r-- | plugins/tests/check_vsz | 9 | ||||
-rw-r--r-- | plugins/tests/test_utils.c | 109 | ||||
-rwxr-xr-x | plugins/tests/test_utils.t | 6 |
16 files changed, 144 insertions, 121 deletions
diff --git a/plugins/tests/.cvsignore b/plugins/tests/.cvsignore new file mode 100644 index 00000000..95112e15 --- /dev/null +++ b/plugins/tests/.cvsignore | |||
@@ -0,0 +1,3 @@ | |||
1 | Makefile | ||
2 | Makefile.in | ||
3 | test_utils | ||
diff --git a/plugins/tests/Makefile.am b/plugins/tests/Makefile.am new file mode 100644 index 00000000..0d82be12 --- /dev/null +++ b/plugins/tests/Makefile.am | |||
@@ -0,0 +1,21 @@ | |||
1 | |||
2 | noinst_PROGRAMS = @EXTRA_TEST@ | ||
3 | |||
4 | # These two lines support "make check", but we use "make test" | ||
5 | TESTS = @EXTRA_TEST@ | ||
6 | check_PROGRAMS = @EXTRA_TEST@ | ||
7 | |||
8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl | ||
9 | |||
10 | EXTRA_PROGRAMS = test_utils | ||
11 | |||
12 | LIBS = @LIBINTL@ | ||
13 | |||
14 | test_utils_SOURCES = test_utils.c | ||
15 | test_utils_CFLAGS = -g -I.. | ||
16 | test_utils_LDFLAGS = -L.. | ||
17 | test_utils_LDADD = ../utils.o @EXTRA_TAPOBJ@ | ||
18 | |||
19 | test: ${noinst_PROGRAMS} | ||
20 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) | ||
21 | |||
diff --git a/plugins/tests/README b/plugins/tests/README new file mode 100644 index 00000000..66935e4d --- /dev/null +++ b/plugins/tests/README | |||
@@ -0,0 +1,5 @@ | |||
1 | The tests in here use the libtap library functions | ||
2 | (http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap), so are | ||
3 | more for unit testing the utils.c library functions. | ||
4 | |||
5 | However, it probably should be merged into the plugins/t subdirectory. | ||
diff --git a/plugins/tests/check_disk b/plugins/tests/check_disk deleted file mode 100644 index c4323e0b..00000000 --- a/plugins/tests/check_disk +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_disk | ||
2 | |||
3 | [normal] | ||
4 | 100 100 / | ||
5 | ^Disk ok - +[\.0-9]+ | ||
6 | |||
7 | [critical] | ||
8 | 0 0 / | ||
9 | ^Only +[\.0-9]+ | ||
diff --git a/plugins/tests/check_dns b/plugins/tests/check_dns deleted file mode 100644 index 2e9b9a09..00000000 --- a/plugins/tests/check_dns +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_dns | ||
2 | |||
3 | [normal] | ||
4 | 127.0.0.1 | ||
5 | DNS ok - +[\.0-9]+ seconds response time, Address\(es\) is\/are 127\.0\.0\.1 | ||
6 | |||
7 | [critical] | ||
8 | $nullhost | ||
9 | DNS (problem - Probably a non-existent host/domain|CRITICAL - Non-existent host/domain|CRITICAL - Connection timed out after [0-9]+ seconds) | ||
diff --git a/plugins/tests/check_ftp b/plugins/tests/check_ftp deleted file mode 100644 index 4266ebdc..00000000 --- a/plugins/tests/check_ftp +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_ftp | ||
2 | |||
3 | [normal] | ||
4 | $hostname -wt 300 -ct 600 | ||
5 | FTP ok - [0-9]+ second response time | ||
6 | |||
7 | [critical] | ||
8 | $noserver -wt 0 -ct 0 | ||
9 | (Invalid FTP response received from host|Connection refused by host) | ||
diff --git a/plugins/tests/check_hpjd b/plugins/tests/check_hpjd deleted file mode 100644 index df35996f..00000000 --- a/plugins/tests/check_hpjd +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_hpjd | ||
2 | |||
3 | [normal] | ||
4 | $printer | ||
5 | ^Printer ok - | ||
6 | |||
7 | [critical] | ||
8 | $noserver | ||
9 | Timeout: No response from ns | ||
diff --git a/plugins/tests/check_http b/plugins/tests/check_http deleted file mode 100644 index e09f6ff7..00000000 --- a/plugins/tests/check_http +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_http | ||
2 | |||
3 | [normal] | ||
4 | www.infoplease.com -wt 300 -ct 600 | ||
5 | HTTP/1.1 200 OK - [0-9]+ second response time | ||
6 | |||
7 | [critical] | ||
8 | $nullhost -wt 1 -ct 2 | ||
9 | (Connection refused by host|Network is unreachable|Connection refused or timed out|Socket timeout after [0-9]+ seconds)$ | ||
diff --git a/plugins/tests/check_load b/plugins/tests/check_load deleted file mode 100644 index 5e4be3a4..00000000 --- a/plugins/tests/check_load +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_load | ||
2 | |||
3 | [normal] | ||
4 | 100 100 100 100 100 100 | ||
5 | ^load average: +[\.0-9]+, +[\.0-9]+, +[\.0-9]+$ | ||
6 | |||
7 | [critical] | ||
8 | 0 0 0 0 0 0 | ||
9 | ^load average: +[\.0-9]+, +[\.0-9]+, +[\.0-9]+ CRITICAL$ | ||
diff --git a/plugins/tests/check_ping b/plugins/tests/check_ping deleted file mode 100644 index 115cbaa3..00000000 --- a/plugins/tests/check_ping +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | check_ping | ||
2 | |||
3 | [normal] | ||
4 | 127.0.0.1 100 100 1000 1000 -p 1 | ||
5 | PING ok - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms | ||
6 | |||
7 | [critical] | ||
8 | 127.0.0.1 0 0 0 0 -p 1 | ||
9 | Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms | ||
10 | |||
11 | [critical] | ||
12 | $nullhost 0 0 0 0 -p 1 -to 1 | ||
13 | CRITICAL - Plugin timed out after 1 seconds | ||
diff --git a/plugins/tests/check_procs b/plugins/tests/check_procs deleted file mode 100644 index f7c65222..00000000 --- a/plugins/tests/check_procs +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | check_procs | ||
2 | |||
3 | # this is a comment | ||
4 | |||
5 | [normal] | ||
6 | 100000 100000 | ||
7 | ^OK - [0-9]+ processes running$ | ||
8 | |||
9 | [normal] | ||
10 | 100000 100000 Z | ||
11 | ^OK - [0-9]+ processes with Z status$ | ||
12 | |||
13 | [warning] | ||
14 | 0 10000000 | ||
15 | ^WARNING - [0-9]+ processes running$ | ||
16 | |||
17 | [critical] | ||
18 | 0 0 | ||
19 | ^CRITICAL - [0-9]+ processes running$ | ||
20 | |||
21 | [critical] | ||
22 | 0 0 S | ||
23 | ^CRITICAL - [0-9]+ processes with S status$ | ||
diff --git a/plugins/tests/check_swap b/plugins/tests/check_swap deleted file mode 100644 index b6cbb42f..00000000 --- a/plugins/tests/check_swap +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | check_swap | ||
2 | |||
3 | [normal] | ||
4 | 100 100 | ||
5 | ^Swap ok - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$ | ||
6 | |||
7 | [critical] | ||
8 | 0 0 | ||
9 | ^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$ | ||
10 | |||
11 | [critical] | ||
12 | 100 100 1000000000 10000000000 | ||
13 | ^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$ | ||
diff --git a/plugins/tests/check_users b/plugins/tests/check_users deleted file mode 100644 index 5a7959a5..00000000 --- a/plugins/tests/check_users +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_users | ||
2 | |||
3 | [normal] | ||
4 | 1000 1000 | ||
5 | ^Users ok - +[0-9]+ users logged in$ | ||
6 | |||
7 | [critical] | ||
8 | 0 0 | ||
9 | ^[0-9]+ +users currently logged in$ | ||
diff --git a/plugins/tests/check_vsz b/plugins/tests/check_vsz deleted file mode 100644 index 4fdec936..00000000 --- a/plugins/tests/check_vsz +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | check_vsz | ||
2 | |||
3 | [normal] | ||
4 | 100000 1000000 init | ||
5 | ^ok \(all VSZ\<[0-9]+\) | ||
6 | |||
7 | [critical] | ||
8 | 0 0 | ||
9 | ^CRITICAL \(VSZ\>[0-9]+\) | ||
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c new file mode 100644 index 00000000..1fda3675 --- /dev/null +++ b/plugins/tests/test_utils.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | This program is free software; you can redistribute it and/or modify | ||
4 | it under the terms of the GNU General Public License as published by | ||
5 | the Free Software Foundation; either version 2 of the License, or | ||
6 | (at your option) any later version. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, | ||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
16 | |||
17 | $Id$ | ||
18 | |||
19 | ******************************************************************************/ | ||
20 | |||
21 | const char *progname = "utils"; | ||
22 | |||
23 | #include "common.h" | ||
24 | #include "utils.h" | ||
25 | #include "popen.h" | ||
26 | |||
27 | #include "tap.h" | ||
28 | |||
29 | int | ||
30 | main (int argc, char **argv) | ||
31 | { | ||
32 | threshold *range; | ||
33 | double temp; | ||
34 | |||
35 | plan_tests(40); | ||
36 | |||
37 | range = parse_threshold("6"); | ||
38 | ok( range != NULL, "'6' is valid threshold"); | ||
39 | ok( range->start == 0, "Start correct"); | ||
40 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
41 | ok( range->end == 6, "End correct"); | ||
42 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
43 | free(range); | ||
44 | |||
45 | range = parse_threshold("-7:23"); | ||
46 | ok( range != NULL, "'-7:23' is valid threshold"); | ||
47 | ok( range->start == -7, "Start correct"); | ||
48 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
49 | ok( range->end == 23, "End correct"); | ||
50 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
51 | free(range); | ||
52 | |||
53 | range = parse_threshold(":5.75"); | ||
54 | ok( range != NULL, "':5.75' is valid threshold"); | ||
55 | ok( range->start == 0, "Start correct"); | ||
56 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
57 | ok( range->end == 5.75, "End correct"); | ||
58 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
59 | free(range); | ||
60 | |||
61 | range = parse_threshold("~:-95.99"); | ||
62 | ok( range != NULL, "~:-95.99' is valid threshold"); | ||
63 | ok( range->start_infinity == TRUE, "Using negative infinity"); | ||
64 | ok( range->end == -95.99, "End correct (with rounding errors)"); | ||
65 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
66 | free(range); | ||
67 | |||
68 | range = parse_threshold("12345678901234567890:"); | ||
69 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ | ||
70 | ok( range != NULL, "'12345678901234567890:' is valid threshold"); | ||
71 | ok( range->start == temp, "Start correct"); | ||
72 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
73 | ok( range->end_infinity == TRUE, "Using infinity"); | ||
74 | free(range); | ||
75 | |||
76 | range = parse_threshold("~:0"); | ||
77 | ok( range != NULL, "'~:0' is valid threshold"); | ||
78 | ok( range->start_infinity == TRUE, "Using negative infinity"); | ||
79 | ok( range->end == 0, "End correct"); | ||
80 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
81 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); | ||
82 | free(range); | ||
83 | |||
84 | range = parse_threshold("@0:657.8210567"); | ||
85 | ok( range != 0, "@0:657.8210567' is a valid threshold"); | ||
86 | ok( range->start == 0, "Start correct"); | ||
87 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
88 | ok( range->end == 657.8210567, "End correct"); | ||
89 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
90 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | ||
91 | free(range); | ||
92 | |||
93 | range = parse_threshold("1:1"); | ||
94 | ok( range != NULL, "'1:1' is a valid threshold"); | ||
95 | ok( range->start == 1, "Start correct"); | ||
96 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
97 | ok( range->end == 1, "End correct"); | ||
98 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
99 | free(range); | ||
100 | |||
101 | range = parse_threshold("2:1"); | ||
102 | ok( range == NULL, "''2:1' rejected"); | ||
103 | |||
104 | return exit_status(); | ||
105 | } | ||
106 | |||
107 | void print_usage() { | ||
108 | printf("Dummy"); | ||
109 | } | ||
diff --git a/plugins/tests/test_utils.t b/plugins/tests/test_utils.t new file mode 100755 index 00000000..8686ad2a --- /dev/null +++ b/plugins/tests/test_utils.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | if (! -e "./test_utils") { | ||
4 | plan skip_all => "./test_utils not compiled - check ./configure --with-libtap-object is defined"; | ||
5 | } | ||
6 | exec "./test_utils"; | ||