summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Helper.pm44
-rw-r--r--Makefile.am2
-rw-r--r--NPTest.pm554
-rw-r--r--configure.in2
-rw-r--r--plugins-scripts/t/check_rpc.t23
-rw-r--r--plugins/t/check_disk.t44
-rw-r--r--plugins/t/check_dns.t44
-rw-r--r--plugins/t/check_fping.t48
-rw-r--r--plugins/t/check_ftp.t44
-rw-r--r--plugins/t/check_hpjd.t50
-rw-r--r--plugins/t/check_http.t36
-rw-r--r--plugins/t/check_imap.t51
-rw-r--r--plugins/t/check_load.t30
-rw-r--r--plugins/t/check_mysql.t33
-rw-r--r--plugins/t/check_ping.t47
-rw-r--r--plugins/t/check_pop.t47
-rw-r--r--plugins/t/check_procs.t53
-rw-r--r--plugins/t/check_smtp.t43
-rw-r--r--plugins/t/check_snmp.t91
-rw-r--r--plugins/t/check_swap.t35
-rw-r--r--plugins/t/check_tcp.t41
-rw-r--r--plugins/t/check_time.t60
-rw-r--r--plugins/t/check_udp.t37
-rw-r--r--plugins/t/check_users.t31
-rw-r--r--plugins/t/check_vsz.t28
-rwxr-xr-xtest.pl.in116
26 files changed, 1060 insertions, 574 deletions
diff --git a/Helper.pm b/Helper.pm
deleted file mode 100644
index 198a648..0000000
--- a/Helper.pm
+++ /dev/null
@@ -1,44 +0,0 @@
1package Helper;
2use strict;
3
4use Exporter();
5use vars qw($VERSION @ISA @EXPORT);
6$VERSION = 0.01;
7@ISA=qw(Exporter);
8@EXPORT=qw(&get_option);
9
10sub 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
441;
diff --git a/Makefile.am b/Makefile.am
index ca570e3..a7c5ffc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,7 @@ SUBDIRS = intl lib plugins plugins-scripts m4 po
5EXTRA_DIST = config.rpath \ 5EXTRA_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
10ACLOCAL_AMFLAGS = -I m4 10ACLOCAL_AMFLAGS = -I m4
11 11
diff --git a/NPTest.pm b/NPTest.pm
new file mode 100644
index 0000000..f3c874b
--- /dev/null
+++ b/NPTest.pm
@@ -0,0 +1,554 @@
1package NPTest;
2
3#
4# Helper Functions for testing Nagios Plugins
5#
6
7require Exporter;
8@ISA = qw(Exporter);
9@EXPORT = qw(getTestParameter checkCmd skipMissingCmd);
10@EXPORT_OK = qw(DetermineTestHarnessDirectory TestsFrom SetCacheFilename);
11
12use strict;
13use warnings;
14
15use Cwd;
16use File::Basename;
17
18use IO::File;
19use Data::Dumper;
20
21use Test;
22
23use 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
28NPTest - Simplify the testing of Nagios Plugins
29
30=head1 DESCRIPTION
31
32This modules provides convenience functions to assist in the testing
33of Nagios Plugins, making the testing code easier to read and write;
34hopefully encouraging the development of more complete test suite for
35the Nagios Plugins. It is based on the patterns of testing seen in the
361.4.0 release, and continues to use the L<Test> module as the basis of
37testing.
38
39=head1 FUNCTIONS
40
41This module defines three public functions, C<getTestParameter(...)>,
42C<checkCmd(...)> and C<skipMissingCmd(...)>. These are exported by
43default via the C<use NPTest;> statement.
44
45=over
46
47=item C<getTestParameter(...)>
48
49A flexible and user override-able method of collecting, storing and
50retrieving test parameters. This function allows the test harness
51developer to interactively request test parameter information from the
52user, when the no means of obtaining the information automatically has
53been successful. The user is provided with the option of accepting
54test harness developer's default value for the parameter, if a suggested
55default is provided.
56
57User supplied responses are stored in an external (file-based)
58cache. These values are retrieved on subsequent runs alleviating the
59user of reconfirming the previous entered responses. The user is able
60to override the value of a parameter on any given run by setting the
61associated environment variable. These environment variable based
62overrides are not stored in the cache, allowing one-time and what-if
63based tests on the command line without polluting the cache.
64
65The option exists to store parameters in a scoped means, allowing a
66test harness to a localise a parameter should the need arise. This
67allows a parameter of the same name to exist in a test harness
68specific scope, while not affecting the globally scoped parameter. The
69scoping identifier is the name of the test harness sans the trailing
70".t". All cache searches first look to a scoped parameter before
71looking for the parameter at global scope. Thus for a test harness
72called "check_disk.t" requesting the parameter "mountpoint_valid", the
73cache is first searched for "check_disk"/"mountpoint_valid", if this
74fails, then a search is conducted for "mountpoint_valid".
75
76The facilitate quick testing setup, it is possible to accept all the
77developer provided defaults by setting the environment variable
78"NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note
79that, such defaults are not stored in the cache, as there is currently
80no mechanism to edit existing cache entries, save the use of text
81editor or removing the cache file completely.
82
83=item C<checkCmd(...)>
84
85This function attempts to encompass the majority of test styles used
86in testing Nagios Plugins. As each plug-in is a separate command, the
87typical tests we wish to perform are against the exit status of the
88command and the output (if any) it generated. Simplifying these tests
89into a single function call, makes the test harness easier to read and
90maintain and allows additional functionality (such as debugging) to be
91provided withoutadditional effort on the part of the test harness
92developer.
93
94It is possible to enable debugging via the environment variable
95C<NPTEST_DEBUG>. If this environment variable exists and its value in PERL's
96boolean context evaluates to true, debugging is enabled.
97
98The 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
110The function treats the first parameter C<$command> as a command line
111to execute as part of the test, it is executed only once and its exit
112status (C<$?E<gt>E<gt>8>) and output are captured.
113
114At this point if debugging is enabled the command, its exit status and
115output are displayed to the tester.
116
117C<checkCmd(...)> allows the testing of either the exit status or the
118generated output or both, not testing either will result in neither
119the C<Test::ok(...)> or C<Test::skip(...)> functions being called,
120something you probably don't want. Note that each defined test
121(C<$desiredExitStatus> and C<$desiredOutput>) results in a invocation
122of either C<Test::ok(...)> or C<Test::skip(...)>, so remember this
123when counting the number of tests to place in the C<Test::plan(...)>
124call.
125
126Many Nagios Plugins test network services, some of which may not be
127present on all systems. To cater for this, C<checkCmd(...)> allows the
128tester to define exceptions based on the command's exit status. These
129exceptions are provided to skip tests if the test case developer
130believes the service is not being provided. For example, if a site
131does not have a POP3 server, the test harness could map the
132appropriate exit status to a useful message the person running the
133tests, telling the reason the test is being skipped.
134
135Example:
136
137my %exceptions = ( 2 =E<gt> "No POP Server present?" );
138
139$t += checkCmd( "./check_pop I<some args>", 0, undef, %exceptions );
140
141Thus, in the above example, an exit status of 2 does not result in a
142failed test case (as the exit status is not the desired value of 0),
143but a skipped test case with the message "No POP Server present?"
144given as the reason.
145
146Sometimes the exit status of a command should be tested against a set
147of possible values, rather than a single value, this could especially
148be the case in failure testing. C<checkCmd(...)> support two methods
149of testing against a set of desired exit status values.
150
151=over
152
153=item *
154
155Firstly, if C<$desiredExitStatus> is a reference to an array of exit
156stati, if the actual exit status of the command is present in the
157array, it is used in the call to C<Test::ok(...)> when testing the
158exit status.
159
160=item *
161
162Alternatively, if C<$desiredExitStatus> is a reference to a hash of
163exit stati (mapped to the strings "continue" or "skip"), similar
164processing to the above occurs with the side affect of determining if
165any 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
172If a command is missing and the test harness must C<Test::skip()> some
173or all of the tests in a given test harness this function provides a
174simple iterator to issue an appropriate message the requested number
175of times.
176
177=back
178
179=head1 SEE ALSO
180
181L<Test>
182
183The rest of the code, as I have only commented on the major public
184functions that test harness writers will use, not all the code present
185in this helper module.
186
187=head1 AUTHOR
188
189Copyright (c) 2005 Peter Bray. All rights reserved.
190
191This package is free software and is provided "as is" without express
192or implied warranty. It may be used, redistributed and/or modified
193under the same terms as the Nagios Plugins release.
194
195=cut
196
197#
198# Package Scope Variables
199#
200
201my( %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
205my( $CACHEFILENAME ) = ( exists( $ENV{'NPTESTCACHE'} ) && $ENV{'NPTESTCACHE'} )
206 ? $ENV{'NPTESTCACHE'} : "/var/tmp/NPTest.cache"; # "../Cache.pdd";
207
208#
209# Testing Functions
210#
211
212sub 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
290sub 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
304sub 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
363sub 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
380sub 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
396sub 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
423sub 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
450sub 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
464sub 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
510sub 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
5511;
552#
553# End of File
554#
diff --git a/configure.in b/configure.in
index a7f7b0e..f80be76 100644
--- a/configure.in
+++ b/configure.in
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
2AC_REVISION ($Revision$) 2AC_REVISION ($Revision$)
3AC_PREREQ(2.58) 3AC_PREREQ(2.58)
4AC_INIT(nagios-plugins,1.5) 4AC_INIT(nagios-plugins,1.5)
5AC_CONFIG_SRCDIR(Helper.pm) 5AC_CONFIG_SRCDIR(NPTest.pm)
6AM_INIT_AUTOMAKE 6AM_INIT_AUTOMAKE
7AM_CONFIG_HEADER(config.h) 7AM_CONFIG_HEADER(config.h)
8AC_CANONICAL_HOST 8AC_CANONICAL_HOST
diff --git a/plugins-scripts/t/check_rpc.t b/plugins-scripts/t/check_rpc.t
index afcb867..9fff0ee 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
1use strict; 8use strict;
2use Test; 9use Test;
3use vars qw($tests); 10use NPTest;
4 11
12use vars qw($tests);
5BEGIN {$tests = 2; plan tests => $tests} 13BEGIN {$tests = 2; plan tests => $tests}
6 14
7my $null = ''; 15my $successOutput = '/^check_rpc/';
8my $cmd; 16
9my $str; 17my $t;
10my $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;
15print "Test was: $cmd\n" if ($?);
16$t += ok $str, '/^check_rpc/';
17 20
18exit(0) if defined($Test::Harness::VERSION); 21exit(0) if defined($Test::Harness::VERSION);
19exit($tests - $t); 22exit($tests - $t);
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index f1e436d..f2427fb 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
1use strict; 8use strict;
2use Test; 9use Test;
10use NPTest;
11
3use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 10; plan tests => $tests}
14
15my $successOutput = '/^DISK OK - /';
16my $failureOutput = '/^DISK CRITICAL - /';
17
18my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/",
19 "The path to a valid mountpoint" );
4 20
5BEGIN {$tests = 6; plan tests => $tests} 21my $mountpoint_invalid = getTestParameter( "mountpoint_invalid", "NP_MOUNTPOINT_INVALID", "/missing",
22 "The path to a invalid (non-existent) mountpoint" );
6 23
7my $null = '';
8my $cmd;
9my $str;
10my $t; 24my $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 );
15print "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;
21print "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;
27print "Test was: $cmd\n" unless ($?);
28$t += ok $str, '/^(Only +[\.0-9]+|DISK CRITICAL - )/';
29 31
30exit(0) if defined($Test::Harness::VERSION); 32exit(0) if defined($Test::Harness::VERSION);
31exit($tests - $t); 33exit($tests - $t);
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index bee1d34..fbaca79 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 6; plan tests => $tests}
14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
7 16
8BEGIN {$tests = 3; plan tests => $tests} 17my $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); 20my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
21 "An invalid (not known to DNS) hostname" );
22
23my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef,
24 "A non default (remote) DNS server" );
11 25
12my $null = '';
13my $cmd;
14my $str;
15my $t; 26my $t;
16 27
17$str = `./check_dns $Cache::dnshost -to 5`; 28#
18$t += ok $?>>8,0; 29# Default DNS Server
19print "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#
25print "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
27exit(0) if defined($Test::Harness::VERSION); 40exit(0) if defined($Test::Harness::VERSION);
28exit($tests - $t); 41exit($tests - $t);
42
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t
index 629ee35..c59d59e 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
4use strict; 8use strict;
5use Cache;
6use Test; 9use Test;
10use NPTest;
11
7use vars qw($tests); 12use vars qw($tests);
8 13
9BEGIN {$tests = 3; plan tests => $tests} 14BEGIN {$tests = 4; plan tests => $tests}
10 15
11exit(0) unless (-x "./check_fping"); 16my $successOutput = '/^FPING OK - /';
17my $failureOutput = '/^FPING CRITICAL - /';
12 18
13#`fping 127.0.0.1 > /dev/null 2>&1` || exit(77); 19my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
20 "The hostname of system responsive to network requests" );
14 21
15my $null = ''; 22my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
16my $cmd; 23 "The hostname of system not responsive to network requests" );
17my $str;
18my $t;
19my $stat;
20 24
25my $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;
25print "Test was: $cmd\n" if ($?);
26$t += ok $str, '/^FPING OK - 127.0.0.1/';
27 28
28$cmd = "./check_fping $Cache::nullhost"; 29my $t;
29$str = `$cmd`; 30
30if ($?>>8 == 1 or $?>>8 == 2) { 31if ( -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}
37else
38{
39 $t += skipMissingCmd( "./check_fping", $tests );
32} 40}
33$t += ok $stat,2;
34print "Test was: $cmd\n" if (($?>>8) < 1);
35 41
36exit(0) if defined($Test::Harness::VERSION); 42exit(0) if defined($Test::Harness::VERSION);
37exit($tests - $t); 43exit($tests - $t);
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t
index d9e9d9c..47a73e1 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; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 4; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost",
16 "A host providing the FTP Service (an FTP server)");
9 17
10my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
11my $cmd; 19 "The hostname of system not responsive to network requests" );
12my $str;
13my $t;
14 20
15$cmd = "./check_ftp $Cache::hostname -wt 300 -ct 600"; 21my $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;
18print "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"; 24my $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"; 26my $t;
27$str = `$cmd`; 27
28$t += ok $?>>8,2; 28$t += checkCmd( "./check_ftp $host_tcp_ftp -wt 300 -ct 600", 0, $successOutput );
29print "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
31exit(0) if defined($Test::Harness::VERSION); 32exit(0) if defined($Test::Harness::VERSION);
32exit($tests - $t); 33exit($tests - $t);
34
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t
index b4e198d..b749c77 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
3use strict; 8use strict;
4use Helper;
5use Cache;
6use Test; 9use Test;
10use NPTest;
11
7use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 5; plan tests => $tests}
8 14
9BEGIN {$tests = 4; plan tests => $tests} 15my $successOutput = '/^Printer ok - /';
16my $failureOutput = '/Timeout: No [Rr]esponse from /';
10 17
11exit(0) unless (-x "./check_hpjd"); 18my $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
13my $null = ''; 21my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
14my $cmd; 22 "The hostname of system not responsive to network requests" );
15my $str;
16my $t;
17my $printer = get_option("hpjd_printer","HP Jet-Direct card address");
18 23
19$cmd = "./check_hpjd $printer"; 24my $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;
22print "Test was: $cmd\n" if ($?);
23$t += ok $str, '/^Printer ok - /';
24 26
25$cmd = "./check_hpjd $Cache::noserver"; 27my $t;
26$str = `$cmd`; 28
27$t += ok $?>>8,2; 29if ( -x "./check_hpjd" )
28print "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}
35else
36{
37 $t += skipMissingCmd( "./check_hpjd", $tests );
38}
30 39
31exit(0) if defined($Test::Harness::VERSION); 40exit(0) if defined($Test::Harness::VERSION);
32exit($tests - $t); 41exit($tests - $t);
42
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 5be549a..56d939b 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 4; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
16 "A host providing the HTTP Service (a web server)" );
9 17
10my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
11my $str; 19 "The hostname of system not responsive to network requests" );
12my $t;
13 20
14$str = `./check_http $Cache::httphost -wt 300 -ct 600`; 21my $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`; 24my $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
26my %exceptions = ( 2 => "No Web Server present?" );
27
28my $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
21exit(0) if defined($Test::Harness::VERSION); 34exit(0) if defined($Test::Harness::VERSION);
22exit($tests - $t); 35exit($tests - $t);
36
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t
index 47494e5..f86faa4 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
4use Cache; 4#
5# $Id$
6#
7
8use strict;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 5; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
16 "A host providing an STMP Service (a mail server)");
9 17
10my $null = ''; 18my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp,
11my $cmd; 19 "A host providing an IMAP Service (a mail server)");
12my $str;
13my $t;
14 20
15$cmd = "./check_imap $Cache::mailhost"; 21my $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;
18print "Test was: $cmd\n" if ($?);
19 23
20$cmd = "./check_imap -H $Cache::mailhost -p 143 -w 9 -c 9 -t 10 -e '* OK'"; 24my $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;
23print "Test was: $cmd\n" if ($?);
24 26
27my %exceptions = ( 2 => "No IMAP Server present?" );
28
29my $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;
30print "Test was: $cmd\n" if ($?);
31 37
32exit(0) if defined($Test::Harness::VERSION); 38exit(0) if defined($Test::Harness::VERSION);
33exit($tests - $t); 39exit($tests - $t);
34
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t
index 414e09d..8f954dc 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
3use strict; 8use strict;
4use Test; 9use Test;
5use vars qw($tests); 10use NPTest;
6 11
12use vars qw($tests);
7BEGIN {$tests = 4; plan tests => $tests} 13BEGIN {$tests = 4; plan tests => $tests}
8 14
9my $null = ''; 15my $successOutput = '/^OK - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/';
10my $cmd; 16my $failureOutput = '/^CRITICAL - load average: [0-9]\.?[0-9]+, [0-9]\.?[0-9]+, [0-9]\.?[0-9]+/';
11my $str;
12my $t;
13 17
14$cmd = "./check_load -w 100,100,100 -c 100,100,100"; 18my $t;
15$str = `$cmd`;
16$t += ok $?>>8,0;
17print "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;
23print "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
26exit(0) if defined($Test::Harness::VERSION); 23exit(0) if defined($Test::Harness::VERSION);
27exit($tests - $t); 24exit($tests - $t);
25
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t
index 0fae65f..ad42359 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
3use strict; 8use strict;
4use Helper;
5use Cache;
6use Test; 9use Test;
10use NPTest;
11
7use vars qw($tests); 12use vars qw($tests);
8 13
9BEGIN {$tests = 2; plan tests => $tests} 14BEGIN {$tests = 2; plan tests => $tests}
10 15
11exit(0) unless (-x "./check_mysql");
12
13my $null = '';
14my $cmd;
15my $str;
16my $t; 16my $t;
17 17
18my $mysqlserver = get_option("mysqlserver","host for MYSQL tests"); 18my $failureOutput = '/Access denied for user: /';
19
20if ( -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; 27else
23$t += ok $str, '/Access denied for user: /'; 28{
29 $t += skipMissingCmd( "./check_mysql", $tests );
30}
24 31
25exit(0) if defined($Test::Harness::VERSION); 32exit(0) if defined($Test::Harness::VERSION);
26exit($tests - $t); 33exit($tests - $t);
diff --git a/plugins/t/check_ping.t b/plugins/t/check_ping.t
index 97bc660..49c568a 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
7 13
8BEGIN {$tests = 5; plan tests => $tests} 14BEGIN {$tests = 6; plan tests => $tests}
15
16my $successOutput = '/PING (ok|OK) - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
17my $failureOutput = '/Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
18
19my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
20 "The hostname of system responsive to network requests" );
21
22my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
23 "The hostname of system not responsive to network requests" );
24
25my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
26 "An invalid (not known to DNS) hostname" );
9 27
10my $null = '';
11my $cmd;
12my $str;
13my $t; 28my $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 );
18print "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;
24print "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;
30print "Test was: $cmd\n" unless ($?);
31 34
32exit(0) if defined($Test::Harness::VERSION); 35exit(0) if defined($Test::Harness::VERSION);
33exit($tests - $t); 36exit($tests - $t);
diff --git a/plugins/t/check_pop.t b/plugins/t/check_pop.t
index 60b5a4e..e78f963 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; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 5; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
16 "A host providing an STMP Service (a mail server)");
9 17
10my $null = ''; 18my $host_tcp_pop = getTestParameter( "host_tcp_pop", "NP_HOST_TCP_POP", $host_tcp_smtp,
11my $cmd; 19 "A host providing an POP Service (a mail server)");
12my $str; 20
13my $t; 21my $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"; 24my $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;
18print "Test was: $cmd\n" if ($?);
19 26
20$cmd = "./check_pop -H $Cache::mailhost -p 110 -w 9 -c 9 -t 10 -e '+OK'"; 27my %exceptions = ( 2 => "No POP Server present?" );
21$str = `$cmd`; 28
22$t += ok $?>>8,0; 29my $t;
23print "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 );
28print "Test was: $cmd\n" if ($?); 34$t += checkCmd( "./check_pop $host_nonresponsive", 2 );
35$t += checkCmd( "./check_pop $hostname_invalid", 2 );
29 36
30exit(0) if defined($Test::Harness::VERSION); 37exit(0) if defined($Test::Harness::VERSION);
31exit($tests - $t); 38exit($tests - $t);
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t
index da49ac6..cb5f122 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
6use vars qw($tests); 10use NPTest;
7 11
12use vars qw($tests);
8BEGIN {$tests = 10; plan tests => $tests} 13BEGIN {$tests = 10; plan tests => $tests}
9 14
10my $null = '';
11my $cmd;
12my $str;
13my $t; 15my $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)?$/' );
19print "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;
26print "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;
33print "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;
40print "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;
47print "Test was: $cmd\n" unless ($?);
48$t += ok $str, '/^PROCS CRITICAL: [0-9]+ process(es)? with /';
49 22
50exit(0) if defined($Test::Harness::VERSION); 23exit(0) if defined($Test::Harness::VERSION);
51exit($tests - $t); 24exit($tests - $t);
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t
index 2a82b87..3bf32ec 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; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 5; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
16 "A host providing an STMP Service (a mail server)");
9 17
10my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
11my $cmd; 19 "The hostname of system not responsive to network requests" );
12my $str;
13my $t;
14 20
15$cmd = "./check_smtp $Cache::mailhost"; 21my $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; 23my %exceptions = ( 2 => "No SMTP Server present?" );
18print "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"; 25my $t;
21$str = `$cmd`;
22$t += ok $?>>8,0;
23print "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 );
28print "Test was: $cmd\n" if ($?); 30$t += checkCmd( "./check_smtp $host_nonresponsive", 2 );
31$t += checkCmd( "./check_smtp $hostname_invalid", 3 );
29 32
30exit(0) if defined($Test::Harness::VERSION); 33exit(0) if defined($Test::Harness::VERSION);
31exit($tests - $t); 34exit($tests - $t);
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index 162b0b9..b45b6c0 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
3use strict; 8use strict;
4use Helper;
5use Cache;
6use Test; 9use Test;
7use vars qw($tests); 10use NPTest;
8 11
9BEGIN {$tests = 8; plan tests => $tests} 12use vars qw($tests);
13BEGIN {$tests = 12; plan tests => $tests}
10 14
11my $null = '';
12my $cmd;
13my $str;
14my $t; 15my $t;
15my $community=get_option("snmp_community","SNMP community name"); 16
16 17if ( -x "./check_snmp" )
17exit(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",
22print "Test was: $cmd\n" if ($?); 23 "The SNMP Community string for SNMP Testing" );
23chomp $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" );
29print "Test was: $cmd\n" if ($?); 30
30chomp $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
36print "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",
37chomp $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",
43print "Test was: $cmd\n" unless ($?); 44 { 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s*$/', %exceptions );
44chomp $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}
51else
52{
53 $t += skipMissingCmd( "./check_snmp", $tests );
54}
50 55
51exit(0) if defined($Test::Harness::VERSION); 56exit(0) if defined($Test::Harness::VERSION);
52exit($tests - $t); 57exit($tests - $t);
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index 5b702f0..348010d 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
6use vars qw($tests); 10use NPTest;
7 11
12use vars qw($tests);
8BEGIN {$tests = 6; plan tests => $tests} 13BEGIN {$tests = 6; plan tests => $tests}
9 14
10my $null = '';
11my $cmd;
12my $str;
13my $t; 15my $t;
14 16
15$cmd = "./check_swap 100 100"; 17my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
16$str = `$cmd`; 18my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
17$t += ok $?>>8,0;
18print "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;
24print "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)
30print "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
33exit(0) if defined($Test::Harness::VERSION); 24exit(0) if defined($Test::Harness::VERSION);
34exit($tests - $t); 25exit($tests - $t);
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index 21c3b77..ffe559d 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; 8use strict;
4use Cache;
5use Test; 9use Test;
10use NPTest;
11
6use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 5; plan tests => $tests}
7 14
8BEGIN {$tests = 3; plan tests => $tests} 15my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
16 "A host providing the HTTP Service (a web server)" );
9 17
10my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
11my $cmd; 19 "The hostname of system not responsive to network requests" );
12my $str; 20
13my $t; 21my $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"; 24my $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; 26my $t;
18print "$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 );
24print "$cmd\n" unless ($?); 31$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
25 32
26exit(0) if defined($Test::Harness::VERSION); 33exit(0) if defined($Test::Harness::VERSION);
27exit($tests - $t); 34exit($tests - $t);
diff --git a/plugins/t/check_time.t b/plugins/t/check_time.t
index 4d8c5c2..05878dc 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
3use strict; 8use strict;
4use Cache;
5use Helper;
6use Test; 9use Test;
10use NPTest;
11
7use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 8; plan tests => $tests}
8 14
9BEGIN {$tests = 6; plan tests => $tests} 15my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost",
16 "A host providing the UDP Time Service" );
10 17
11my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
12my $cmd; 19 "The hostname of system not responsive to network requests" );
13my $str;
14my $t;
15my $udp_hostname=get_option("udp_hostname","UDP host name");
16 20
17# standard mode 21my $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"; 24my $successOutput = '/^TIME OK - [0-9]+ second time difference/';
20$str = `$cmd`;
21$t += ok $?>>8,0;
22print "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"; 26my $t;
26$str = `$cmd`;
27$t += ok $?>>8,0;
28print "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;
36print "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
51exit(0) if defined($Test::Harness::VERSION); 39exit(0) if defined($Test::Harness::VERSION);
52exit($tests - $t); 40exit($tests - $t);
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t
index abbf5e4..c80e08a 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; 8use strict;
4use Cache;
5use Helper;
6use Test; 9use Test;
10use NPTest;
11
7use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 3; plan tests => $tests} #TODO# Update to 4 when the commented out test is fixed
8 14
9BEGIN {$tests = 3; plan tests => $tests} 15my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost",
16 "A host providing the UDP Time Service" );
10 17
11my $null = ''; 18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
12my $str; 19 "The hostname of system not responsive to network requests" );
13my $t; 20
14my $hostname=get_option("udp_hostname","UDP host name"); 21my $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`; 24my $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$/'; 26my $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
23exit(0) if defined($Test::Harness::VERSION); 32exit(0) if defined($Test::Harness::VERSION);
24exit($tests - $t); 33exit($tests - $t);
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t
index 593f173..4b313d3 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
3use strict; 8use strict;
4use Cache;
5use Test; 9use Test;
6use vars qw($tests); 10use NPTest;
7 11
12use vars qw($tests);
8BEGIN {$tests = 4; plan tests => $tests} 13BEGIN {$tests = 4; plan tests => $tests}
9 14
10my $null = ''; 15my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/';
11my $cmd; 16my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/';
12my $str;
13my $t;
14 17
15$cmd = "./check_users 1000 1000"; 18my $t;
16$str = `$cmd`;
17$t += ok $?>>8,0;
18print "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;
24print "Test was: $cmd\n" unless ($?);
25$t += ok $str, '/^USERS CRITICAL - [0-9]+ +users currently logged in$/';
26 22
27exit(0) if defined($Test::Harness::VERSION); 23exit(0) if defined($Test::Harness::VERSION);
28exit($tests - $t); 24exit($tests - $t);
25
diff --git a/plugins/t/check_vsz.t b/plugins/t/check_vsz.t
deleted file mode 100644
index 9597261..0000000
--- a/plugins/t/check_vsz.t
+++ /dev/null
@@ -1,28 +0,0 @@
1#! /usr/bin/perl -w
2
3use strict;
4use Cache;
5use Test;
6use vars qw($tests);
7
8BEGIN {$tests = 4; plan tests => $tests}
9
10my $null = '';
11my $cmd;
12my $str;
13my $t;
14
15$cmd = "./check_vsz 100000 1000000 init";
16$str = `$cmd`;
17$t += ok $?>>8,0;
18print "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;
24print "Test was: $cmd\n" unless ($?);
25$t += ok $str, '/^CRITICAL \(VSZ\>[0-9]+\)/';
26
27exit(0) if defined($Test::Harness::VERSION);
28exit($tests - $t);
diff --git a/test.pl.in b/test.pl.in
index e88c473..22d0576 100755
--- a/test.pl.in
+++ b/test.pl.in
@@ -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
2use strict; 8use strict;
3 9
4my $file = '../Cache'; 10use Getopt::Long;
5unless (-f "$file.pm") {
6 open(CACHE,">$file.pm") or die "Cannot open cache";
7 print CACHE "package Cache;
8require Exporter;
9\@ISA=qw(Exporter);
10\@EXPORT=qw();
111;
12";
13 close CACHE;
14}
15 11
16use Helper; 12use NPTest qw(DetermineTestHarnessDirectory TestsFrom);
17my ($tstdir,$spath,$hostname,$httphost,$mailhost,$dnshost,$noserver,$nullhost,$quickcheck);
18 13
19use Getopt::Long; 14my $tstdir;
20GetOptions 15
21 ("tstdir:s"=>\$tstdir, 16if ( ! 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); 22my @tests;
32 23
33unless ($quickcheck) { 24if ( 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}
28else
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
46my @dots; 38 @tests = TestsFrom( $directory, 1 );
47if (@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}
76my $prog; 40
77my $test; 41if ( ! scalar( @tests ) )
78my @progs; 42{
79foreach $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
89use Test::Harness; 47use Test::Harness;
48
90#$Test::Harness::verbose=1; 49#$Test::Harness::verbose=1;
91runtests(@progs); 50
51runtests( @tests );