Fixed typo in check_disk
[monitoring-plugins.git] / contrib / check_qmailq.pl
blob4c3f68ff3d9dd59b943eaf743e43270b65546e4a
1 #!/usr/bin/perl
3 # check_qmailq.pl - nagios plugin
4 # This plugin allows you to check the number of Mails in a qmail-
5 # queue. PLUGIN NEEDS CONFIGURATION ! (see below)
7 # Copyright 2000 Benjamin Schmid
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 # Emergency E-Mail :) blueshift@gmx.net
27 ### CONFIGURATION SECTION ####################
29 my $statcommand = "/var/qmail/bin/qmail-qstat";
30 my $queuewarn = 5; # Warning, if more than x mail in Queue
31 my $queuecrit = 10; # Critical if "--"
32 my $prewarn = 1; # Warning, if more than x unhandled mails
33 # (not in Queue
34 my $precrit = 5; # Critical, if "--"
36 ### CONFIURATION SECTION END ################
38 use strict;
39 use Carp;
41 #use Getopt::Long;
42 #&Getopt::Long::config('auto_abbrev');
46 my $TIMEOUT = 15;
48 my %ERRORS = ('UNKNOWN' , '-1',
49 'OK' , '0',
50 'WARNING', '1',
51 'CRITICAL', '2');
53 my $state = "UNKNOWN";
54 my $answer = "";
56 #sub usage {
57 # printf "\nMissing arguments!\n";
58 # printf "\n";
59 # printf "Printer Server Queue Nagios Plugin\n";
60 # printf "monitors jobs in lpr queues\n";
61 # printf "usage: \n";
62 # printf "check_lpq.pl \n";
63 # printf "Copyright (C) 2000 Benjamin Schmid\n";
64 # printf "check_lpq.pl comes with ABSOLUTELY NO WARRANTY\n";
65 # printf "This programm is licensed under the terms of the ";
66 # printf "GNU General Public License\n(check source code for details)\n";
67 # printf "\n\n";
68 # exit $ERRORS{"UNKNOWN"};
71 # Just in case of problems, let's not hang Nagios
72 $SIG{'ALRM'} = sub {
73 print ("ERROR: check_lpq.pl Time-Out $TIMEOUT s \n");
74 exit $ERRORS{"UNKNOWN"};
76 alarm($TIMEOUT);
79 #$status = GetOptions("community=s",\$community,
80 # "port=i",\$port);
81 #if ($status == 0)
83 # &usage;
86 # $hostname = shift || &usage;
88 if (! open STAT, "$statcommand|") {
89 print ("$state: $statcommand returns no result!");
90 exit $ERRORS{$state};
92 my @lines = <STAT>;
93 close STAT;
95 # Mails in Queues
96 if ($lines[0]=~/^messages in queue: (\d+)/) {
97 my $anzq = $1;
98 $answer = $answer . "$anzq";
99 $state='WARNING' if ($anzq >= $queuewarn);
100 $state='CRITICAL' if ($anzq >= $queuecrit);
101 } else {
102 $state='CRITICAL';
103 $answer="Keine gueltigte Antwort (Zeile #1) von $statcommand\n";
106 # Unverarbeite Mails
107 if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
108 my $anzp = $1;
109 $answer = $answer . " E-Mail(s) nicht ausgeliefert, $anzp unverarbeitet.";
110 $state='WARNING' if ($anzp >= $prewarn && $state eq 'UNKNOWN');
111 $state='CRITICAL' if ($anzp >= $precrit);
112 } else {
113 $state='CRITICAL';
114 $answer=$answer . "Keine gueltigte Antwort (Zeile #2) von $statcommand\n";
117 $state = 'OK' if ($state eq 'UNKNOWN');
119 print ("$state: $answer\n");
120 exit $ERRORS{$state};