-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_mount.pl
executable file
·82 lines (74 loc) · 1.92 KB
/
check_mount.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl -w
#
# Copyright 2009-2017 Martin Scharm
#
# This file is part of bf-monitoring.
# <https://binfalse.de/software/nagios/>
# <https://github.com/binfalse/monitoring>
#
# bf-monitoring is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# bf-monitoring is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# bf-monitoring If not, see <http://www.gnu.org/licenses/>.
#
###################################
#
# Check the state of mount points
# written by Martin Scharm
# see http://binfalse.de
#
###################################
use warnings;
use strict;
use Getopt::Long qw(:config no_ignore_case);
use lib '/usr/lib/nagios/plugins';
use utils qw(%ERRORS);
my $MOUNT = undef;
my $TYPE = undef;
sub how_to
{
print "USAGE: $0\n\t-m MOUNTPOINT\twich mountpoint to check\n\t[-t TYPE]\toptionally check whether it's this kind of fs-type\n\n";
}
GetOptions (
'm=s' => \ $MOUNT,
'mountpoint=s' => \ $MOUNT,
't=s' => \ $TYPE,
'type=s' => \ $TYPE
);
unless (defined ($MOUNT))
{
print "Please define mountpoint\n\n";
how_to;
exit $ERRORS{'CRITICAL'};
}
my $erg = `/bin/mount | /bin/grep $MOUNT`;
if ($erg)
{
if (defined ($TYPE))
{
if ($erg =~ m/type $TYPE /)
{
print $MOUNT . " is mounted! Type is " . $TYPE . "\n";
exit $ERRORS{'OK'};
}
else
{
print $MOUNT . " is mounted! But type is not " . $TYPE . "\n";
exit $ERRORS{'WARNING'};
}
}
print $MOUNT . " is mounted!\n";
exit $ERRORS{'OK'};
}
else
{
print $MOUNT . " is not mounted!\n";
exit $ERRORS{'CRITICAL'};
}