diff options
author | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-08-14 19:00:17 +0000 |
---|---|---|
committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-08-14 19:00:17 +0000 |
commit | 9e3002c652b8e2e59f99e115e458c3f3bc738d59 (patch) | |
tree | cfe5f858f00cf249a73cfa8777dd2a8adbab1d2c /contrib/check_inodes-freebsd.pl | |
parent | 2e24418ea7c179d2db3eccf9a6b6b4378e2857d2 (diff) | |
download | monitoring-plugins-9e3002c652b8e2e59f99e115e458c3f3bc738d59.tar.gz |
check inodes - freebsd - candidate for merge with check_inodes
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@72 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_inodes-freebsd.pl')
-rw-r--r-- | contrib/check_inodes-freebsd.pl | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/contrib/check_inodes-freebsd.pl b/contrib/check_inodes-freebsd.pl new file mode 100644 index 00000000..6dc83754 --- /dev/null +++ b/contrib/check_inodes-freebsd.pl | |||
@@ -0,0 +1,127 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # check_inodes.pl for FreeBSD | ||
4 | # Designed on FreeBSD 4.6 (although this should not matter) | ||
5 | # parses df output, splits, and then takes variables | ||
6 | # df.pl -f mountpoint -w warningnumber -c critical number | ||
7 | # USE NUMBERS AND NOT PERCENTS FOR wanring and critical values | ||
8 | # -h is help | ||
9 | # -v is version | ||
10 | # Mountpoints: | ||
11 | # like / or /usr or /var (whatever you mount drives NOT the device names) | ||
12 | # Andrew Ryder - 20020804 - atr@mrcoffee.org | ||
13 | |||
14 | |||
15 | use strict; | ||
16 | use Getopt::Long; | ||
17 | use vars qw($opt_V $opt_h $opt_w $opt_c $opt_f $verbose $PROGNAME); | ||
18 | use lib "/usr/local/libexec/nagios" ; | ||
19 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | ||
20 | |||
21 | my $df = "/bin/df"; | ||
22 | my $grep = "/usr/bin/grep"; | ||
23 | |||
24 | $PROGNAME="df.pl"; | ||
25 | |||
26 | sub print_help (); | ||
27 | sub print_usage (); | ||
28 | |||
29 | |||
30 | $ENV{'PATH'}=''; | ||
31 | $ENV{'BASH_ENV'}=''; | ||
32 | $ENV{'ENV'}=''; | ||
33 | |||
34 | Getopt::Long::Configure('bundling'); | ||
35 | GetOptions | ||
36 | ("V" => \$opt_V, "version" => \$opt_V, | ||
37 | "h" => \$opt_h, "help" => \$opt_h, | ||
38 | "w=s" => \$opt_w, "warning=s" => \$opt_w, | ||
39 | "c=s" => \$opt_c, "critical=s" => \$opt_c, | ||
40 | "f=s" => \$opt_f, "filesystem=s" => \$opt_f); | ||
41 | |||
42 | |||
43 | if ($opt_V) { | ||
44 | print_revision($PROGNAME,'$Revision$ '); | ||
45 | exit $ERRORS{'OK'}; | ||
46 | } | ||
47 | |||
48 | if ($opt_h) { | ||
49 | print_help(); | ||
50 | exit $ERRORS{'OK'}; | ||
51 | } | ||
52 | |||
53 | ($opt_w) || ($opt_w = shift) || ($opt_w = 50); | ||
54 | my $warning = $1 if ($opt_w =~ /([0-9]+)/); | ||
55 | |||
56 | ($opt_c) || ($opt_c = shift) || ($opt_c = 75); | ||
57 | my $critical = $1 if ($opt_c =~ /([0-9]+)/); | ||
58 | |||
59 | if ($opt_c < $opt_w) { | ||
60 | print "Critical offset should be larger than warning offset\n"; | ||
61 | print_usage(); | ||
62 | exit $ERRORS{"UNKNOWN"}; | ||
63 | } | ||
64 | |||
65 | ($opt_f) || ($opt_f = "/"); | ||
66 | |||
67 | |||
68 | unless (-e $df) { | ||
69 | print "UNKNOWN: $df is not where df is\n"; | ||
70 | exit $ERRORS{'UNKNOWN'}; | ||
71 | } | ||
72 | |||
73 | unless (-e $grep) { | ||
74 | print "UNKNOWN: $grep is not where grep is\n"; | ||
75 | exit $ERRORS{'UNKNOWN'}; | ||
76 | } | ||
77 | |||
78 | unless (-d $opt_f) { | ||
79 | print "UNKNOWN: $opt_f is not a mount point\n"; | ||
80 | exit $ERRORS{'UNKNOWN'}; | ||
81 | } | ||
82 | |||
83 | |||
84 | my $state = $ERRORS{'UNKNOWN'}; | ||
85 | my $answer; | ||
86 | |||
87 | open(DF, "$df -i $opt_f| $grep -v Filesystem |"); | ||
88 | |||
89 | while (<DF>) { | ||
90 | |||
91 | my ($fs,$onek,$used,$avail,$capacity,$iused,$ifree,$ipercent,$mounted) = split; | ||
92 | $ipercent =~ s/%//s; | ||
93 | |||
94 | if ($ipercent > $opt_w) { | ||
95 | $state = $ERRORS{'WARNING'}; | ||
96 | $answer = "WARNING: $ipercent percent inodes free on $opt_f\n"; | ||
97 | } elsif ($ipercent > $opt_w) { | ||
98 | $state = $ERRORS{'CRITCAL'}; | ||
99 | $answer = "CRITICAL: $ipercent percent inodes free on $opt_f\n"; | ||
100 | } elsif ($ipercent < $opt_w) { | ||
101 | $state = $ERRORS{'OK'}; | ||
102 | $answer = "OK: $ipercent percent inodes free on $opt_f\n"; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | close(DF); | ||
107 | |||
108 | print "$answer"; | ||
109 | exit $state; | ||
110 | |||
111 | sub print_usage () { | ||
112 | print "Usage: $PROGNAME <filesystem> [-w <warn>] [-c <crit>]\n"; | ||
113 | print "Example: $PROGNAME /dev/ad0s1a -w 50 -c 75\n"; | ||
114 | } | ||
115 | |||
116 | sub print_help () { | ||
117 | print_revision($PROGNAME,'$Revision$'); | ||
118 | print "Copyright (c) 2002 Andrew Ryder\n"; | ||
119 | print "\n"; | ||
120 | print_usage(); | ||
121 | print "\n"; | ||
122 | print "<warn> = Inode Percent at which a warning message is returned. Defaults to 50.\n"; | ||
123 | print "<crit> = Inode Percent at which a critical message is returned..\n Defaults to 75.\n\n"; | ||
124 | support(); | ||
125 | } | ||
126 | |||
127 | |||