forked from glensc/monitoring-plugin-check_amavis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_amavis.pl
executable file
·94 lines (80 loc) · 1.82 KB
/
check_amavis.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl
# Downloaded from exchange.nagios.org
# URL: https://exchange.nagios.org/directory/Plugins/Anti-2DVirus/Amavis/check_amavis/details
#
# Maintained later on by Elan Ruusamäe <[email protected]>
# https://github.com/glensc/monitoring-plugin-check_amavis
use Getopt::Long;
use MIME::Entity;
use Net::SMTP;
use strict;
use warnings;
my $server = '';
my $port = 10024;
my $from = '';
my $to = '';
my $debug = 0;
my $timeout = 15;
my %STATES = (
"OK" => 0,
"WARNING" => 1,
"CRITICAL" => 2,
"UNKNOWN" => 3,
"DEPENDENT" => 4,
);
GetOptions (
"server|s=s" => \$server,
"port|p=s" => \$port,
"from|f=s" => \$from,
"timeout=s" => \$timeout,
"debug|d" => \$debug,
"to|t=s" => \$to,
);
if (!$server || !$from) {
print "ERROR: Please specify --server, --from\n";
exit $STATES{UNKNOWN};
}
if (!$to) {
$to = $from;
}
my $EICAR = <<'EOF';
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
EOF
my $top = MIME::Entity->build(
Type => "multipart/mixed",
From => $from,
To => $to,
Subject => "EICAR test",
Data => "This is a test",
);
$top->attach(
Data => $EICAR,
Type => "application/x-msdos-program",
Encoding => "base64",
);
my $smtp = new Net::SMTP(
$server,
Port => $port,
Debug => $debug,
Timeout => $timeout,
);
if (!$smtp) {
print "CRITICAL - amavisd-new server unreachable\n";
exit $STATES{CRITICAL};
}
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend($top->stringify);
$smtp->dataend();
my $result = $smtp->message();
$smtp->close();
warn "RESULT[$result]\n" if $debug;
# <<< 250 2.5.0 Ok, id=21563-09, BOUNCE
if ($result =~ /2\.7\.[01] Ok,/ && $result =~ /discarded|BOUNCE/) {
print "OK - All fine\n";
exit $STATES{OK};
} else {
print "CRITICAL - amavisd-new returned $result\n";
exit $STATES{CRITICAL};
}