Code

Removing CVS/SVN tags and replacing with git-based versioning
[nagiosplug.git] / plugins / t / check_smtp.t
1 #! /usr/bin/perl -w -I ..
2 #
3 # Simple Mail Transfer Protocol (SMTP) Test via check_smtp
4 #
5 #
7 use strict;
8 use Test::More;
9 use NPTest;
11 my $host_tcp_smtp      = getTestParameter( "NP_HOST_TCP_SMTP", 
12                                            "A host providing an SMTP Service (a mail server)", "mailhost");
13 my $host_tcp_smtp_tls  = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
14                                            "A host providing SMTP with TLS", $host_tcp_smtp);
15 my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS",
16                                            "A host providing SMTP without TLS", "");
18 my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 
19                                            "The hostname of system not responsive to network requests", "10.0.0.1" );
21 my $hostname_invalid   = getTestParameter( "NP_HOSTNAME_INVALID",   
22                                            "An invalid (not known to DNS) hostname", "nosuchhost" );
23 my $res;
25 plan tests => 10;
27 SKIP: {
28         skip "No SMTP server defined", 4 unless $host_tcp_smtp;
29         $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
30         is ($res->return_code, 0, "OK");
31         
32         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
33         is ($res->return_code, 0, "OK, within 9 second response");
35         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
36         is ($res->return_code, 0, "OK, old syntax");
38         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
39         is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
41         TODO: {
42                 local $TODO = "Output is over two lines";
43                 like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
44         }
45 }
47 SKIP: {
48         skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
49         # SSL connection for TLS
50         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" );
51         is ($res->return_code, 0, "OK, with STARTTLS" );
52 }
54 SKIP: {
55         skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls;
56         $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" );
57         is ($res->return_code, 1, "OK, got warning from server without TLS");
58         is ($res->output, "WARNING - TLS not supported by server", "Right error message" );
59 }
61 $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
62 is ($res->return_code, 2, "CRITICAL - host non responding" );
64 $res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
65 is ($res->return_code, 3, "UNKNOWN - hostname invalid" );