Prepare for the 2.2 release
[monitoring-plugins.git] / plugins / t / check_ssh.t
blob800834925f8d2c2c5279c5ddd13adaf2b7bd03b0
1 #! /usr/bin/perl -w -I ..
3 # check_ssh tests
7 use strict;
8 use Test::More;
9 use NPTest;
11 # Required parameters
12 my $ssh_host = getTestParameter("NP_SSH_HOST",
13 "A host providing SSH service",
14 "localhost");
16 my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE",
17 "The hostname of system not responsive to network requests",
18 "10.0.0.1" );
20 my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID",
21 "An invalid (not known to DNS) hostname",
22 "nosuchhost" );
25 plan skip_all => "SSH_HOST must be defined" unless $ssh_host;
26 plan tests => 6;
29 my $result = NPTest->testCmd(
30 "./check_ssh -H $ssh_host"
32 cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
33 like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)");
36 $result = NPTest->testCmd(
37 "./check_ssh -H $host_nonresponsive -t 2"
39 cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)");
40 like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)");
44 $result = NPTest->testCmd(
45 "./check_ssh -H $hostname_invalid -t 2"
47 cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)");
48 like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)");