equal
deleted
inserted
replaced
|
1 #! /usr/bin/perl |
|
2 |
|
3 #use 5.10.0; |
|
4 use strict; |
|
5 use warnings; |
|
6 use Pod::Usage; |
|
7 use Getopt::Long; |
|
8 use Nagios; |
|
9 |
|
10 my $fs; |
|
11 |
|
12 delete @ENV{grep /^(LC_|LANG)/, keys %ENV}; |
|
13 |
|
14 GetOptions( |
|
15 "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, |
|
16 "m|man" => sub { |
|
17 pod2usage( |
|
18 -exit => 0, |
|
19 -verbose => 2, |
|
20 -noperldoc => system("perldoc -V 2>/dev/null 1>&2") |
|
21 ); |
|
22 }, |
|
23 ) |
|
24 and defined($fs = shift) |
|
25 or pod2usage; |
|
26 |
|
27 my @df = $ENV{HARNESS_ACTIVE} ? <STDIN> : `df -P -B 1K '$fs'`; |
|
28 |
|
29 ($fs, my ($blocks, $used, $avail, undef, $mp)) = split " " => $df[1]; |
|
30 |
|
31 if (not defined $avail or not defined $blocks or $blocks == 0) { |
|
32 print "FS UNKNOWN - can't determine values for $fs\n"; |
|
33 exit Nagios::UNKNOWN; |
|
34 } |
|
35 |
|
36 my $ratio = int(100 * ($avail / $blocks)); |
|
37 my $msg = "$fs on $mp: left ${avail}kB of ${blocks}kB ($ratio%)"; |
|
38 if ($ratio > 30) { print "FS OK - $msg\n"; exit Nagios::OK } |
|
39 if ($ratio > 10) { print "FS WARN - $msg\n"; exit Nagios::WARNING } |
|
40 |
|
41 print "FS CRIT - $msg ($ratio%)\n"; |
|
42 exit Nagios::CRITICAL; |
|
43 |
|
44 __END__ |
|
45 |
|
46 =head1 NAME |
|
47 |
|
48 checkfs - check the current file system |
|
49 |
|
50 =head1 SYNOPSIS |
|
51 |
|
52 checkfs [-h|--help] |
|
53 checkfs [-m|--man] |
|
54 checkfs <filesystem> |
|
55 |
|
56 =head1 DESCRIPTION |
|
57 |
|
58 B<checkfs> checks the filesystem. |
|
59 |
|
60 =head1 OPTIONS |
|
61 |
|
62 =over 4 |
|
63 |
|
64 =item B<-h>|B<--help> |
|
65 |
|
66 =item B<-m>|B<--man> |
|
67 |
|
68 The usual help messages; |
|
69 |
|
70 =back |