#! /usr/bin/perl -w # Copyright (c) 2014 Joey Schulze # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA use strict; use Getopt::Long; use lib '/usr/lib/nagios/plugins'; use utils qw(%ERRORS); my $config = { 'host' => undef, 'warn_jobs' => 50, 'crit_jobs' => 150, 'warn_hours' => 24, 'crit_hours' => 72, }; my $host; Getopt::Long::Configure('no_ignore_case'); GetOptions 'host|h=s' => \$host, 'warn=s' => \$config->{warn_jobs}, 'crit=s' => \$config->{crit_jobs}, 'WARN=s' => \$config->{warn_hours}, 'CRIT=s' => \$config->{crit_hours}, 'help' => \&print_help; sub print_help { print<) { push @list, $_; } close $prg; return \@list; } unless ($host) { print "UUCP ERROR: -h missing\n"; exit $ERRORS{CRITICAL}; } my $list = uustat $host; unless (defined $list) { printf "UUCP CRITICAL - %s: Execution of uustat failed\n", $host; exit $ERRORS{CRITICAL}; } if (scalar @$list > $config->{warn_jobs}) { printf "UUCP WARNING - %s: %d jobs\n", $host, scalar @$list; exit $ERRORS{WARNING}; } if (scalar @$list > $config->{crit_jobs}) { printf "UUCP CRITICAL - %s: %d jobs\n", $host, scalar @$list; exit $ERRORS{CRITICAL}; } my $oldlist; $oldlist = uustat $host, $config->{warn_hours}; unless (defined $oldlist) { printf "UUCP WARNING - %s: Execution of uustat failed\n", $host; exit $ERRORS{WARNING}; } if (scalar @$oldlist > 0) { printf "UUCP WARNING - %s: %d jobs older than %d hours\n", $host, scalar @$list, $config->{crit_hours}; exit $ERRORS{WARNING}; } $oldlist = uustat $host, $config->{crit_hours}; unless (defined $oldlist) { printf "UUCP WARNING - %s: Execution of uustat failed\n", $host; exit $ERRORS{WARNING}; } if (scalar @$oldlist > 0) { printf "UUCP CRITICAL - %s: %d jobs older than %d hours\n", $host, scalar @$list, $config->{crit_hours}; exit $ERRORS{CRITICAL}; } printf "UUCP OK - %s: %d jobs\n", $host, scalar @$list; exit $ERRORS{'OK'};