check_qmailq.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/perl
  2. #
  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)
  6. #
  7. # Copyright 2000 Benjamin Schmid
  8. #
  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.
  13. #
  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.
  18. #
  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.
  22. #
  23. #
  24. # Emergency E-Mail :) blueshift@gmx.net
  25. #
  26. ### CONFIGURATION SECTION ####################
  27. my $statcommand = "/var/qmail/bin/qmail-qstat";
  28. my $queuewarn = 5; # Warning, if more than x mail in Queue
  29. my $queuecrit = 10; # Critical if "--"
  30. my $prewarn = 1; # Warning, if more than x unhandled mails
  31. # (not in Queue
  32. my $precrit = 5; # Critical, if "--"
  33. ### CONFIURATION SECTION END ################
  34. use strict;
  35. use Carp;
  36. #use Getopt::Long;
  37. #&Getopt::Long::config('auto_abbrev');
  38. my $TIMEOUT = 15;
  39. my %ERRORS = ('UNKNOWN' , '-1',
  40. 'OK' , '0',
  41. 'WARNING', '1',
  42. 'CRITICAL', '2');
  43. my $state = "UNKNOWN";
  44. my $answer = "";
  45. #sub usage {
  46. # printf "\nMissing arguments!\n";
  47. # printf "\n";
  48. # printf "Printer Server Queue Nagios Plugin\n";
  49. # printf "monitors jobs in lpr queues\n";
  50. # printf "usage: \n";
  51. # printf "check_lpq.pl \n";
  52. # printf "Copyright (C) 2000 Benjamin Schmid\n";
  53. # printf "check_lpq.pl comes with ABSOLUTELY NO WARRANTY\n";
  54. # printf "This programm is licensed under the terms of the ";
  55. # printf "GNU General Public License\n(check source code for details)\n";
  56. # printf "\n\n";
  57. # exit $ERRORS{"UNKNOWN"};
  58. #}
  59. # Just in case of problems, let's not hang Nagios
  60. $SIG{'ALRM'} = sub {
  61. print ("ERROR: check_lpq.pl Time-Out $TIMEOUT s \n");
  62. exit $ERRORS{"UNKNOWN"};
  63. };
  64. alarm($TIMEOUT);
  65. #$status = GetOptions("community=s",\$community,
  66. # "port=i",\$port);
  67. #if ($status == 0)
  68. #{
  69. # &usage;
  70. #}
  71. # $hostname = shift || &usage;
  72. if (! open STAT, "$statcommand|") {
  73. print ("$state: $statcommand returns no result!");
  74. exit $ERRORS{$state};
  75. }
  76. my @lines = <STAT>;
  77. close STAT;
  78. # Mails in Queues
  79. if ($lines[0]=~/^messages in queue: (\d+)/) {
  80. my $anzq = $1;
  81. $answer = $answer . "$anzq";
  82. $state='WARNING' if ($anzq >= $queuewarn);
  83. $state='CRITICAL' if ($anzq >= $queuecrit);
  84. } else {
  85. $state='CRITICAL';
  86. $answer="Keine gueltigte Antwort (Zeile #1) von $statcommand\n";
  87. }
  88. # Unverarbeite Mails
  89. if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
  90. my $anzp = $1;
  91. $answer = $answer . " E-Mail(s) nicht ausgeliefert, $anzp unverarbeitet.";
  92. $state='WARNING' if ($anzp >= $prewarn && $state eq 'UNKNOWN');
  93. $state='CRITICAL' if ($anzp >= $precrit);
  94. } else {
  95. $state='CRITICAL';
  96. $answer=$answer . "Keine gueltigte Antwort (Zeile #2) von $statcommand\n";
  97. }
  98. $state = 'OK' if ($state eq 'UNKNOWN');
  99. print ("$state: $answer\n");
  100. exit $ERRORS{$state};