Revert "Make use of xasprintf instead of asprintf"
[monitoring-plugins.git] / plugins / t / check_fping.t
blob08692e46c66fb64243fb2b44b9ebe5b0636e2c24
1 #! /usr/bin/perl -w -I ..
3 # FPing Tests via check_fping
7 use strict;
8 use Test;
9 use NPTest;
11 use vars qw($tests);
13 BEGIN {$tests = 4; plan tests => $tests}
15 my $successOutput = '/^FPING OK - /';
16 my $failureOutput = '/^FPING CRITICAL - /';
18 my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
19 "The hostname of system responsive to network requests" );
21 my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
22 "The hostname of system not responsive to network requests" );
24 my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
25 "An invalid (not known to DNS) hostname" );
28 my $t;
30 my $fping = qx(which fping 2> /dev/null);
31 chomp($fping);
32 if( ! -x "./check_fping") {
33 $t += skipMissingCmd( "./check_fping", $tests );
35 elsif ( $> != 0 && (!$fping || ! -u $fping)) {
36 $t += skipMsg( "./check_fping", $tests );
37 } else {
38 $t += checkCmd( "./check_fping $host_responsive", 0, $successOutput );
39 $t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] );
40 $t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] );
43 exit(0) if defined($Test::Harness::VERSION);
44 exit($tests - $t);