New UUCP queue check
[infodrom/icinga-plugins] / check_uucp
1 #! /usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5 use lib '/usr/lib/nagios/plugins';
6 use utils qw(%ERRORS &print_revision &support);
7
8 my $config = {
9     'host' => undef,
10     'warn_jobs' => 50,
11     'crit_jobs' => 150,
12     'warn_hours' => 24,
13     'crit_hours' => 72,
14
15 };
16
17 my $host;
18 Getopt::Long::Configure('no_ignore_case');
19 GetOptions 'H=s' => \$host,
20     'host|h=s' => \$host,
21     'warn=s' => \$config->{warn_jobs},
22     'crit=s' => \$config->{crit_jobs},
23     'WARN=s' => \$config->{warn_hours},
24     'CRIT=s' => \$config->{crit_hours},
25     'help' => \&print_help;
26
27 sub print_help
28 {
29     print<<EOT;
30 help
31 EOT
32     exit $ERRORS{'OK'};
33 }
34
35 sub uustat
36 {
37     my $host = shift;
38     my $hours = shift;
39
40     my $cmd = sprintf('/usr/bin/uustat -s %s %s', $host,
41                       $hours ? '-o ' . $hours : '');
42
43     open my $prg, '|-', $cmd || return;
44     my @list;
45     while (<$prg>) {
46         push @list, $_;
47     }
48     close $prg;
49
50     return \@list;
51 }
52
53 unless ($host) {
54     print "UUCP ERROR: -h <hostname> missing\n";
55     exit $ERRORS{CRITICAL};
56 }
57
58 my $list = uustat $host;
59
60 unless (defined $list) {
61     printf "UUCP CRITICAL - %s: Execution of uustat failed\n", $host;
62     exit $ERRORS{CRITICAL};
63 }
64
65 if (scalar @$list > $config->{warn_jobs}) {
66     printf "UUCP WARNING - %s: %d jobs\n", $host, scalar @$list;
67     exit $ERRORS{WARNING};
68 }
69
70 if (scalar @$list > $config->{crit_jobs}) {
71     printf "UUCP CRITICAL - %s: %d jobs\n", $host, scalar @$list;
72     exit $ERRORS{CRITICAL};
73 }
74
75 my $oldlist;
76 $oldlist = uustat $host, $config->{warn_hours};
77
78 unless (defined $oldlist) {
79     printf "UUCP WARNING - %s: Execution of uustat failed\n", $host;
80     exit $ERRORS{WARNING};
81 }
82
83 if (scalar @$oldlist > 0) {
84     printf "UUCP WARNING - %s: %d jobs older than %d hours\n", $host, scalar @$list, scalar @$list, $config->{crit_hours};
85     exit $ERRORS{WARNING};
86 }
87
88 $oldlist = uustat $host, $config->{crit_hours};
89
90 unless (defined $oldlist) {
91     printf "UUCP WARNING - %s: Execution of uustat failed\n", $host;
92     exit $ERRORS{WARNING};
93 }
94
95 if (scalar @$oldlist > 0) {
96     printf "UUCP CRITICAL - %s: %d jobs older than %d hours\n", $host, scalar @$list, $config->{crit_hours};
97     exit $ERRORS{CRITICAL};
98 }
99
100 printf "UUCP OK - %s: %d jobs\n", $host, scalar @$list;
101 exit $ERRORS{'OK'};