equal
deleted
inserted
replaced
|
1 #! /usr/bin/perl |
|
2 use 5.8.8; |
|
3 use strict; |
|
4 use warnings; |
|
5 use Pod::Usage; |
|
6 use Getopt::Long; |
|
7 use Nagios; |
|
8 use Switch; |
|
9 |
|
10 my $file; |
|
11 my $fs; |
|
12 my $ismp; |
|
13 my $isblocks; |
|
14 my $isavail; |
|
15 my $ispct; |
|
16 |
|
17 my $opt_input = undef; |
|
18 |
|
19 GetOptions( |
|
20 "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, |
|
21 "m|man" => sub { |
|
22 pod2usage( |
|
23 -exit => 0, |
|
24 -verbose => 2, |
|
25 -noperldoc => system("perldoc -V 2>/dev/null 1>&2") |
|
26 ); |
|
27 }, |
|
28 "i|input=s" => \$opt_input, |
|
29 ) and $fs = shift || pod2usage; |
|
30 |
|
31 if (defined $opt_input) { |
|
32 my @line = split(/ /, $opt_input); |
|
33 $fs = $line[0]; |
|
34 $isblocks = $line[1]; |
|
35 $isavail = $line[3]; |
|
36 $ispct = $line[4]; |
|
37 $ismp = $line[5]; |
|
38 } |
|
39 else |
|
40 { |
|
41 ($fs, my ($blocks, $used, $avail, $pct, $mp)) = |
|
42 split " " => (`df -P -B 1K $fs`)[1]; |
|
43 $isblocks = $blocks; |
|
44 $isavail = $avail; |
|
45 $ismp = $mp; |
|
46 $ispct = $pct; |
|
47 } |
|
48 my $msg = "$fs on $ismp: left ${isavail}kB of ${isblocks}kB ($ispct)"; |
|
49 |
|
50 my $aval = $isavail / $isblocks; |
|
51 if ($aval < 0.1) { print "FS CRIT - $msg\n"; exit Nagios::CRITICAL } |
|
52 if ($aval < 0.3) { print "FS WARN - $msg\n"; exit Nagios::WARNING } |
|
53 if ($aval >= 0.3) { print "FS OK - $msg\n"; exit Nagios::OK } |
|
54 |
|
55 __END__ |
|
56 |
|
57 =head1 NAME |
|
58 |
|
59 checkfs - check the current file system |
|
60 |
|
61 =head1 SYNOPSIS |
|
62 |
|
63 checkfs [-h|--help] |
|
64 checkfs [-m|--man] |
|
65 checkfs [-i|--input] |
|
66 checkfs <filesystem> |
|
67 |
|
68 =head1 DESCRIPTION |
|
69 |
|
70 B<checkfs> checks the filesystem. |
|
71 |
|
72 =head1 OPTIONS |
|
73 |
|
74 =over 4 |
|
75 |
|
76 =item B<-h>|B<--help> |
|
77 |
|
78 =item B<-m>|B<--man> |
|
79 |
|
80 =item B<-i>|B<--input> |
|
81 |
|
82 The usual help messages; |
|
83 |
|
84 =back |
|
85 |
|
86 |
|
87 |