77 lines
1.4 KiB
Plaintext
77 lines
1.4 KiB
Plaintext
|
#!/bin/bash
|
||
|
#
|
||
|
# Nagios plugin to check clamav daemon status
|
||
|
#
|
||
|
# Author : Benjamin Renard <brenard@easter-eggs.com>
|
||
|
# Date : Wed, 12 Jun 2019 13:15:33 +0200
|
||
|
# Source : http://gogs.zionetrix.net/check_clamd
|
||
|
#
|
||
|
|
||
|
CLAMDSCAN=clamdscan
|
||
|
FILE_TO_CHECK="/etc/mtab"
|
||
|
DEBUG=0
|
||
|
|
||
|
function debug() {
|
||
|
if [ $DEBUG -eq 1 ]
|
||
|
then
|
||
|
>&2 echo -e "[DEBUG] $1"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function usage() {
|
||
|
cat << EOF
|
||
|
Usage : $0 [-d] [-h] [options]
|
||
|
-c Path to clamdscan (Default : auto-detected)
|
||
|
-f Path of the file to check with clamdscan (Default : $FILE_TO_CHECK)
|
||
|
-d Debug mode
|
||
|
-h Show this message
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
while getopts "hf:c:n:d" OPTION
|
||
|
do
|
||
|
case $OPTION in
|
||
|
f)
|
||
|
FILE_TO_CHECK=$OPTARG
|
||
|
;;
|
||
|
c)
|
||
|
CLAMDSCAN=$OPTARG
|
||
|
;;
|
||
|
d)
|
||
|
DEBUG=1
|
||
|
;;
|
||
|
h)
|
||
|
usage
|
||
|
exit 0
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unkown option '$OPTION'"
|
||
|
usage
|
||
|
exit 1
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
CMD="$CLAMDSCAN --stream --stdout --infected --no-summary $FILE_TO_CHECK"
|
||
|
debug "clamdscan command = '$CMD'"
|
||
|
|
||
|
ERRORS=$( $CMD 2>&1 )
|
||
|
EXITCODE=$?
|
||
|
|
||
|
debug "clamdscan exit code = $EXITCODE"
|
||
|
debug "clamdscan output =\n$ERRORS"
|
||
|
|
||
|
if [ $EXITCODE -ne 0 ]
|
||
|
then
|
||
|
echo "CRITICAL - clamdscan exit with $EXITCODE"
|
||
|
[ -n "$ERRORS" ] && echo -e "clamdscan return:\n$ERRORS"
|
||
|
exit 2
|
||
|
elif [ -z "$ERRORS" ]
|
||
|
then
|
||
|
echo "OK - Clamav daemon is running and answer to scan request"
|
||
|
exit 0
|
||
|
else
|
||
|
echo "WARNING - clamdscan return some errors checking $FILE_TO_CHECK file"
|
||
|
echo -e "$ERRORS"
|
||
|
exit 1
|
||
|
fi
|