Code

Added examples for new features to check_disk
[nagiosplug.git] / plugins-scripts / check_mailq.pl
index aaec2515c8379b8e1646600c17bd21f2fe999eb7..c676e41a1ac6a3b78d2447d90a1ad427dcf02dbf 100755 (executable)
@@ -22,6 +22,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
+# $Id$
+#
 ############################################################################
 
 use POSIX;
@@ -171,7 +173,7 @@ if ($mailq eq "sendmail") {
                    # multi queue: one for each queue. overwrite on multi queue below
                  $msg_q = $1 ;
                        }
-               } elsif (/^\s+Total\sRequests:\s(\d+)$/) {
+               } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
                        print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
                        #
                        # multi queue: last line
@@ -184,12 +186,10 @@ if ($mailq eq "sendmail") {
        ## close mailq
 
        close (MAILQ); 
-       # declare an error if we also get a non-zero return code from mailq
-       # unless already set to critical
+
        if ( $? ) {
-               $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"}  ;
-               print "STDERR $?: $!\n" if $verbose;
-               $msg = "$state: (stderr)\n";
+               print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+               exit $ERRORS{CRITICAL};
        }
 
        ## shut off the alarm
@@ -316,12 +316,10 @@ elsif ( $mailq eq "postfix" ) {
 
         # close qmail-qstat
         close MAILQ;
-        # declare an error if we also get a non-zero return code from mailq
-        # unless already set to critical
+
         if ( $? ) {
-                $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"}  ;
-                print "STDERR $?: $!\n" if $verbose;
-                $msg = "$state: (stderr)\n";
+               print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+               exit $ERRORS{CRITICAL};
         }
 
         ## shut off the alarm
@@ -399,12 +397,10 @@ elsif ( $mailq eq "qmail" ) {
 
        # close qmail-qstat
        close MAILQ;
-       # declare an error if we also get a non-zero return code from mailq
-       # unless already set to critical
+
        if ( $? ) {
-               $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"}  ;
-               print "STDERR $?: $!\n" if $verbose;
-               $msg = "$state: (stderr)\n";
+               print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+               exit $ERRORS{CRITICAL};
        }
 
        ## shut off the alarm
@@ -488,6 +484,11 @@ elsif ( $mailq eq "exim" ) {
            }
        }
        close(MAILQ) ;
+
+       if ( $? ) {
+               print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+               exit $ERRORS{CRITICAL};
+       }
        if ($msg_q < $opt_w) {
                $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
                $state = $ERRORS{'OK'};
@@ -517,8 +518,6 @@ sub process_arguments(){
                 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default     sendmail)
                 "w=i" => \$opt_w, "warning=i"  => \$opt_w,   # warning if above this number
                 "c=i" => \$opt_c, "critical=i" => \$opt_c,       # critical if above this number
-                "W=i" => \$opt_W, "Warning=i"  => \$opt_W,   # warning if above this number
-                "C=i" => \$opt_C, "Critical=i" => \$opt_C,       # critical if above this number
                 "t=i" => \$opt_t, "timeout=i"  => \$opt_t 
                 );