]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/asterisk/pbx-daemon/nagios_plugins/check_asterisk_spool.pl
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[Evergreen.git] / Open-ILS / src / asterisk / pbx-daemon / nagios_plugins / check_asterisk_spool.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Getopt::Std;
6
7 my %result_names = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3);
8
9 sub result {
10     my ($result_name, $msg) = @_;
11
12     my $code = $result_names{$result_name};
13
14     printf("ASTSPOOL %s - %s\n", $result_name, $msg);
15     exit($code);
16 }
17
18 ####### main
19 # command-line options:
20 # c is for count. more than this number of files
21 #   in the directory means a critical status. less is ok. there is no warning.
22 # d is for directory.
23
24 my (%opts) = (
25     "c" => 8,
26     "d" => "/var/spool/asterisk/outgoing"
27 );
28
29 getopts("c:d:", \%opts);
30
31 opendir DIR, $opts{d} or result("UNKNOWN", "$opts{d}: $!");
32 my $count = grep { $_ ne '.' && $_ ne '..' } (readdir DIR);
33 closedir DIR;
34
35 if ($count > $opts{c}) {
36     result("CRITICAL", "$count file(s) in $opts{d}");
37 } else {
38     result("OK", "$count file(s) in $opts{d}");
39 }