New UUCP queue check
authorJoey Schulze <joey@infodrom.org>
Mon, 28 Apr 2014 18:53:40 +0000 (20:53 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 28 Apr 2014 18:53:40 +0000 (20:53 +0200)
check_uucp [new file with mode: 0755]

diff --git a/check_uucp b/check_uucp
new file mode 100755 (executable)
index 0000000..bf8ca52
--- /dev/null
@@ -0,0 +1,101 @@
+#! /usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+use lib '/usr/lib/nagios/plugins';
+use utils qw(%ERRORS &print_revision &support);
+
+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 'H=s' => \$host,
+    '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<<EOT;
+help
+EOT
+    exit $ERRORS{'OK'};
+}
+
+sub uustat
+{
+    my $host = shift;
+    my $hours = shift;
+
+    my $cmd = sprintf('/usr/bin/uustat -s %s %s', $host,
+                     $hours ? '-o ' . $hours : '');
+
+    open my $prg, '|-', $cmd || return;
+    my @list;
+    while (<$prg>) {
+       push @list, $_;
+    }
+    close $prg;
+
+    return \@list;
+}
+
+unless ($host) {
+    print "UUCP ERROR: -h <hostname> 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, 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'};