You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

#!/bin/bash
path=""
while test $# -gt 0; do
case $1 in
(-h|--help) cat <<EOF
$0 [OPTIONS] PATH
-h, --help show this help
PATH
Path to check.
DESCRIPTION
Icinga plugin to check whether a given path is available. Detects
problems, e.g. with glusterfs: In case of a problem, there is an error
message such as "socket not connected".
EOF
exit;;
(*) if test $# -ne 1; then
echo "ERROR: please specify an existing path, not $*" 1>&2
exit 1
fi
path="$1";;
esac
if test $# -lt 1; then
echo "ERROR: missing option, try $0 --help"
exit 1
fi
shift
done
if ! test -d "$path"; then
echo "ERROR: no such path $path" 1>&2
exit 1
fi
time=$(mktemp)
out=$(mktemp)
err=$(mktemp)
if /usr/bin/time -f "elapsed=%es" -qo $time mount | grep -q 'on '"$path"' '; then
if /usr/bin/time -f "elapsed=%es" -qo $time ls "$path" > $out 2> $err && test -s $out; then
if [[ $(<$time) =~ elapsed=0.0[012]s ]]; then
level=0
STATUS="OK - ${path}:"
else
level=1
STATUS="WARNING - ${path}:"
fi
else
if test -s $err; then
level=2
STATUS="CRITICAL - $(<$err):"
else
level=2
STATUS="CRITICAL - ${path} is empty:"
fi
fi
else
level=2
STATUS="CRITICAL - ${path} not mounted:"
fi
echo ${STATUS} $(<$time)
rm $time $out $err 2>&1 > /dev/null
exit $level