2 $ID = q$Id: check_afsspace,v 1.16 2006/03/17 23:06:54 quanah Exp $;
4 # check_afsspace -- Monitor AFS disk space usage under Nagios.
6 # Written by Susan Feng <sfeng@stanford.edu>
7 # Updated by Russ Allbery <rra@stanford.edu>
8 # Copyright 2003, 2004 Board of Trustees, Leland Stanford Jr. University
10 # This program is free software; you may redistribute it and/or modify it
11 # under the same terms as Perl itself.
13 # Expects a host with the -H option and checks the partition usage with
14 # vos partinfo. Exits with status 1 if the free space is below a warning
15 # percentage and with status 2 if the free space is above a critical
16 # percentage (this works with the Nagios check architecture).
18 ##############################################################################
20 ##############################################################################
22 # The default percentage full at which to warn and at which to send a critical
23 # alert. These can be overridden with the -w and -c command-line options.
27 # The default timeout in seconds (implemented by alarm) for vos partinfo.
30 # The full path to vos. Make sure that this is on local disk so that
31 # monitoring doesn't have an AFS dependency.
32 ($VOS) = grep { -x $_ } qw(/usr/bin/vos /usr/local/bin/vos);
33 $VOS ||= '/usr/bin/vos';
35 ##############################################################################
36 # Modules and declarations
37 ##############################################################################
42 use vars qw($CRITICAL $ID $TIMEOUT $VOS $WARNINGS);
44 use Getopt::Long qw(GetOptions);
46 ##############################################################################
48 ##############################################################################
50 # Parse command line options.
51 my ($help, $host, $version);
52 Getopt::Long::config ('bundling', 'no_ignore_case');
53 GetOptions ('critical|c=i' => \$CRITICAL,
54 'hostname|H=s' => \$host,
56 'timeout|t=i' => \$TIMEOUT,
57 'version|V' => \$version,
58 'warning|w=i' => \$WARNINGS) or exit 3;
60 print "Feeding myself to perldoc, please wait....\n";
61 exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
63 my $version = join (' ', (split (' ', $ID))[1..3]);
65 $version =~ s/(\S+)$/($1)/;
71 warn "Usage: $0 [-hv] [-c <level>] [-w <level>] -H <host>\n";
74 if ($WARNINGS > $CRITICAL) {
75 warn "$0: warning level $WARNINGS greater than critical level $CRITICAL\n";
81 print "AFS CRITICAL - network timeout after $TIMEOUT seconds\n";
86 # Get the partinfo information and calculate the percentage free for each
87 # partition. Accumulate critical messages in @critical and warnings in
88 # @warnings. Accumulate all percentages in @all.
89 my (@critical, @warnings, @all);
90 my @data = `$VOS partinfo '$host' 2> /dev/null`;
92 print "AFS CRITICAL - cannot contact server\n";
96 my ($partition, $free, $total) = (split)[4,5,11];
97 my $percent = int ((($total - $free) / $total) * 100);
98 if ($percent >= $CRITICAL) {
99 push (@critical, "$partition$percent% (free $free)");
100 } elsif ($percent >= $WARNINGS) {
101 push (@warnings, "$partition$percent% (free $free)");
103 push (@all, "$partition$percent%");
106 # Exit with the appropriate error messages.
108 print "AFS CRITICAL - @critical\n";
110 } elsif (@warnings) {
111 print "AFS WARNING - @warnings\n";
114 print "AFS OK - @all\n";
118 ##############################################################################
120 ##############################################################################
124 check_afsspace - Monitor AFS disk space usage under Nagios
128 check_afsspace [B<-hV>] [B<-c> I<threshold>] [B<-w> I<threshold>]
129 [B<-t> I<timeout>] B<-H> I<host>
133 B<check_afsspace> is a Nagios plugin for checking free space on AFS server
134 partitions. It uses C<vos partinfo> to obtain the free space on the
135 partitions on an AFS server and will return an alert if the percentage of
136 used space exceeds a threshold. By default, it returns a critical error if
137 the used space is over 90% and a warning if it is over 85% (changable with
138 the B<-c> and B<-w> options).
140 B<check_afsspace> will always print out a single line of output, giving the
141 critical errors if any, otherwise giving the warnings if any, otherwise
142 listing in an abbreviated form the percentage free space for all partitions.
148 =item B<-c> I<threshold>, B<--critical>=I<threshold>
150 Change the critical percentage threshold to I<threshold>, which should be an
151 integer percentage. The default is 90.
153 =item B<-H> I<host>, B<--hostname>=I<host>
155 The AFS file server whose free space B<check_afsspace> should check. This
158 =item B<-h>, B<--help>
160 Print out this documentation (which is done simply by feeding the script
163 =item B<-t> I<timeout>, B<--timeout>=I<timeout>
165 Change the timeout for the C<vos partinfo> command. The default timeout is
168 =item B<-V>, B<--version>
170 Print out the version of B<check_afsspace> and quit.
172 =item B<-w> I<threshold>, B<--warning>=I<threshold>
174 Change the warning percentage threshold to I<threshold>, which should be an
175 integer percentage. The default is 85.
181 B<check_afsspace> follows the standard Nagios exit status requirements.
182 This means that it will exit with status 0 if there are no problems, with
183 status 2 if there is at least one critical partition for that server, and
184 with status 1 if there are no critical partitions but at least one warning
185 partition. For other errors, such as invalid syntax, B<check_afsspace> will
190 The standard B<-v> verbose Nagios plugin option is not supported and should
191 be. (For example, under B<-vv> we would want to show the actual total,
192 free, and used byte counts, not just the percentages.)
194 The usage message for invalid options and for the B<-h> option doesn't
195 conform to Nagios standards.
199 This script does not use the Nagios util library or any of the defaults that
200 it provides, which makes it somewhat deficient as a Nagios plugin. This is
201 intentional, though, since this script can be used with other monitoring
202 systems as well. It's not clear what a good solution to this would be.
208 The current version of this and other AFS monitoring plugins for Nagios are
209 available from the AFS monitoring tools page at
210 L<http://www.eyrie.org/~eagle/software/afs-monitor/>.
214 Originally written by Susan Feng for use with mon. Updated by Quanah
215 Gibson-Mount to work with Nagios, and then further updated by Russ Allbery
216 <rra@stanford.edu> to support more standard options and to use a more
217 uniform coding style.
219 =head1 COPYRIGHT AND LICENSE
221 Copyright 2003, 2004 Board of Trustees, Leland Stanford Jr. University.
223 This program is free software; you may redistribute it and/or modify it
224 under the same terms as Perl itself.