1 |
#!/bin/bash |
2 |
|
3 |
# check_glusterfs_mount - plugin for nagios to check that a glusterfs partition |
4 |
# is correctly mounted |
5 |
# Copyright (C) 2008 Ioannis Aslanidis (deathwing00 at deathwing00 dot org) |
6 |
# |
7 |
# This program is free software; you can redistribute it and/or modify |
8 |
# it under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 2 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# This program is distributed in the hope that it will be useful, |
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU Library General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with this program; if not, write to the Free Software |
19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
21 |
TIMELIMIT=5 # We allow 5 seconds for ls to run. If it does not, we consider it has hanged. |
22 |
TOTALPARAMS=1 # Total number of expected parameters. |
23 |
MINLINES=2 # If we find less that these number of lines, we understand that there was an error. |
24 |
|
25 |
TryList() |
26 |
{ |
27 |
# We only expect one parameter: the path to check. |
28 |
path=${1} |
29 |
# List the contents of the path and verify that the output is correct |
30 |
numlines=$(/bin/ls -l ${path} | /usr/bin/wc -l) |
31 |
if [ ${numlines} -lt ${MINLINES} ]; then |
32 |
echo CRITICAL: GlusterFS mount point ${1} is not working correctly. |
33 |
exit 2 |
34 |
fi |
35 |
} |
36 |
|
37 |
TimerOn() |
38 |
{ |
39 |
/bin/sleep ${TIMELIMIT} && /usr/bin/kill -s 14 ${$} & |
40 |
# Waits some seconds, then sends sigalarm to script. |
41 |
} |
42 |
|
43 |
Int14Vector() |
44 |
{ |
45 |
echo CRITICAL: GlusterFS mount point ${1} is not working. Could not list the contents! |
46 |
exit 2 |
47 |
} |
48 |
|
49 |
# Timer interrupt (14) subverted for our purposes. |
50 |
trap Int14Vector 14 |
51 |
|
52 |
# Check that the total number of parameters is correct. |
53 |
if [ ${#} -ne ${TOTALPARAMS} ]; then |
54 |
echo UNKNOWN: Script was executed with incorrect number of arguments. Check could not be performed. |
55 |
exit 3 |
56 |
fi |
57 |
|
58 |
# Start the timer. |
59 |
TimerOn |
60 |
# Make the call. |
61 |
TryList ${1} |
62 |
|
63 |
# If we get past this point it means that everything went fine. |
64 |
|
65 |
# Return success. |
66 |
echo OK: GlusterFS mount ${1} is available |
67 |
|
68 |
# Kill the alarm timer, we do not need it any more. (bash will write to stdout about the process that got killed, redirecting makes no sense here) |
69 |
kill -9 ${!} |
70 |
wait ${!} 2>/dev/null |
71 |
# sleep 1 |
72 |
|
73 |
# Exit with success |
74 |
exit 0 |