-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_postfix_queue
More file actions
executable file
·102 lines (87 loc) · 2.77 KB
/
check_postfix_queue
File metadata and controls
executable file
·102 lines (87 loc) · 2.77 KB
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
95
96
97
98
99
100
101
102
#!/usr/bin/perl
# Author: Dennis Lichtenthaeler <dennis.lichtenthaeler@episode-iv.de>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use Getopt::Long;
use File::Find;
use File::Spec;
use lib '/usr/lib64/nagios/plugins'; ## change this to the folder containing "utils.pm"
use utils;
my $queuedir = "/var/spool/postfix";
my $help = 0;
my $warning = 20;
my $critical = 50;
my $result = GetOptions (
"queuedir|d=s" => \$queuedir,
"warning|w=i" => \$warning,
"critical|c=i" => \$critical,
"help|h" => \$help,
);
if ($help) {
print qq~$0
Check postfix queue folders for e-mails (i.e. files)
The following optional parameters exist:
--queuedir (default $queuedir)
Use an alternative postfix queue directory
--warning (default $warning)
Warn if at least one queue directory contains more than n messages
--critical (default $critical)
Cry in pain if at leastone queue directory contains more than n messages
--help
Show this
~;
exit;
}
if (!-d $queuedir) {
print "UNKNOWN: $queuedir is not a directory\n";
exit $utils::ERRORS{'UNKNOWN'};
}
my %stats;
for my $queue ( "deferred","active","maildrop","incoming","corrupt","hold") {
my $dir = File::Spec->join($queuedir, $queue);
if (-d $dir) {
$stats{$queue} = 0;
find ({
wanted => sub { $stats{$queue}++ if (-f $_) },
no_chdir => 1,
}, $dir);
}
}
my $state = $utils::ERRORS{'OK'};
my @perfdata;
for (sort(keys(%stats))) {
if ($stats{$_} > $warning && $state < $utils::ERRORS{'WARNING'}) {
$state = $utils::ERRORS{'WARNING'};
}
if ($stats{$_} > $critical && $state < $utils::ERRORS{'CRITICAL'}) {
$state = $utils::ERRORS{'CRITICAL'};
}
push(@perfdata, $_."=".$stats{$_});
}
if ($state == $utils::ERRORS{'OK'}) {
print "OK: queues look good|".join(" ", @perfdata)."\n";
exit $utils::ERRORS{'OK'};
}
elsif ($state == $utils::ERRORS{'WARNING'}) {
print "WARNING: one or more queues are filling up|".join(" ", @perfdata)."\n";
exit $utils::ERRORS{'WARNING'};
}
elsif ($state == $utils::ERRORS{'CRITICAL'}) {
print "CRITICAL: one or more queues seem to be clogged|".join(" ", @perfdata)."\n";
exit $utils::ERRORS{'CRITICAL'};
}
else {
print "UNKNOWN: Something went wrong\n";
exit $utils::ERRORS{'UNKNOWN'};
}