diff options
-rw-r--r-- | Helper.pm | 44 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | NPTest.pm | 554 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | plugins-scripts/t/check_rpc.t | 23 | ||||
-rw-r--r-- | plugins/t/check_disk.t | 44 | ||||
-rw-r--r-- | plugins/t/check_dns.t | 44 | ||||
-rw-r--r-- | plugins/t/check_fping.t | 48 | ||||
-rw-r--r-- | plugins/t/check_ftp.t | 44 | ||||
-rw-r--r-- | plugins/t/check_hpjd.t | 50 | ||||
-rw-r--r-- | plugins/t/check_http.t | 36 | ||||
-rw-r--r-- | plugins/t/check_imap.t | 51 | ||||
-rw-r--r-- | plugins/t/check_load.t | 30 | ||||
-rw-r--r-- | plugins/t/check_mysql.t | 33 | ||||
-rw-r--r-- | plugins/t/check_ping.t | 47 | ||||
-rw-r--r-- | plugins/t/check_pop.t | 47 | ||||
-rw-r--r-- | plugins/t/check_procs.t | 53 | ||||
-rw-r--r-- | plugins/t/check_smtp.t | 43 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 91 | ||||
-rw-r--r-- | plugins/t/check_swap.t | 35 | ||||
-rw-r--r-- | plugins/t/check_tcp.t | 41 | ||||
-rw-r--r-- | plugins/t/check_time.t | 60 | ||||
-rw-r--r-- | plugins/t/check_udp.t | 37 | ||||
-rw-r--r-- | plugins/t/check_users.t | 31 | ||||
-rw-r--r-- | plugins/t/check_vsz.t | 28 | ||||
-rwxr-xr-x | test.pl.in | 116 |
26 files changed, 1060 insertions, 574 deletions
diff --git a/Helper.pm b/Helper.pm deleted file mode 100644 index 198a6480..00000000 --- a/Helper.pm +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | package Helper; | ||
2 | use strict; | ||
3 | |||
4 | use Exporter(); | ||
5 | use vars qw($VERSION @ISA @EXPORT); | ||
6 | $VERSION = 0.01; | ||
7 | @ISA=qw(Exporter); | ||
8 | @EXPORT=qw(&get_option); | ||
9 | |||
10 | sub get_option ($$) { | ||
11 | my $file = 'Cache'; | ||
12 | my $response; | ||
13 | my $var = shift; | ||
14 | |||
15 | require "$file.pm"; | ||
16 | if(defined($Cache::{$var})){ | ||
17 | $response=$Cache::{$var}; | ||
18 | return $$response; | ||
19 | } | ||
20 | |||
21 | my $request = shift; | ||
22 | my $filename; | ||
23 | my $path; | ||
24 | foreach $path (@INC) { | ||
25 | $filename="$path/$file.pm"; | ||
26 | last if (-e $filename); | ||
27 | } | ||
28 | print STDERR "Enter $request\n"; | ||
29 | $response=<STDIN>; | ||
30 | chop($response); | ||
31 | open(CACHE,"<$filename") or die "Cannot open cache for reading"; | ||
32 | undef $/; | ||
33 | my $cache = <CACHE>; | ||
34 | $/="\n"; | ||
35 | close CACHE; | ||
36 | $cache =~ s/^(\@EXPORT\s*=\s*qw\(\s*[^\)]*)\)\s*;/$1 $var\)\;/msg; | ||
37 | $cache =~ s/^1;[\n\s]*\Z/\$$var=\"$response\"\;\n1\;\n/msg; | ||
38 | open(CACHE,">$filename") or die "Cannot open cache for writing"; | ||
39 | print CACHE $cache; | ||
40 | close CACHE; | ||
41 | return $response; | ||
42 | } | ||
43 | |||
44 | 1; | ||
diff --git a/Makefile.am b/Makefile.am index ca570e37..a7c5ffc6 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -5,7 +5,7 @@ SUBDIRS = intl lib plugins plugins-scripts m4 po | |||
5 | EXTRA_DIST = config.rpath \ | 5 | EXTRA_DIST = config.rpath \ |
6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ | 6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ |
7 | REQUIREMENTS SUPPORT THANKS \ | 7 | REQUIREMENTS SUPPORT THANKS \ |
8 | Helper.pm contrib pkg nagios-plugins.spec | 8 | NPTest.pm contrib pkg nagios-plugins.spec |
9 | 9 | ||
10 | ACLOCAL_AMFLAGS = -I m4 | 10 | ACLOCAL_AMFLAGS = -I m4 |
11 | 11 | ||
diff --git a/NPTest.pm b/NPTest.pm new file mode 100644 index 00000000..f3c874b8 --- /dev/null +++ b/NPTest.pm | |||
@@ -0,0 +1,554 @@ | |||
1 | package NPTest; | ||
2 | |||
3 | # | ||
4 | # Helper Functions for testing Nagios Plugins | ||
5 | # | ||
6 | |||
7 | require Exporter; | ||
8 | @ISA = qw(Exporter); | ||
9 | @EXPORT = qw(getTestParameter checkCmd skipMissingCmd); | ||
10 | @EXPORT_OK = qw(DetermineTestHarnessDirectory TestsFrom SetCacheFilename); | ||
11 | |||
12 | use strict; | ||
13 | use warnings; | ||
14 | |||
15 | use Cwd; | ||
16 | use File::Basename; | ||
17 | |||
18 | use IO::File; | ||
19 | use Data::Dumper; | ||
20 | |||
21 | use Test; | ||
22 | |||
23 | use vars qw($VERSION); | ||
24 | $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker | ||
25 | |||
26 | =head1 NAME | ||
27 | |||
28 | NPTest - Simplify the testing of Nagios Plugins | ||
29 | |||
30 | =head1 DESCRIPTION | ||
31 | |||
32 | This modules provides convenience functions to assist in the testing | ||
33 | of Nagios Plugins, making the testing code easier to read and write; | ||
34 | hopefully encouraging the development of more complete test suite for | ||
35 | the Nagios Plugins. It is based on the patterns of testing seen in the | ||
36 | 1.4.0 release, and continues to use the L<Test> module as the basis of | ||
37 | testing. | ||
38 | |||
39 | =head1 FUNCTIONS | ||
40 | |||
41 | This module defines three public functions, C<getTestParameter(...)>, | ||
42 | C<checkCmd(...)> and C<skipMissingCmd(...)>. These are exported by | ||
43 | default via the C<use NPTest;> statement. | ||
44 | |||
45 | =over | ||
46 | |||
47 | =item C<getTestParameter(...)> | ||
48 | |||
49 | A flexible and user override-able method of collecting, storing and | ||
50 | retrieving test parameters. This function allows the test harness | ||
51 | developer to interactively request test parameter information from the | ||
52 | user, when the no means of obtaining the information automatically has | ||
53 | been successful. The user is provided with the option of accepting | ||
54 | test harness developer's default value for the parameter, if a suggested | ||
55 | default is provided. | ||
56 | |||
57 | User supplied responses are stored in an external (file-based) | ||
58 | cache. These values are retrieved on subsequent runs alleviating the | ||
59 | user of reconfirming the previous entered responses. The user is able | ||
60 | to override the value of a parameter on any given run by setting the | ||
61 | associated environment variable. These environment variable based | ||
62 | overrides are not stored in the cache, allowing one-time and what-if | ||
63 | based tests on the command line without polluting the cache. | ||
64 | |||
65 | The option exists to store parameters in a scoped means, allowing a | ||
66 | test harness to a localise a parameter should the need arise. This | ||
67 | allows a parameter of the same name to exist in a test harness | ||
68 | specific scope, while not affecting the globally scoped parameter. The | ||
69 | scoping identifier is the name of the test harness sans the trailing | ||
70 | ".t". All cache searches first look to a scoped parameter before | ||
71 | looking for the parameter at global scope. Thus for a test harness | ||
72 | called "check_disk.t" requesting the parameter "mountpoint_valid", the | ||
73 | cache is first searched for "check_disk"/"mountpoint_valid", if this | ||
74 | fails, then a search is conducted for "mountpoint_valid". | ||
75 | |||
76 | The facilitate quick testing setup, it is possible to accept all the | ||
77 | developer provided defaults by setting the environment variable | ||
78 | "NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note | ||
79 | that, such defaults are not stored in the cache, as there is currently | ||
80 | no mechanism to edit existing cache entries, save the use of text | ||
81 | editor or removing the cache file completely. | ||
82 | |||
83 | =item C<checkCmd(...)> | ||
84 | |||
85 | This function attempts to encompass the majority of test styles used | ||
86 | in testing Nagios Plugins. As each plug-in is a separate command, the | ||
87 | typical tests we wish to perform are against the exit status of the | ||
88 | command and the output (if any) it generated. Simplifying these tests | ||
89 | into a single function call, makes the test harness easier to read and | ||
90 | maintain and allows additional functionality (such as debugging) to be | ||
91 | provided withoutadditional effort on the part of the test harness | ||
92 | developer. | ||
93 | |||
94 | It is possible to enable debugging via the environment variable | ||
95 | C<NPTEST_DEBUG>. If this environment variable exists and its value in PERL's | ||
96 | boolean context evaluates to true, debugging is enabled. | ||
97 | |||
98 | The function prototype can be expressed as follows: | ||
99 | |||
100 | Parameter 1 : command => DEFINED SCALAR(string) | ||
101 | Parameter 2 : desiredExitStatus => ONE OF | ||
102 | SCALAR(integer) | ||
103 | ARRAYREF(integer) | ||
104 | HASHREF(integer,string) | ||
105 | UNDEFINED | ||
106 | Parameter 3 : desiredOutput => SCALAR(string) OR UNDEFINED | ||
107 | Parameter 4 : exceptions => HASH(integer,string) OR UNDEFINED | ||
108 | Returns : SCALAR(integer) as defined by Test::ok(...) | ||
109 | |||
110 | The function treats the first parameter C<$command> as a command line | ||
111 | to execute as part of the test, it is executed only once and its exit | ||
112 | status (C<$?E<gt>E<gt>8>) and output are captured. | ||
113 | |||
114 | At this point if debugging is enabled the command, its exit status and | ||
115 | output are displayed to the tester. | ||
116 | |||
117 | C<checkCmd(...)> allows the testing of either the exit status or the | ||
118 | generated output or both, not testing either will result in neither | ||
119 | the C<Test::ok(...)> or C<Test::skip(...)> functions being called, | ||
120 | something you probably don't want. Note that each defined test | ||
121 | (C<$desiredExitStatus> and C<$desiredOutput>) results in a invocation | ||
122 | of either C<Test::ok(...)> or C<Test::skip(...)>, so remember this | ||
123 | when counting the number of tests to place in the C<Test::plan(...)> | ||
124 | call. | ||
125 | |||
126 | Many Nagios Plugins test network services, some of which may not be | ||
127 | present on all systems. To cater for this, C<checkCmd(...)> allows the | ||
128 | tester to define exceptions based on the command's exit status. These | ||
129 | exceptions are provided to skip tests if the test case developer | ||
130 | believes the service is not being provided. For example, if a site | ||
131 | does not have a POP3 server, the test harness could map the | ||
132 | appropriate exit status to a useful message the person running the | ||
133 | tests, telling the reason the test is being skipped. | ||
134 | |||
135 | Example: | ||
136 | |||
137 | my %exceptions = ( 2 =E<gt> "No POP Server present?" ); | ||
138 | |||
139 | $t += checkCmd( "./check_pop I<some args>", 0, undef, %exceptions ); | ||
140 | |||
141 | Thus, in the above example, an exit status of 2 does not result in a | ||
142 | failed test case (as the exit status is not the desired value of 0), | ||
143 | but a skipped test case with the message "No POP Server present?" | ||
144 | given as the reason. | ||
145 | |||
146 | Sometimes the exit status of a command should be tested against a set | ||
147 | of possible values, rather than a single value, this could especially | ||
148 | be the case in failure testing. C<checkCmd(...)> support two methods | ||
149 | of testing against a set of desired exit status values. | ||
150 | |||
151 | =over | ||
152 | |||
153 | =item * | ||
154 | |||
155 | Firstly, if C<$desiredExitStatus> is a reference to an array of exit | ||
156 | stati, if the actual exit status of the command is present in the | ||
157 | array, it is used in the call to C<Test::ok(...)> when testing the | ||
158 | exit status. | ||
159 | |||
160 | =item * | ||
161 | |||
162 | Alternatively, if C<$desiredExitStatus> is a reference to a hash of | ||
163 | exit stati (mapped to the strings "continue" or "skip"), similar | ||
164 | processing to the above occurs with the side affect of determining if | ||
165 | any generated output testing should proceed. Note: only the string | ||
166 | "skip" will result in generated output testing being skipped. | ||
167 | |||
168 | =back | ||
169 | |||
170 | =item C<skipMissingCmd(...)> | ||
171 | |||
172 | If a command is missing and the test harness must C<Test::skip()> some | ||
173 | or all of the tests in a given test harness this function provides a | ||
174 | simple iterator to issue an appropriate message the requested number | ||
175 | of times. | ||
176 | |||
177 | =back | ||
178 | |||
179 | =head1 SEE ALSO | ||
180 | |||
181 | L<Test> | ||
182 | |||
183 | The rest of the code, as I have only commented on the major public | ||
184 | functions that test harness writers will use, not all the code present | ||
185 | in this helper module. | ||
186 | |||
187 | =head1 AUTHOR | ||
188 | |||
189 | Copyright (c) 2005 Peter Bray. All rights reserved. | ||
190 | |||
191 | This package is free software and is provided "as is" without express | ||
192 | or implied warranty. It may be used, redistributed and/or modified | ||
193 | under the same terms as the Nagios Plugins release. | ||
194 | |||
195 | =cut | ||
196 | |||
197 | # | ||
198 | # Package Scope Variables | ||
199 | # | ||
200 | |||
201 | my( %CACHE ) = (); | ||
202 | |||
203 | # I'm not really sure wether to house a site-specific cache inside | ||
204 | # or outside of the extracted source / build tree - lets default to outside | ||
205 | my( $CACHEFILENAME ) = ( exists( $ENV{'NPTESTCACHE'} ) && $ENV{'NPTESTCACHE'} ) | ||
206 | ? $ENV{'NPTESTCACHE'} : "/var/tmp/NPTest.cache"; # "../Cache.pdd"; | ||
207 | |||
208 | # | ||
209 | # Testing Functions | ||
210 | # | ||
211 | |||
212 | sub checkCmd | ||
213 | { | ||
214 | my( $command, $desiredExitStatus, $desiredOutput, %exceptions ) = @_; | ||
215 | |||
216 | my $output = `${command}`; | ||
217 | my $exitStatus = $? >> 8; | ||
218 | |||
219 | $output = "" unless defined( $output ); | ||
220 | chomp( $output ); | ||
221 | |||
222 | if ( exists( $ENV{'NPTEST_DEBUG'} ) && $ENV{'NPTEST_DEBUG'} ) | ||
223 | { | ||
224 | my( $pkg, $file, $line ) = caller(0); | ||
225 | |||
226 | print "checkCmd: Called from line $line in $file\n"; | ||
227 | print "Testing : ${command}\n"; | ||
228 | print "Result : ${exitStatus} AND '${output}'\n"; | ||
229 | } | ||
230 | |||
231 | my $testStatus; | ||
232 | |||
233 | my $testOutput = "continue"; | ||
234 | |||
235 | if ( defined( $desiredExitStatus ) ) | ||
236 | { | ||
237 | if ( ref $desiredExitStatus eq "ARRAY" ) | ||
238 | { | ||
239 | if ( scalar( grep { $_ == $exitStatus } @{$desiredExitStatus} ) ) | ||
240 | { | ||
241 | $desiredExitStatus = $exitStatus; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | $desiredExitStatus = -1; | ||
246 | } | ||
247 | } | ||
248 | elsif ( ref $desiredExitStatus eq "HASH" ) | ||
249 | { | ||
250 | if ( exists( ${$desiredExitStatus}{$exitStatus} ) ) | ||
251 | { | ||
252 | if ( defined( ${$desiredExitStatus}{$exitStatus} ) ) | ||
253 | { | ||
254 | $testOutput = ${$desiredExitStatus}{$exitStatus}; | ||
255 | } | ||
256 | $desiredExitStatus = $exitStatus; | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | $desiredExitStatus = -1; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | if ( %exceptions && exists( $exceptions{$exitStatus} ) ) | ||
265 | { | ||
266 | $testStatus += skip( $exceptions{$exitStatus}, $exitStatus, $desiredExitStatus ); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | $testStatus += ok( $exitStatus, $desiredExitStatus ); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | if ( defined( $desiredOutput ) ) | ||
275 | { | ||
276 | if ( $testOutput ne "skip" ) | ||
277 | { | ||
278 | $testStatus += ok( $output, $desiredOutput ); | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | $testStatus += skip( "Skipping output test as requested", $output, $desiredOutput ); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | return $testStatus; | ||
287 | } | ||
288 | |||
289 | |||
290 | sub skipMissingCmd | ||
291 | { | ||
292 | my( $command, $count ) = @_; | ||
293 | |||
294 | my $testStatus; | ||
295 | |||
296 | for ( 1 .. $count ) | ||
297 | { | ||
298 | $testStatus += skip( "Missing ${command} - tests skipped", 1 ); | ||
299 | } | ||
300 | |||
301 | return $testStatus; | ||
302 | } | ||
303 | |||
304 | sub getTestParameter | ||
305 | { | ||
306 | my( $param, $envvar, $default, $brief, $scoped ) = @_; | ||
307 | |||
308 | # Apply default values for optional arguments | ||
309 | $scoped = ( defined( $scoped ) && $scoped ); | ||
310 | |||
311 | my $testharness = basename( (caller(0))[1], ".t" ); # used for scoping | ||
312 | |||
313 | if ( defined( $envvar ) && exists( $ENV{$envvar} ) && $ENV{$envvar} ) | ||
314 | { | ||
315 | return $ENV{$envvar} | ||
316 | } | ||
317 | |||
318 | my $cachedValue = SearchCache( $param, $testharness ); | ||
319 | if ( defined( $cachedValue ) && $cachedValue ) | ||
320 | { | ||
321 | return $cachedValue; | ||
322 | } | ||
323 | |||
324 | my $defaultValid = ( defined( $default ) && $default ); | ||
325 | my $autoAcceptDefault = ( exists( $ENV{'NPTEST_ACCEPTDEFAULT'} ) && $ENV{'NPTEST_ACCEPTDEFAULT'} ); | ||
326 | |||
327 | if ( $autoAcceptDefault && $defaultValid ) | ||
328 | { | ||
329 | return $default; | ||
330 | } | ||
331 | |||
332 | my $userResponse = ""; | ||
333 | |||
334 | while ( $userResponse eq "" ) | ||
335 | { | ||
336 | print STDERR "\n"; | ||
337 | print STDERR "Test Harness : $testharness\n"; | ||
338 | print STDERR "Test Parameter : $param\n"; | ||
339 | print STDERR "Environment Variable : $envvar\n"; | ||
340 | print STDERR "Brief Description : $brief\n"; | ||
341 | print STDERR "Enter value ", ($defaultValid ? "[${default}]" : "[]"), " => "; | ||
342 | $userResponse = <STDIN>; | ||
343 | $userResponse = "" if ! defined( $userResponse ); # Handle EOF | ||
344 | chomp( $userResponse ); | ||
345 | if ( $defaultValid && $userResponse eq "" ) | ||
346 | { | ||
347 | $userResponse = $default; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | print STDERR "\n"; | ||
352 | |||
353 | # define all user responses at global scope | ||
354 | SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse ); | ||
355 | |||
356 | return $userResponse; | ||
357 | } | ||
358 | |||
359 | # | ||
360 | # Internal Cache Management Functions | ||
361 | # | ||
362 | |||
363 | sub SearchCache | ||
364 | { | ||
365 | my( $param, $scope ) = @_; | ||
366 | |||
367 | LoadCache(); | ||
368 | |||
369 | if ( exists( $CACHE{$scope} ) && exists( $CACHE{$scope}{$param} ) ) | ||
370 | { | ||
371 | return $CACHE{$scope}{$param}; | ||
372 | } | ||
373 | |||
374 | if ( exists( $CACHE{$param} ) ) | ||
375 | { | ||
376 | return $CACHE{$param}; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | sub SetCacheParameter | ||
381 | { | ||
382 | my( $param, $scope, $value ) = @_; | ||
383 | |||
384 | if ( defined( $scope ) ) | ||
385 | { | ||
386 | $CACHE{$scope}{$param} = $value; | ||
387 | } | ||
388 | else | ||
389 | { | ||
390 | $CACHE{$param} = $value; | ||
391 | } | ||
392 | |||
393 | SaveCache(); | ||
394 | } | ||
395 | |||
396 | sub LoadCache | ||
397 | { | ||
398 | return if exists( $CACHE{'_cache_loaded_'} ); | ||
399 | |||
400 | if ( -f $CACHEFILENAME ) | ||
401 | { | ||
402 | my( $fileHandle ) = new IO::File; | ||
403 | |||
404 | if ( ! $fileHandle->open( "< ${CACHEFILENAME}" ) ) | ||
405 | { | ||
406 | print STDERR "NPTest::LoadCache() : Problem opening ${CACHEFILENAME} : $!\n"; | ||
407 | return; | ||
408 | } | ||
409 | |||
410 | my( $fileContents ) = join( "\n", <$fileHandle> ); | ||
411 | |||
412 | $fileHandle->close(); | ||
413 | |||
414 | my( $contentsRef ) = eval $fileContents; | ||
415 | %CACHE = %{$contentsRef}; | ||
416 | |||
417 | } | ||
418 | |||
419 | $CACHE{'_cache_loaded_'} = 1; | ||
420 | } | ||
421 | |||
422 | |||
423 | sub SaveCache | ||
424 | { | ||
425 | delete $CACHE{'_cache_loaded_'}; | ||
426 | |||
427 | my( $fileHandle ) = new IO::File; | ||
428 | |||
429 | if ( ! $fileHandle->open( "> ${CACHEFILENAME}" ) ) | ||
430 | { | ||
431 | print STDERR "NPTest::LoadCache() : Problem saving ${CACHEFILENAME} : $!\n"; | ||
432 | return; | ||
433 | } | ||
434 | |||
435 | my( $dataDumper ) = new Data::Dumper( [ \%CACHE ] ); | ||
436 | |||
437 | $dataDumper->Terse(1); | ||
438 | |||
439 | print $fileHandle $dataDumper->Dump(); | ||
440 | |||
441 | $fileHandle->close(); | ||
442 | |||
443 | $CACHE{'_cache_loaded_'} = 1; | ||
444 | } | ||
445 | |||
446 | # | ||
447 | # (Questionable) Public Cache Management Functions | ||
448 | # | ||
449 | |||
450 | sub SetCacheFilename | ||
451 | { | ||
452 | my( $filename ) = @_; | ||
453 | |||
454 | # Unfortunately we can not validate the filename | ||
455 | # in any meaningful way, as it may not yet exist | ||
456 | $CACHEFILENAME = $filename; | ||
457 | } | ||
458 | |||
459 | |||
460 | # | ||
461 | # Test Harness Wrapper Functions | ||
462 | # | ||
463 | |||
464 | sub DetermineTestHarnessDirectory | ||
465 | { | ||
466 | my( $userSupplied ) = @_; | ||
467 | |||
468 | # User Supplied | ||
469 | if ( defined( $userSupplied ) && $userSupplied ) | ||
470 | { | ||
471 | if ( -d $userSupplied ) | ||
472 | { | ||
473 | return $userSupplied; | ||
474 | } | ||
475 | else | ||
476 | { | ||
477 | return undef; # userSupplied is invalid -> FAIL | ||
478 | } | ||
479 | } | ||
480 | |||
481 | # Simple Case : "t" is a subdirectory of the current directory | ||
482 | if ( -d "./t" ) | ||
483 | { | ||
484 | return "./t"; | ||
485 | } | ||
486 | |||
487 | # To be honest I don't understand which case satisfies the | ||
488 | # original code in test.pl : when $tstdir == `pwd` w.r.t. | ||
489 | # $tstdir =~ s|^(.*)/([^/]+)/?$|$1/$2|; and if (-d "../../$2/t") | ||
490 | # Assuming pwd is "/a/b/c/d/e" then we are testing for "/a/b/c/e/t" | ||
491 | # if I understand the code correctly (a big assumption) | ||
492 | |||
493 | # Simple Case : the current directory is "t" | ||
494 | my $pwd = cwd(); | ||
495 | |||
496 | if ( $pwd =~ m|/t$| ) | ||
497 | { | ||
498 | return $pwd; | ||
499 | |||
500 | # The alternate that might work better is | ||
501 | # chdir( ".." ); | ||
502 | # return "./t"; | ||
503 | # As the current test harnesses assume the application | ||
504 | # to be tested is in the current directory (ie "./check_disk ....") | ||
505 | } | ||
506 | |||
507 | return undef; | ||
508 | } | ||
509 | |||
510 | sub TestsFrom | ||
511 | { | ||
512 | my( $directory, $excludeIfAppMissing ) = @_; | ||
513 | |||
514 | $excludeIfAppMissing = 0 unless defined( $excludeIfAppMissing ); | ||
515 | |||
516 | if ( ! opendir( DIR, $directory ) ) | ||
517 | { | ||
518 | print STDERR "NPTest::TestsFrom() - Failed to open ${directory} : $!\n"; | ||
519 | return (); | ||
520 | } | ||
521 | |||
522 | my( @tests ) = (); | ||
523 | |||
524 | my $filename; | ||
525 | my $application; | ||
526 | |||
527 | while ( $filename = readdir( DIR ) ) | ||
528 | { | ||
529 | if ( $filename =~ m/\.t$/ ) | ||
530 | { | ||
531 | if ( $excludeIfAppMissing ) | ||
532 | { | ||
533 | $application = basename( $filename, ".t" ); | ||
534 | if ( ! -e $application ) | ||
535 | { | ||
536 | print STDERR "No application (${application}) found for test harness (${filename})\n"; | ||
537 | next; | ||
538 | } | ||
539 | } | ||
540 | push @tests, "${directory}/${filename}"; | ||
541 | } | ||
542 | } | ||
543 | |||
544 | closedir( DIR ); | ||
545 | |||
546 | return @tests; | ||
547 | } | ||
548 | |||
549 | |||
550 | |||
551 | 1; | ||
552 | # | ||
553 | # End of File | ||
554 | # | ||
diff --git a/configure.in b/configure.in index a7f7b0ef..f80be768 100644 --- a/configure.in +++ b/configure.in | |||
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. | |||
2 | AC_REVISION ($Revision$) | 2 | AC_REVISION ($Revision$) |
3 | AC_PREREQ(2.58) | 3 | AC_PREREQ(2.58) |
4 | AC_INIT(nagios-plugins,1.5) | 4 | AC_INIT(nagios-plugins,1.5) |
5 | AC_CONFIG_SRCDIR(Helper.pm) | 5 | AC_CONFIG_SRCDIR(NPTest.pm) |
6 | AM_INIT_AUTOMAKE | 6 | AM_INIT_AUTOMAKE |
7 | AM_CONFIG_HEADER(config.h) | 7 | AM_CONFIG_HEADER(config.h) |
8 | AC_CANONICAL_HOST | 8 | AC_CANONICAL_HOST |
diff --git a/plugins-scripts/t/check_rpc.t b/plugins-scripts/t/check_rpc.t index afcb867c..9fff0ee9 100644 --- a/plugins-scripts/t/check_rpc.t +++ b/plugins-scripts/t/check_rpc.t | |||
@@ -1,19 +1,22 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Remote Procedure Call (RPC) Tests via check_rpc | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
7 | |||
1 | use strict; | 8 | use strict; |
2 | use Test; | 9 | use Test; |
3 | use vars qw($tests); | 10 | use NPTest; |
4 | 11 | ||
12 | use vars qw($tests); | ||
5 | BEGIN {$tests = 2; plan tests => $tests} | 13 | BEGIN {$tests = 2; plan tests => $tests} |
6 | 14 | ||
7 | my $null = ''; | 15 | my $successOutput = '/^check_rpc/'; |
8 | my $cmd; | 16 | |
9 | my $str; | 17 | my $t; |
10 | my $t=0; | ||
11 | 18 | ||
12 | $cmd = "./check_rpc -V"; | 19 | $t += checkCmd( "./check_rpc -V", 0, $successOutput ); |
13 | $str = `$cmd`; | ||
14 | $t += ok $?>>8,0; | ||
15 | print "Test was: $cmd\n" if ($?); | ||
16 | $t += ok $str, '/^check_rpc/'; | ||
17 | 20 | ||
18 | exit(0) if defined($Test::Harness::VERSION); | 21 | exit(0) if defined($Test::Harness::VERSION); |
19 | exit($tests - $t); | 22 | exit($tests - $t); |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index f1e436dc..f2427fbe 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -1,31 +1,33 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Disk Space Tests via check_disk | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
7 | |||
1 | use strict; | 8 | use strict; |
2 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
3 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 10; plan tests => $tests} | ||
14 | |||
15 | my $successOutput = '/^DISK OK - /'; | ||
16 | my $failureOutput = '/^DISK CRITICAL - /'; | ||
17 | |||
18 | my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/", | ||
19 | "The path to a valid mountpoint" ); | ||
4 | 20 | ||
5 | BEGIN {$tests = 6; plan tests => $tests} | 21 | my $mountpoint_invalid = getTestParameter( "mountpoint_invalid", "NP_MOUNTPOINT_INVALID", "/missing", |
22 | "The path to a invalid (non-existent) mountpoint" ); | ||
6 | 23 | ||
7 | my $null = ''; | ||
8 | my $cmd; | ||
9 | my $str; | ||
10 | my $t; | 24 | my $t; |
11 | 25 | ||
12 | $cmd = "./check_disk 100 100 /"; | 26 | $t += checkCmd( "./check_disk 100 100 ${mountpoint_valid}", 0, $successOutput ); |
13 | $str = `$cmd`; | 27 | $t += checkCmd( "./check_disk -w 0 -c 0 ${mountpoint_valid}", 0, $successOutput ); |
14 | $t += ok $?>>8,0; | 28 | $t += checkCmd( "./check_disk -w 1\% -c 1\% ${mountpoint_valid}", 0, $successOutput ); |
15 | print "Test was: $cmd\n" if ($?); | 29 | $t += checkCmd( "./check_disk 0 0 ${mountpoint_valid}", 2, $failureOutput ); |
16 | $t += ok $str, '/^(Disk ok - +[\.0-9]+|DISK OK - )/'; | 30 | $t += checkCmd( "./check_disk 100 100 ${mountpoint_invalid}", 2, '/not found/' ); |
17 | |||
18 | $cmd = "./check_disk -w 0 -c 0 /"; | ||
19 | $str = `$cmd`; | ||
20 | $t += ok $?>>8,0; | ||
21 | print "Test was: $cmd\n" if ($?); | ||
22 | $t += ok $str, '/^(Disk ok - +[\.0-9]+|DISK OK - )/'; | ||
23 | |||
24 | $cmd = "./check_disk 0 0 /"; | ||
25 | $str = `$cmd`; | ||
26 | $t += ok $?>>8,2; | ||
27 | print "Test was: $cmd\n" unless ($?); | ||
28 | $t += ok $str, '/^(Only +[\.0-9]+|DISK CRITICAL - )/'; | ||
29 | 31 | ||
30 | exit(0) if defined($Test::Harness::VERSION); | 32 | exit(0) if defined($Test::Harness::VERSION); |
31 | exit($tests - $t); | 33 | exit($tests - $t); |
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index bee1d34b..fbaca794 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t | |||
@@ -1,28 +1,42 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Domain Name Server (DNS) Tests via check_dns | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 6; plan tests => $tests} | ||
14 | |||
15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; | ||
7 | 16 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 17 | my $hostname_valid = getTestParameter( "hostname_valid", "NP_HOSTNAME_VALID", "localhost", |
18 | "A valid (known to DNS) hostname" ); | ||
9 | 19 | ||
10 | #`nslookup localhost > /dev/null 2>&1` || exit(77); | 20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | |||
23 | my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef, | ||
24 | "A non default (remote) DNS server" ); | ||
11 | 25 | ||
12 | my $null = ''; | ||
13 | my $cmd; | ||
14 | my $str; | ||
15 | my $t; | 26 | my $t; |
16 | 27 | ||
17 | $str = `./check_dns $Cache::dnshost -to 5`; | 28 | # |
18 | $t += ok $?>>8,0; | 29 | # Default DNS Server |
19 | print "Test was: $cmd\n" if ($?); | 30 | # |
20 | $t += ok $str, '/DNS OK: +[\.0-9]+ seconds response time, /'; | 31 | $t += checkCmd( "./check_dns -H $hostname_valid -t 5", 0, $successOutput ); |
32 | $t += checkCmd( "./check_dns -H $hostname_invalid -t 1", 2 ); | ||
21 | 33 | ||
22 | $cmd = "./check_dns $Cache::nullhost -to 1"; | 34 | # |
23 | $str = `$cmd`; | 35 | # Specified DNS Server |
24 | $t += ok $?>>8,2; | 36 | # |
25 | print "Test was: $cmd\n" unless ($?); | 37 | $t += checkCmd( "./check_dns -H $hostname_valid -s $dns_server -t 5", 0, $successOutput ); |
38 | $t += checkCmd( "./check_dns -H $hostname_invalid -s $dns_server -t 1", 2 ); | ||
26 | 39 | ||
27 | exit(0) if defined($Test::Harness::VERSION); | 40 | exit(0) if defined($Test::Harness::VERSION); |
28 | exit($tests - $t); | 41 | exit($tests - $t); |
42 | |||
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t index 629ee35f..c59d59e0 100644 --- a/plugins/t/check_fping.t +++ b/plugins/t/check_fping.t | |||
@@ -1,37 +1,43 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # FPing Tests via check_fping | ||
4 | # | ||
2 | # $Id$ | 5 | # $Id$ |
6 | # | ||
3 | 7 | ||
4 | use strict; | 8 | use strict; |
5 | use Cache; | ||
6 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
7 | use vars qw($tests); | 12 | use vars qw($tests); |
8 | 13 | ||
9 | BEGIN {$tests = 3; plan tests => $tests} | 14 | BEGIN {$tests = 4; plan tests => $tests} |
10 | 15 | ||
11 | exit(0) unless (-x "./check_fping"); | 16 | my $successOutput = '/^FPING OK - /'; |
17 | my $failureOutput = '/^FPING CRITICAL - /'; | ||
12 | 18 | ||
13 | #`fping 127.0.0.1 > /dev/null 2>&1` || exit(77); | 19 | my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost", |
20 | "The hostname of system responsive to network requests" ); | ||
14 | 21 | ||
15 | my $null = ''; | 22 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
16 | my $cmd; | 23 | "The hostname of system not responsive to network requests" ); |
17 | my $str; | ||
18 | my $t; | ||
19 | my $stat; | ||
20 | 24 | ||
25 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
26 | "An invalid (not known to DNS) hostname" ); | ||
21 | 27 | ||
22 | $cmd = "./check_fping 127.0.0.1"; | ||
23 | $str = `$cmd`; | ||
24 | $t += ok $?>>8,0; | ||
25 | print "Test was: $cmd\n" if ($?); | ||
26 | $t += ok $str, '/^FPING OK - 127.0.0.1/'; | ||
27 | 28 | ||
28 | $cmd = "./check_fping $Cache::nullhost"; | 29 | my $t; |
29 | $str = `$cmd`; | 30 | |
30 | if ($?>>8 == 1 or $?>>8 == 2) { | 31 | if ( -x "./check_fping" ) |
31 | $stat = 2; | 32 | { |
33 | $t += checkCmd( "./check_fping $host_responsive", 0, $successOutput ); | ||
34 | $t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] ); | ||
35 | $t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] ); | ||
36 | } | ||
37 | else | ||
38 | { | ||
39 | $t += skipMissingCmd( "./check_fping", $tests ); | ||
32 | } | 40 | } |
33 | $t += ok $stat,2; | ||
34 | print "Test was: $cmd\n" if (($?>>8) < 1); | ||
35 | 41 | ||
36 | exit(0) if defined($Test::Harness::VERSION); | 42 | exit(0) if defined($Test::Harness::VERSION); |
37 | exit($tests - $t); | 43 | exit($tests - $t); |
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t index d9e9d9ca..47a73e13 100644 --- a/plugins/t/check_ftp.t +++ b/plugins/t/check_ftp.t | |||
@@ -1,32 +1,34 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # File Transfer Protocol (FTP) Test via check_ftp | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | #use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 4; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost", |
16 | "A host providing the FTP Service (an FTP server)"); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
11 | my $cmd; | 19 | "The hostname of system not responsive to network requests" ); |
12 | my $str; | ||
13 | my $t; | ||
14 | 20 | ||
15 | $cmd = "./check_ftp $Cache::hostname -wt 300 -ct 600"; | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
16 | $str = `$cmd`; | 22 | "An invalid (not known to DNS) hostname" ); |
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | $t += ok $str, '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; | ||
20 | 23 | ||
21 | #$cmd = "./check_ftp $Cache::noserver -wt 0 -ct 0"; | 24 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; |
22 | #$str = `$cmd`; | ||
23 | #$t += ok $?>>8,2; | ||
24 | #print "Test was: $cmd\n" unless ($?); | ||
25 | 25 | ||
26 | $cmd = "./check_ftp $Cache::nullhost -wt 0 -ct 0 -to 1"; | 26 | my $t; |
27 | $str = `$cmd`; | 27 | |
28 | $t += ok $?>>8,2; | 28 | $t += checkCmd( "./check_ftp $host_tcp_ftp -wt 300 -ct 600", 0, $successOutput ); |
29 | print "Test was: $cmd\n" unless ($?); | 29 | $t += checkCmd( "./check_ftp $host_nonresponsive -wt 0 -ct 0 -to 1", 2 ); |
30 | $t += checkCmd( "./check_ftp $hostname_invalid -wt 0 -ct 0", 2 ); | ||
30 | 31 | ||
31 | exit(0) if defined($Test::Harness::VERSION); | 32 | exit(0) if defined($Test::Harness::VERSION); |
32 | exit($tests - $t); | 33 | exit($tests - $t); |
34 | |||
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t index b4e198d2..b749c778 100644 --- a/plugins/t/check_hpjd.t +++ b/plugins/t/check_hpjd.t | |||
@@ -1,32 +1,42 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # HP JetDirect Test via check_hpjd | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Helper; | ||
5 | use Cache; | ||
6 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
7 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | ||
8 | 14 | ||
9 | BEGIN {$tests = 4; plan tests => $tests} | 15 | my $successOutput = '/^Printer ok - /'; |
16 | my $failureOutput = '/Timeout: No [Rr]esponse from /'; | ||
10 | 17 | ||
11 | exit(0) unless (-x "./check_hpjd"); | 18 | my $host_tcp_hpjd = getTestParameter( "host_tcp_hpjd", "NP_HOST_TCP_HPJD", undef, |
19 | "A host (usually a printer) providing the HP-JetDirect Services" ); | ||
12 | 20 | ||
13 | my $null = ''; | 21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
14 | my $cmd; | 22 | "The hostname of system not responsive to network requests" ); |
15 | my $str; | ||
16 | my $t; | ||
17 | my $printer = get_option("hpjd_printer","HP Jet-Direct card address"); | ||
18 | 23 | ||
19 | $cmd = "./check_hpjd $printer"; | 24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
20 | $str = `$cmd`; | 25 | "An invalid (not known to DNS) hostname" ); |
21 | $t += ok $?>>8,0; | ||
22 | print "Test was: $cmd\n" if ($?); | ||
23 | $t += ok $str, '/^Printer ok - /'; | ||
24 | 26 | ||
25 | $cmd = "./check_hpjd $Cache::noserver"; | 27 | my $t; |
26 | $str = `$cmd`; | 28 | |
27 | $t += ok $?>>8,2; | 29 | if ( -x "./check_hpjd" ) |
28 | print "Test was: $cmd\n" unless ($?); | 30 | { |
29 | $t += ok $str, '/Timeout: No response from /'; | 31 | $t += checkCmd( "./check_hpjd $host_tcp_hpjd", 0, $successOutput ); |
32 | $t += checkCmd( "./check_hpjd $host_nonresponsive", 2, $failureOutput ); | ||
33 | $t += checkCmd( "./check_hpjd $hostname_invalid", 3 ); | ||
34 | } | ||
35 | else | ||
36 | { | ||
37 | $t += skipMissingCmd( "./check_hpjd", $tests ); | ||
38 | } | ||
30 | 39 | ||
31 | exit(0) if defined($Test::Harness::VERSION); | 40 | exit(0) if defined($Test::Harness::VERSION); |
32 | exit($tests - $t); | 41 | exit($tests - $t); |
42 | |||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 5be549ad..56d939b3 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -1,22 +1,36 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # HyperText Transfer Protocol (HTTP) Test via check_http | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 4; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", |
16 | "A host providing the HTTP Service (a web server)" ); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
11 | my $str; | 19 | "The hostname of system not responsive to network requests" ); |
12 | my $t; | ||
13 | 20 | ||
14 | $str = `./check_http $Cache::httphost -wt 300 -ct 600`; | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
15 | $t += ok $?>>8,0; | 22 | "An invalid (not known to DNS) hostname" ); |
16 | $t += ok $str, '/(HTTP\s[o|O][k|K]\s)?\s?HTTP\/1.[01]\s[0-9]{3}\s(OK|Found)\s-\s+[0-9]+\sbytes\sin\s+([0-9]+|[0-9]+\.[0-9]+)\sseconds/'; | ||
17 | 23 | ||
18 | $str = `./check_http $Cache::nullhost -wt 1 -ct 2`; | 24 | my $successOutput = '/(HTTP\s[o|O][k|K]\s)?\s?HTTP\/1.[01]\s[0-9]{3}\s(OK|Found)\s-\s+[0-9]+\sbytes\sin\s+([0-9]+|[0-9]+\.[0-9]+)\sseconds/'; |
19 | $t += ok $?>>8,2; | 25 | |
26 | my %exceptions = ( 2 => "No Web Server present?" ); | ||
27 | |||
28 | my $t; | ||
29 | |||
30 | $t += checkCmd( "./check_http $host_tcp_http -wt 300 -ct 600", { 0 => 'continue', 2 => 'skip' }, $successOutput, %exceptions ); | ||
31 | $t += checkCmd( "./check_http $host_nonresponsive -wt 1 -ct 2", 2 ); | ||
32 | $t += checkCmd( "./check_http $hostname_invalid -wt 1 -ct 2", 2 ); | ||
20 | 33 | ||
21 | exit(0) if defined($Test::Harness::VERSION); | 34 | exit(0) if defined($Test::Harness::VERSION); |
22 | exit($tests - $t); | 35 | exit($tests - $t); |
36 | |||
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t index 47494e59..f86faa4c 100644 --- a/plugins/t/check_imap.t +++ b/plugins/t/check_imap.t | |||
@@ -1,34 +1,39 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | 2 | # | |
3 | #use strict; | 3 | # Internet Mail Access Protocol (IMAP) Server Tests via check_imap |
4 | use Cache; | 4 | # |
5 | # $Id$ | ||
6 | # | ||
7 | |||
8 | use strict; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", |
16 | "A host providing an STMP Service (a mail server)"); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp, |
11 | my $cmd; | 19 | "A host providing an IMAP Service (a mail server)"); |
12 | my $str; | ||
13 | my $t; | ||
14 | 20 | ||
15 | $cmd = "./check_imap $Cache::mailhost"; | 21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
16 | $str = `$cmd`; | 22 | "The hostname of system not responsive to network requests" ); |
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | 23 | ||
20 | $cmd = "./check_imap -H $Cache::mailhost -p 143 -w 9 -c 9 -t 10 -e '* OK'"; | 24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
21 | $str = `$cmd`; | 25 | "An invalid (not known to DNS) hostname" ); |
22 | $t += ok $?>>8,0; | ||
23 | print "Test was: $cmd\n" if ($?); | ||
24 | 26 | ||
27 | my %exceptions = ( 2 => "No IMAP Server present?" ); | ||
28 | |||
29 | my $t; | ||
30 | |||
31 | $t += checkCmd( "./check_imap $host_tcp_imap", 0, undef, %exceptions ); | ||
32 | $t += checkCmd( "./check_imap -H $host_tcp_imap -p 143 -w 9 -c 9 -t 10 -e '* OK'", 0, undef, %exceptions ); | ||
33 | $t += checkCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'", 0, undef, %exceptions ); | ||
34 | $t += checkCmd( "./check_imap $host_nonresponsive", 2 ); | ||
35 | $t += checkCmd( "./check_imap $hostname_invalid", 2 ); | ||
25 | 36 | ||
26 | # Reverse compatibility | ||
27 | $cmd = "./check_imap $Cache::mailhost -p 143 -wt 9 -ct 9 -to 10 -e '* OK'"; | ||
28 | $str = `$cmd`; | ||
29 | $t += ok $?>>8,0; | ||
30 | print "Test was: $cmd\n" if ($?); | ||
31 | 37 | ||
32 | exit(0) if defined($Test::Harness::VERSION); | 38 | exit(0) if defined($Test::Harness::VERSION); |
33 | exit($tests - $t); | 39 | exit($tests - $t); |
34 | |||
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 414e09d6..8f954dc4 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
@@ -1,27 +1,25 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Load Average Tests via check_load | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Test; | 9 | use Test; |
5 | use vars qw($tests); | 10 | use NPTest; |
6 | 11 | ||
12 | use vars qw($tests); | ||
7 | BEGIN {$tests = 4; plan tests => $tests} | 13 | BEGIN {$tests = 4; plan tests => $tests} |
8 | 14 | ||
9 | my $null = ''; | 15 | my $successOutput = '/^OK - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/'; |
10 | my $cmd; | 16 | my $failureOutput = '/^CRITICAL - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/'; |
11 | my $str; | ||
12 | my $t; | ||
13 | 17 | ||
14 | $cmd = "./check_load -w 100,100,100 -c 100,100,100"; | 18 | my $t; |
15 | $str = `$cmd`; | ||
16 | $t += ok $?>>8,0; | ||
17 | print "Test was: $cmd\n" if ($?); | ||
18 | $t += ok $str, '/^OK - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/'; | ||
19 | 19 | ||
20 | $cmd = "./check_load -w 0,0,0 -c 0,0,0"; | 20 | $t += checkCmd( "./check_load -w 100,100,100 -c 100,100,100", 0, $successOutput ); |
21 | $str = `$cmd`; | 21 | $t += checkCmd( "./check_load -w 0,0,0 -c 0,0,0", 2, $failureOutput ); |
22 | $t += ok $?>>8,2; | ||
23 | print "Test was: $cmd\n" unless ($?); | ||
24 | $t += ok $str, '/^CRITICAL - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/'; | ||
25 | 22 | ||
26 | exit(0) if defined($Test::Harness::VERSION); | 23 | exit(0) if defined($Test::Harness::VERSION); |
27 | exit($tests - $t); | 24 | exit($tests - $t); |
25 | |||
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index 0fae65fe..ad423595 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
@@ -1,26 +1,33 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # MySQL Database Server Tests via check_mysql | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Helper; | ||
5 | use Cache; | ||
6 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
7 | use vars qw($tests); | 12 | use vars qw($tests); |
8 | 13 | ||
9 | BEGIN {$tests = 2; plan tests => $tests} | 14 | BEGIN {$tests = 2; plan tests => $tests} |
10 | 15 | ||
11 | exit(0) unless (-x "./check_mysql"); | ||
12 | |||
13 | my $null = ''; | ||
14 | my $cmd; | ||
15 | my $str; | ||
16 | my $t; | 16 | my $t; |
17 | 17 | ||
18 | my $mysqlserver = get_option("mysqlserver","host for MYSQL tests"); | 18 | my $failureOutput = '/Access denied for user: /'; |
19 | |||
20 | if ( -x "./check_mysql" ) | ||
21 | { | ||
22 | my $mysqlserver = getTestParameter( "mysql_server", "NP_MYSQL_SERVER", undef, | ||
23 | "A MySQL Server"); | ||
19 | 24 | ||
20 | $cmd = "./check_mysql -H $mysqlserver -P 3306"; | 25 | $t += checkCmd( "./check_mysql -H $mysqlserver -P 3306", 2, $failureOutput ); |
21 | $str = `$cmd`; | 26 | } |
22 | $t += ok $?>>8,2; | 27 | else |
23 | $t += ok $str, '/Access denied for user: /'; | 28 | { |
29 | $t += skipMissingCmd( "./check_mysql", $tests ); | ||
30 | } | ||
24 | 31 | ||
25 | exit(0) if defined($Test::Harness::VERSION); | 32 | exit(0) if defined($Test::Harness::VERSION); |
26 | exit($tests - $t); | 33 | exit($tests - $t); |
diff --git a/plugins/t/check_ping.t b/plugins/t/check_ping.t index 97bc660e..49c568a6 100644 --- a/plugins/t/check_ping.t +++ b/plugins/t/check_ping.t | |||
@@ -1,33 +1,36 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Ping Response Tests via check_ping | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
7 | 13 | ||
8 | BEGIN {$tests = 5; plan tests => $tests} | 14 | BEGIN {$tests = 6; plan tests => $tests} |
15 | |||
16 | my $successOutput = '/PING (ok|OK) - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/'; | ||
17 | my $failureOutput = '/Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/'; | ||
18 | |||
19 | my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost", | ||
20 | "The hostname of system responsive to network requests" ); | ||
21 | |||
22 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
23 | "The hostname of system not responsive to network requests" ); | ||
24 | |||
25 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
26 | "An invalid (not known to DNS) hostname" ); | ||
9 | 27 | ||
10 | my $null = ''; | ||
11 | my $cmd; | ||
12 | my $str; | ||
13 | my $t; | 28 | my $t; |
14 | 29 | ||
15 | $cmd = "./check_ping 127.0.0.1 100 100 1000 1000 -p 1"; | 30 | $t += checkCmd( "./check_ping $host_responsive 100 100 1000 1000 -p 1", 0, $successOutput ); |
16 | $str = `$cmd`; | 31 | $t += checkCmd( "./check_ping $host_responsive 0 0 0 0 -p 1", 2, $failureOutput ); |
17 | $t += ok $?>>8,0; | 32 | $t += checkCmd( "./check_ping $host_nonresponsive 0 0 0 0 -p 1 -to 1", 2 ); |
18 | print "Test was: $cmd\n" if ($?); | 33 | $t += checkCmd( "./check_ping $hostname_invalid 0 0 0 0 -p 1 -to 1", 3 ); |
19 | $t += ok $str, '/PING (ok|OK) - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/'; | ||
20 | |||
21 | $cmd = "./check_ping 127.0.0.1 0 0 0 0 -p 1"; | ||
22 | $str = `$cmd`; | ||
23 | $t += ok $?>>8,2; | ||
24 | print "Test was: $cmd\n" unless ($?); | ||
25 | $t += ok $str, '/Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/'; | ||
26 | |||
27 | $cmd = "./check_ping $Cache::nullhost 0 0 0 0 -p 1 -to 1"; | ||
28 | $str = `$cmd`; | ||
29 | $t += ok $?>>8,2; | ||
30 | print "Test was: $cmd\n" unless ($?); | ||
31 | 34 | ||
32 | exit(0) if defined($Test::Harness::VERSION); | 35 | exit(0) if defined($Test::Harness::VERSION); |
33 | exit($tests - $t); | 36 | exit($tests - $t); |
diff --git a/plugins/t/check_pop.t b/plugins/t/check_pop.t index 60b5a4ef..e78f963e 100644 --- a/plugins/t/check_pop.t +++ b/plugins/t/check_pop.t | |||
@@ -1,31 +1,38 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Post Office Protocol (POP) Server Tests via check_pop | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | #use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", |
16 | "A host providing an STMP Service (a mail server)"); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_tcp_pop = getTestParameter( "host_tcp_pop", "NP_HOST_TCP_POP", $host_tcp_smtp, |
11 | my $cmd; | 19 | "A host providing an POP Service (a mail server)"); |
12 | my $str; | 20 | |
13 | my $t; | 21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
22 | "The hostname of system not responsive to network requests" ); | ||
14 | 23 | ||
15 | $cmd = "./check_pop $Cache::mailhost"; | 24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
16 | $str = `$cmd`; | 25 | "An invalid (not known to DNS) hostname" ); |
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | 26 | ||
20 | $cmd = "./check_pop -H $Cache::mailhost -p 110 -w 9 -c 9 -t 10 -e '+OK'"; | 27 | my %exceptions = ( 2 => "No POP Server present?" ); |
21 | $str = `$cmd`; | 28 | |
22 | $t += ok $?>>8,0; | 29 | my $t; |
23 | print "Test was: $cmd\n" if ($?); | ||
24 | 30 | ||
25 | $cmd = "./check_pop $Cache::mailhost -p 110 -wt 9 -ct 9 -to 10 -e '+OK'"; | 31 | $t += checkCmd( "./check_pop $host_tcp_pop", 0, undef, %exceptions ); |
26 | $str = `$cmd`; | 32 | $t += checkCmd( "./check_pop -H $host_tcp_pop -p 110 -w 9 -c 9 -t 10 -e '+OK'", 0, undef, %exceptions ); |
27 | $t += ok $?>>8,0; | 33 | $t += checkCmd( "./check_pop $host_tcp_pop -p 110 -wt 9 -ct 9 -to 10 -e '+OK'", 0, undef, %exceptions ); |
28 | print "Test was: $cmd\n" if ($?); | 34 | $t += checkCmd( "./check_pop $host_nonresponsive", 2 ); |
35 | $t += checkCmd( "./check_pop $hostname_invalid", 2 ); | ||
29 | 36 | ||
30 | exit(0) if defined($Test::Harness::VERSION); | 37 | exit(0) if defined($Test::Harness::VERSION); |
31 | exit($tests - $t); | 38 | exit($tests - $t); |
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t index da49ac61..cb5f1224 100644 --- a/plugins/t/check_procs.t +++ b/plugins/t/check_procs.t | |||
@@ -1,51 +1,24 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Process Tests via check_procs | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
6 | use vars qw($tests); | 10 | use NPTest; |
7 | 11 | ||
12 | use vars qw($tests); | ||
8 | BEGIN {$tests = 10; plan tests => $tests} | 13 | BEGIN {$tests = 10; plan tests => $tests} |
9 | 14 | ||
10 | my $null = ''; | ||
11 | my $cmd; | ||
12 | my $str; | ||
13 | my $t; | 15 | my $t; |
14 | 16 | ||
15 | # Reverse Compatibility | 17 | $t += checkCmd( "./check_procs -w 100000 -c 100000", 0, '/^PROCS OK: [0-9]+ process(es)?$/' ); |
16 | $cmd = "./check_procs -w 100000 -c 100000"; | 18 | $t += checkCmd( "./check_procs -w 100000 -c 100000 -s Z", 0, '/^PROCS OK: [0-9]+ process(es)? with /' ); |
17 | $str = `$cmd`; | 19 | $t += checkCmd( "./check_procs -w 0 -c 10000000", 1, '/^PROCS WARNING: [0-9]+ process(es)?$/' ); |
18 | $t += ok $?>>8,0; | 20 | $t += checkCmd( "./check_procs -w 0 -c 0", 2, '/^PROCS CRITICAL: [0-9]+ process(es)?$/' ); |
19 | print "Test was: $cmd\n" if ($?); | 21 | $t += checkCmd( "./check_procs -w 0 -c 0 -s S", 2, '/^PROCS CRITICAL: [0-9]+ process(es)? with /' ); |
20 | $t += ok $str, '/^PROCS OK: [0-9]+ process(es)?$/'; | ||
21 | |||
22 | # Reverse Compatibility | ||
23 | $cmd = "./check_procs -w 100000 -c 100000 -s Z"; | ||
24 | $str = `$cmd`; | ||
25 | $t += ok $?>>8,0; | ||
26 | print "Test was: $cmd\n" if ($?); | ||
27 | $t += ok $str, '/^PROCS OK: [0-9]+ process(es)? with /'; | ||
28 | |||
29 | # Reverse Compatibility | ||
30 | $cmd = "./check_procs -w 0 -c 10000000"; | ||
31 | $str = `$cmd`; | ||
32 | $t += ok $?>>8,1; | ||
33 | print "Test was: $cmd\n" unless ($?); | ||
34 | $t += ok $str, '/^PROCS WARNING: [0-9]+ process(es)?$/'; | ||
35 | |||
36 | # Reverse Compatibility | ||
37 | $cmd = "./check_procs -w 0 -c 0"; | ||
38 | $str = `$cmd`; | ||
39 | $t += ok $?>>8,2; | ||
40 | print "Test was: $cmd\n" unless ($?); | ||
41 | $t += ok $str, '/^PROCS CRITICAL: [0-9]+ process(es)?$/'; | ||
42 | |||
43 | # Reverse Compatibility | ||
44 | $cmd = "./check_procs -w 0 -c 0 -s S"; | ||
45 | $str = `$cmd`; | ||
46 | $t += ok $?>>8,2; | ||
47 | print "Test was: $cmd\n" unless ($?); | ||
48 | $t += ok $str, '/^PROCS CRITICAL: [0-9]+ process(es)? with /'; | ||
49 | 22 | ||
50 | exit(0) if defined($Test::Harness::VERSION); | 23 | exit(0) if defined($Test::Harness::VERSION); |
51 | exit($tests - $t); | 24 | exit($tests - $t); |
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t index 2a82b877..3bf32ecf 100644 --- a/plugins/t/check_smtp.t +++ b/plugins/t/check_smtp.t | |||
@@ -1,31 +1,34 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Simple Mail Transfer Protocol (SMTP) Test via check_smtp | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | #use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", |
16 | "A host providing an STMP Service (a mail server)"); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
11 | my $cmd; | 19 | "The hostname of system not responsive to network requests" ); |
12 | my $str; | ||
13 | my $t; | ||
14 | 20 | ||
15 | $cmd = "./check_smtp $Cache::mailhost"; | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
16 | $str = `$cmd`; | 22 | "An invalid (not known to DNS) hostname" ); |
17 | $t += ok $?>>8,0; | 23 | my %exceptions = ( 2 => "No SMTP Server present?" ); |
18 | print "Test was: $cmd\n" if ($?); | ||
19 | 24 | ||
20 | $cmd = "./check_smtp -H $Cache::mailhost -p 25 -t 1 -w 9 -c 9 -t 10 -e 220"; | 25 | my $t; |
21 | $str = `$cmd`; | ||
22 | $t += ok $?>>8,0; | ||
23 | print "Test was: $cmd\n" if ($?); | ||
24 | 26 | ||
25 | $cmd = "./check_smtp -H $Cache::mailhost -p 25 -wt 9 -ct 9 -to 10 -e 220"; | 27 | $t += checkCmd( "./check_smtp $host_tcp_smtp", 0, undef, %exceptions ); |
26 | $str = `$cmd`; | 28 | $t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -t 1 -w 9 -c 9 -t 10 -e 220", 0, undef, %exceptions ); |
27 | $t += ok $?>>8,0; | 29 | $t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220", 0, undef, %exceptions ); |
28 | print "Test was: $cmd\n" if ($?); | 30 | $t += checkCmd( "./check_smtp $host_nonresponsive", 2 ); |
31 | $t += checkCmd( "./check_smtp $hostname_invalid", 3 ); | ||
29 | 32 | ||
30 | exit(0) if defined($Test::Harness::VERSION); | 33 | exit(0) if defined($Test::Harness::VERSION); |
31 | exit($tests - $t); | 34 | exit($tests - $t); |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 162b0b9b..b45b6c01 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -1,52 +1,57 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Simple Network Management Protocol (SNMP) Test via check_snmp | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Helper; | ||
5 | use Cache; | ||
6 | use Test; | 9 | use Test; |
7 | use vars qw($tests); | 10 | use NPTest; |
8 | 11 | ||
9 | BEGIN {$tests = 8; plan tests => $tests} | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 12; plan tests => $tests} | ||
10 | 14 | ||
11 | my $null = ''; | ||
12 | my $cmd; | ||
13 | my $str; | ||
14 | my $t; | 15 | my $t; |
15 | my $community=get_option("snmp_community","SNMP community name"); | 16 | |
16 | 17 | if ( -x "./check_snmp" ) | |
17 | exit(0) unless (-x "./check_snmp"); | 18 | { |
18 | 19 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | |
19 | $cmd = "./check_snmp -H 127.0.0.1 -C $community -o system.sysUpTime.0 -w 1: -c 1:"; | 20 | "A host providing an SNMP Service"); |
20 | $str = `$cmd`; | 21 | |
21 | $t += ok $?>>8,0; | 22 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", |
22 | print "Test was: $cmd\n" if ($?); | 23 | "The SNMP Community string for SNMP Testing" ); |
23 | chomp $str; | 24 | |
24 | $t += ok $str, '/^SNMP OK - \d+/'; | 25 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
25 | 26 | "The hostname of system not responsive to network requests" ); | |
26 | $cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"; | 27 | |
27 | $str = `$cmd`; | 28 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
28 | $t += ok $?>>8,0; | 29 | "An invalid (not known to DNS) hostname" ); |
29 | print "Test was: $cmd\n" if ($?); | 30 | |
30 | chomp $str; | 31 | my %exceptions = ( 3 => "No SNMP Server present?" ); |
31 | $t += ok $str, '/^SNMP OK - 1\s*$/'; | 32 | |
32 | 33 | ||
33 | $cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"; | 34 | $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", |
34 | $str = `$cmd`; | 35 | { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - \d+/', %exceptions ); |
35 | $t += ok $?>>8,1; | 36 | |
36 | print "Test was: $cmd\n" unless ($?); | 37 | $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1", |
37 | chomp $str; | 38 | { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - 1\s*$/', %exceptions ); |
38 | $t += ok $str, '/^SNMP WARNING - \*1\*\s*$/'; | 39 | |
39 | 40 | $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:", | |
40 | $cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"; | 41 | { 1 => 'continue', 3 => 'skip' }, '/^SNMP WARNING - \*1\*\s*$/', %exceptions ); |
41 | $str = `$cmd`; | 42 | |
42 | $t += ok $?>>8,2; | 43 | $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0", |
43 | print "Test was: $cmd\n" unless ($?); | 44 | { 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s*$/', %exceptions ); |
44 | chomp $str; | 45 | |
45 | $t += ok $str, '/^SNMP CRITICAL - \*1\*\s*$/'; | 46 | $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); |
46 | 47 | ||
47 | #host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 = 1 | 48 | $t += checkCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); |
48 | #enterprises.ucdavis.memory.memAvailSwap.0 | 49 | |
49 | #./check_snmp 127.0.0.1 -C staff -o enterprises.ucdavis.diskTable.dskEntry.dskAvail.1,enterprises.ucdavis.diskTable.dskEntry.dskPercent.1 -w 100000: -c 50000: -l Space on root -u 'bytes free (','% used)' | 50 | } |
51 | else | ||
52 | { | ||
53 | $t += skipMissingCmd( "./check_snmp", $tests ); | ||
54 | } | ||
50 | 55 | ||
51 | exit(0) if defined($Test::Harness::VERSION); | 56 | exit(0) if defined($Test::Harness::VERSION); |
52 | exit($tests - $t); | 57 | exit($tests - $t); |
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index 5b702f00..348010de 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
@@ -1,34 +1,25 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Swap Space Tests via check_swap | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
6 | use vars qw($tests); | 10 | use NPTest; |
7 | 11 | ||
12 | use vars qw($tests); | ||
8 | BEGIN {$tests = 6; plan tests => $tests} | 13 | BEGIN {$tests = 6; plan tests => $tests} |
9 | 14 | ||
10 | my $null = ''; | ||
11 | my $cmd; | ||
12 | my $str; | ||
13 | my $t; | 15 | my $t; |
14 | 16 | ||
15 | $cmd = "./check_swap 100 100"; | 17 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; |
16 | $str = `$cmd`; | 18 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; |
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | $t += ok $str, '/^Swap ok - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$/'; | ||
20 | |||
21 | $cmd = "./check_swap 0 0"; | ||
22 | $str = `$cmd`; | ||
23 | $t += ok $?>>8,2; | ||
24 | print "Test was: $cmd\n" unless ($?); | ||
25 | $t += ok $str, '/^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$/'; | ||
26 | 19 | ||
27 | $cmd = "./check_swap 100 100 1000000000 1000000000"; | 20 | $t += checkCmd( "./check_swap -w 1048576 -c 1048576", 0, $successOutput ); # 1MB free |
28 | $str = `$cmd`; | 21 | $t += checkCmd( "./check_swap -w 1\% -c 1\%", 0, $successOutput ); # 1% free |
29 | $t += ok $?>>8,2; | 22 | $t += checkCmd( "./check_swap -w 100\% -c 100\%", 2, $failureOutput ); # 100% free (always fails) |
30 | print "Test was: $cmd\n" unless ($?); | ||
31 | $t += ok $str, '/^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$/'; | ||
32 | 23 | ||
33 | exit(0) if defined($Test::Harness::VERSION); | 24 | exit(0) if defined($Test::Harness::VERSION); |
34 | exit($tests - $t); | 25 | exit($tests - $t); |
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index 21c3b774..ffe559df 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -1,27 +1,34 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # TCP Connection Based Tests via check_tcp | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | #use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
6 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 5; plan tests => $tests} | ||
7 | 14 | ||
8 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", |
16 | "A host providing the HTTP Service (a web server)" ); | ||
9 | 17 | ||
10 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
11 | my $cmd; | 19 | "The hostname of system not responsive to network requests" ); |
12 | my $str; | 20 | |
13 | my $t; | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
22 | "An invalid (not known to DNS) hostname" ); | ||
14 | 23 | ||
15 | $cmd = "./check_tcp $Cache::hostname -p 80 -wt 300 -ct 600"; | 24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; |
16 | $str = `$cmd`; | 25 | |
17 | $t += ok $?>>8,0; | 26 | my $t; |
18 | print "$cmd\n" if ($?); | ||
19 | $t += ok $str, '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port 80/'; | ||
20 | 27 | ||
21 | $cmd = "./check_tcp $Cache::nullhost -p 81 -wt 0 -ct 0 -to 1"; | 28 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); |
22 | $str = `$cmd`; | 29 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test |
23 | $t += ok $?>>8,2; | 30 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); |
24 | print "$cmd\n" unless ($?); | 31 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); |
25 | 32 | ||
26 | exit(0) if defined($Test::Harness::VERSION); | 33 | exit(0) if defined($Test::Harness::VERSION); |
27 | exit($tests - $t); | 34 | exit($tests - $t); |
diff --git a/plugins/t/check_time.t b/plugins/t/check_time.t index 4d8c5c2b..05878dc2 100644 --- a/plugins/t/check_time.t +++ b/plugins/t/check_time.t | |||
@@ -1,52 +1,40 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # System Time Tests via check_time | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Helper; | ||
6 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
7 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 8; plan tests => $tests} | ||
8 | 14 | ||
9 | BEGIN {$tests = 6; plan tests => $tests} | 15 | my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost", |
16 | "A host providing the UDP Time Service" ); | ||
10 | 17 | ||
11 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
12 | my $cmd; | 19 | "The hostname of system not responsive to network requests" ); |
13 | my $str; | ||
14 | my $t; | ||
15 | my $udp_hostname=get_option("udp_hostname","UDP host name"); | ||
16 | 20 | ||
17 | # standard mode | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
22 | "An invalid (not known to DNS) hostname" ); | ||
18 | 23 | ||
19 | $cmd = "./check_time -H $udp_hostname -w 999999,59 -c 999999,59 -t 60"; | 24 | my $successOutput = '/^TIME OK - [0-9]+ second time difference/'; |
20 | $str = `$cmd`; | ||
21 | $t += ok $?>>8,0; | ||
22 | print "Test was: $cmd\n" if ($?); | ||
23 | $t += ok $str, '/^TIME OK - [0-9]+ second time difference$/'; | ||
24 | 25 | ||
25 | $cmd = "./check_time -H $udp_hostname -w 999999 -W 59 -c 999999 -C 59 -t 60"; | 26 | my $t; |
26 | $str = `$cmd`; | ||
27 | $t += ok $?>>8,0; | ||
28 | print "Test was: $cmd\n" if ($?); | ||
29 | $t += ok $str, '/^TIME OK - [0-9]+ second time difference$/'; | ||
30 | 27 | ||
31 | # reverse compatibility mode | 28 | # standard mode |
29 | $t += checkCmd( "./check_time -H $host_udp_time -w 999999,59 -c 999999,59 -t 60", 0, $successOutput ); | ||
30 | $t += checkCmd( "./check_time -H $host_udp_time -w 999999 -W 59 -c 999999 -C 59 -t 60", 0, $successOutput ); | ||
32 | 31 | ||
33 | $cmd = "./check_time $udp_hostname -wt 59 -ct 59 -cd 999999 -wd 999999 -to 60"; | 32 | # reverse compatibility mode |
34 | $str = `$cmd`; | 33 | $t += checkCmd( "./check_time $host_udp_time -wt 59 -ct 59 -cd 999999 -wd 999999 -to 60", 0, $successOutput ); |
35 | $t += ok $?>>8,0; | ||
36 | print "Test was: $cmd\n" if ($?); | ||
37 | $t += ok $str, '/^TIME OK - [0-9]+ second time difference$/'; | ||
38 | 34 | ||
39 | # failure mode | 35 | # failure mode |
40 | 36 | $t += checkCmd( "./check_time -H $host_nonresponsive -t 1", 2 ); | |
41 | #$cmd = "./check_time -H $Cache::nullhost -t 1"; | 37 | $t += checkCmd( "./check_time -H $hostname_invalid -t 1", 3 ); |
42 | #$str = `$cmd`; | ||
43 | #$t += ok $?>>8,255; | ||
44 | #print "Test was: $cmd\n" unless ($?); | ||
45 | |||
46 | #$cmd = "./check_time -H $Cache::noserver -t 1"; | ||
47 | #$str = `$cmd`; | ||
48 | #$t += ok $?>>8,255; | ||
49 | #print "$cmd\n" unless ($?); | ||
50 | 38 | ||
51 | exit(0) if defined($Test::Harness::VERSION); | 39 | exit(0) if defined($Test::Harness::VERSION); |
52 | exit($tests - $t); | 40 | exit($tests - $t); |
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t index abbf5e49..c80e08ad 100644 --- a/plugins/t/check_udp.t +++ b/plugins/t/check_udp.t | |||
@@ -1,24 +1,33 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # UDP Connection Based Tests via check_udp | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | #use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Helper; | ||
6 | use Test; | 9 | use Test; |
10 | use NPTest; | ||
11 | |||
7 | use vars qw($tests); | 12 | use vars qw($tests); |
13 | BEGIN {$tests = 3; plan tests => $tests} #TODO# Update to 4 when the commented out test is fixed | ||
8 | 14 | ||
9 | BEGIN {$tests = 3; plan tests => $tests} | 15 | my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost", |
16 | "A host providing the UDP Time Service" ); | ||
10 | 17 | ||
11 | my $null = ''; | 18 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
12 | my $str; | 19 | "The hostname of system not responsive to network requests" ); |
13 | my $t; | 20 | |
14 | my $hostname=get_option("udp_hostname","UDP host name"); | 21 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
22 | "An invalid (not known to DNS) hostname" ); | ||
15 | 23 | ||
16 | $str = `./check_udp $hostname -p 37 -wt 300 -ct 600`; | 24 | my $successOutput = '/^Connection accepted on port [0-9]+ - [0-9]+ second response time$/'; |
17 | $t += ok $?>>8,0; | 25 | |
18 | $t += ok $str, '/^Connection accepted on port 37 - [0-9]+ second response time$/'; | 26 | my $t; |
19 | 27 | ||
20 | $str = `./check_udp $Cache::nullhost -p 80 -wt 0 -ct 0 -to 1`; | 28 | $t += checkCmd( "./check_udp -H $host_udp_time -p 37 -wt 300 -ct 600", 0, $successOutput ); |
21 | $t += ok $?>>8,2; | 29 | $t += checkCmd( "./check_udp $host_nonresponsive -p 37 -wt 0 -ct 0 -to 1", 2 ); |
30 | #TODO# $t += checkCmd( "./check_udp $hostname_invalid -p 37 -wt 0 -ct 0 -to 1", 2 ); # Currently returns 0 (ie success) | ||
22 | 31 | ||
23 | exit(0) if defined($Test::Harness::VERSION); | 32 | exit(0) if defined($Test::Harness::VERSION); |
24 | exit($tests - $t); | 33 | exit($tests - $t); |
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 593f1737..4b313d30 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t | |||
@@ -1,28 +1,25 @@ | |||
1 | #! /usr/bin/perl -w | 1 | #! /usr/bin/perl -w -I .. |
2 | # | ||
3 | # Logged in Users Tests via check_users | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
2 | 7 | ||
3 | use strict; | 8 | use strict; |
4 | use Cache; | ||
5 | use Test; | 9 | use Test; |
6 | use vars qw($tests); | 10 | use NPTest; |
7 | 11 | ||
12 | use vars qw($tests); | ||
8 | BEGIN {$tests = 4; plan tests => $tests} | 13 | BEGIN {$tests = 4; plan tests => $tests} |
9 | 14 | ||
10 | my $null = ''; | 15 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; |
11 | my $cmd; | 16 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; |
12 | my $str; | ||
13 | my $t; | ||
14 | 17 | ||
15 | $cmd = "./check_users 1000 1000"; | 18 | my $t; |
16 | $str = `$cmd`; | ||
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | $t += ok $str, '/^USERS OK - +[0-9]+ users currently logged in$/'; | ||
20 | 19 | ||
21 | $cmd = "./check_users 0 0"; | 20 | $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); |
22 | $str = `$cmd`; | 21 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); |
23 | $t += ok $?>>8,2; | ||
24 | print "Test was: $cmd\n" unless ($?); | ||
25 | $t += ok $str, '/^USERS CRITICAL - [0-9]+ +users currently logged in$/'; | ||
26 | 22 | ||
27 | exit(0) if defined($Test::Harness::VERSION); | 23 | exit(0) if defined($Test::Harness::VERSION); |
28 | exit($tests - $t); | 24 | exit($tests - $t); |
25 | |||
diff --git a/plugins/t/check_vsz.t b/plugins/t/check_vsz.t deleted file mode 100644 index 95972619..00000000 --- a/plugins/t/check_vsz.t +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | #! /usr/bin/perl -w | ||
2 | |||
3 | use strict; | ||
4 | use Cache; | ||
5 | use Test; | ||
6 | use vars qw($tests); | ||
7 | |||
8 | BEGIN {$tests = 4; plan tests => $tests} | ||
9 | |||
10 | my $null = ''; | ||
11 | my $cmd; | ||
12 | my $str; | ||
13 | my $t; | ||
14 | |||
15 | $cmd = "./check_vsz 100000 1000000 init"; | ||
16 | $str = `$cmd`; | ||
17 | $t += ok $?>>8,0; | ||
18 | print "Test was: $cmd\n" if ($?); | ||
19 | $t += ok $str, '/^ok \(all VSZ\<[0-9]+\)/'; | ||
20 | |||
21 | $cmd = "./check_vsz 0 0"; | ||
22 | $str = `$cmd`; | ||
23 | $t += ok $?>>8,2; | ||
24 | print "Test was: $cmd\n" unless ($?); | ||
25 | $t += ok $str, '/^CRITICAL \(VSZ\>[0-9]+\)/'; | ||
26 | |||
27 | exit(0) if defined($Test::Harness::VERSION); | ||
28 | exit($tests - $t); | ||
@@ -1,91 +1,51 @@ | |||
1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w -I .. -I ../.. |
2 | # | ||
3 | # Wrapper for running the test harnesses | ||
4 | # | ||
5 | # $Id$ | ||
6 | # | ||
7 | |||
2 | use strict; | 8 | use strict; |
3 | 9 | ||
4 | my $file = '../Cache'; | 10 | use Getopt::Long; |
5 | unless (-f "$file.pm") { | ||
6 | open(CACHE,">$file.pm") or die "Cannot open cache"; | ||
7 | print CACHE "package Cache; | ||
8 | require Exporter; | ||
9 | \@ISA=qw(Exporter); | ||
10 | \@EXPORT=qw(); | ||
11 | 1; | ||
12 | "; | ||
13 | close CACHE; | ||
14 | } | ||
15 | 11 | ||
16 | use Helper; | 12 | use NPTest qw(DetermineTestHarnessDirectory TestsFrom); |
17 | my ($tstdir,$spath,$hostname,$httphost,$mailhost,$dnshost,$noserver,$nullhost,$quickcheck); | ||
18 | 13 | ||
19 | use Getopt::Long; | 14 | my $tstdir; |
20 | GetOptions | 15 | |
21 | ("tstdir:s"=>\$tstdir, | 16 | if ( ! GetOptions( "testdir:s" => \$tstdir ) ) |
22 | "spath:s"=>\$spath, | 17 | { |
23 | "hostname:s"=>\$hostname, | 18 | print "Usage: ${0} [--testdir=<directory>] [<test_harness.t> ...]\n"; |
24 | "httpname:s"=>\$httphost, | 19 | exit 1; |
25 | "mailhost:s"=>\$mailhost, | 20 | } |
26 | "dnshost:s"=>\$dnshost, | ||
27 | "noserver:s"=>\$noserver, | ||
28 | "nullhost:s"=>\$nullhost, | ||
29 | "quickcheck"=>\$quickcheck); | ||
30 | 21 | ||
31 | $spath = "." unless ($spath); | 22 | my @tests; |
32 | 23 | ||
33 | unless ($quickcheck) { | 24 | if ( scalar( @ARGV ) ) |
34 | 25 | { | |
35 | $hostname = get_option("hostname","host for FTP/UDP tests") unless ($hostname); | 26 | @tests = @ARGV; |
36 | $httphost = get_option("httphost","host for HTTP tests") unless ($httphost); | ||
37 | $mailhost = get_option("mailhost","host for SMTP/IMAP/POP tests") unless ($mailhost); | ||
38 | $dnshost = get_option("dnshost","hostname to lookup for DNS tests") unless ($dnshost); | ||
39 | $noserver = get_option("noserver","host that rejects above services") unless ($noserver); | ||
40 | # This machine should not be locatable from your network. Use IP | ||
41 | # private addresses like 10.x.x.x and pick one that does not exist | ||
42 | # on your LAN/WAN | ||
43 | $nullhost = get_option("nullhost","nonexistent IP address (e.g., 10.0.0.0)") unless ($nullhost); | ||
44 | } | 27 | } |
28 | else | ||
29 | { | ||
30 | my $directory = DetermineTestHarnessDirectory( $tstdir ); | ||
31 | |||
32 | if ( !defined( $directory ) ) | ||
33 | { | ||
34 | print STDERR "$0: Unable to determine the test harness directory - ABORTING\n"; | ||
35 | exit 2; | ||
36 | } | ||
45 | 37 | ||
46 | my @dots; | 38 | @tests = TestsFrom( $directory, 1 ); |
47 | if (@ARGV) { | ||
48 | @dots = @ARGV; | ||
49 | } else { | ||
50 | unless ($tstdir) { | ||
51 | if (-d './t') { | ||
52 | $tstdir = './t'; | ||
53 | } else { | ||
54 | $tstdir = $ENV{PWD}; | ||
55 | $tstdir = `/bin/pwd` unless defined($tstdir); | ||
56 | chomp $tstdir; | ||
57 | if (defined($tstdir)) { | ||
58 | $tstdir =~ s|^(.*)/([^/]+)/?$|$1/$2|; | ||
59 | if (-d "../../$2/t") { | ||
60 | $tstdir = "../../$2/t"; | ||
61 | } elsif (-d "$tstdir/t") { | ||
62 | $tstdir = "$tstdir/t"; | ||
63 | } | ||
64 | } else { | ||
65 | die "Could not get PWD from environment\n"; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | $tstdir = './t' unless ($tstdir); | ||
70 | opendir(DIR, $tstdir) || die "can't opendir $tstdir: $!"; | ||
71 | while ($file = readdir(DIR)) { | ||
72 | push @dots, "$tstdir/$file" if ($file =~ m/^[^\.]+\.t$/); | ||
73 | } | ||
74 | closedir DIR; | ||
75 | } | 39 | } |
76 | my $prog; | 40 | |
77 | my $test; | 41 | if ( ! scalar( @tests ) ) |
78 | my @progs; | 42 | { |
79 | foreach $test (@dots) { | 43 | print STDERR "$0: Unable to determine the test harnesses to run - ABORTING\n"; |
80 | $prog=`basename $test .t`; | 44 | exit 3; |
81 | chomp $prog; | ||
82 | if ( -e "$prog" ){ | ||
83 | push @progs, "$test"; | ||
84 | }else{ | ||
85 | print "No binary found for $prog\n"; | ||
86 | } | ||
87 | } | 45 | } |
88 | 46 | ||
89 | use Test::Harness; | 47 | use Test::Harness; |
48 | |||
90 | #$Test::Harness::verbose=1; | 49 | #$Test::Harness::verbose=1; |
91 | runtests(@progs); | 50 | |
51 | runtests( @tests ); | ||