2019-07-23 22:28:09 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Small script to survey CRL
|
|
|
|
# GPL v3+
|
|
|
|
|
|
|
|
# Default values
|
2019-08-08 01:32:29 +02:00
|
|
|
# Warning : 7 days - 10 years
|
|
|
|
# (juste because more than 10 years is really far stretched and might be a manipulation error)
|
|
|
|
RANGE_WARNING="7:3650"
|
|
|
|
# Critical : 3 days
|
|
|
|
RANGE_CRITICAL="3:"
|
2019-07-23 22:28:09 +02:00
|
|
|
|
|
|
|
# Output
|
|
|
|
OUTPUT_EXIT_STATUS=0
|
|
|
|
OUTPUT_DETAIL_WARNING=""
|
|
|
|
OUTPUT_DETAIL_CRITICAL=""
|
2019-08-08 01:32:29 +02:00
|
|
|
#OUTPUT_PERFDATA=""
|
|
|
|
|
|
|
|
PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' )
|
|
|
|
REVISION="0.2"
|
2019-07-23 22:28:09 +02:00
|
|
|
|
|
|
|
# Stop at the first non-catched error
|
|
|
|
set -e
|
|
|
|
|
2019-08-08 01:32:29 +02:00
|
|
|
# Include check_range()
|
|
|
|
. $PROGPATH/utils.sh
|
|
|
|
|
2019-07-23 22:28:09 +02:00
|
|
|
#
|
|
|
|
# Help function
|
|
|
|
#
|
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage :
|
|
|
|
$0 [-w warning_range] [-c critical_range] -f file.crl [[-w...] -f file.crl ] ...
|
|
|
|
|
2019-08-08 01:32:29 +02:00
|
|
|
Thresholds in days.
|
2019-07-23 22:28:09 +02:00
|
|
|
|
|
|
|
Note: Since the file is checked against the lastest ranges given, order
|
|
|
|
of the arguments are important.
|
|
|
|
|
|
|
|
Default values:
|
|
|
|
warning_range: $RANGE_WARNING
|
|
|
|
critical_range: $RANGE_CRITICAL
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
check_range_syntax() {
|
2019-08-08 01:32:29 +02:00
|
|
|
check_range 0 "$1" >/dev/null 2>&1
|
|
|
|
if [ "$?" -eq "2" ]; then
|
|
|
|
return 1
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Some early checks
|
|
|
|
if ! which openssl >/dev/null 2>&1 ; then
|
|
|
|
echo "UNKNOWN 'openssl' not found."
|
2019-08-08 01:32:29 +02:00
|
|
|
exit $STATE_UNKNOWN
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Parameters management
|
|
|
|
#
|
|
|
|
while getopts hw:c:f: OPT; do
|
|
|
|
case "$OPT" in
|
|
|
|
'h')
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
'w')
|
|
|
|
if check_range_syntax "$OPTARG" >/dev/null; then
|
|
|
|
RANGE_WARNING="$OPTARG"
|
|
|
|
else
|
2019-08-08 01:32:29 +02:00
|
|
|
echo "UNKNOWN: invalid range : $OPTARG"
|
|
|
|
exit $STATE_UNKNOWN
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
'c')
|
|
|
|
if check_range_syntax "$OPTARG" >/dev/null; then
|
|
|
|
RANGE_CRITICAL="$OPTARG"
|
|
|
|
else
|
2019-08-08 01:32:29 +02:00
|
|
|
echo "UNKNOWN: invalid range : $OPTARG"
|
|
|
|
exit $STATE_UNKNOWN
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
'f')
|
|
|
|
# I'm not very proud of this one : aesthetically speaking, treatments
|
|
|
|
# should not be done during params management :)
|
|
|
|
CRL_FILE="$OPTARG"
|
|
|
|
if [ ! -f "$CRL_FILE" ]; then
|
2019-08-08 01:32:29 +02:00
|
|
|
echo "UNKNOWN: inexistent file : $CRL_FILE"
|
|
|
|
exit $STATE_UNKNOWN
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract time left, in seconds
|
|
|
|
EXPIRATION_DATE="$( openssl crl -noout -text -in "$CRL_FILE" | sed -n "s/^[[:space:]]\+Next Update: \(.*\)$/\1/p" )"
|
|
|
|
if [ -z "$EXPIRATION_DATE" ]; then
|
|
|
|
echo "UNKNOWN: couldn't get expiration date."
|
2019-08-08 01:32:29 +02:00
|
|
|
exit $STATE_UNKNOWN
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
2019-08-08 01:32:29 +02:00
|
|
|
TIME_LEFT=$(( ( $( date --date="$EXPIRATION_DATE" +%s ) - $( date +%s ) ) / 86400 ))
|
2019-07-23 22:28:09 +02:00
|
|
|
|
|
|
|
# Check time left against range
|
2019-08-08 01:32:29 +02:00
|
|
|
if check_range "$TIME_LEFT" "$RANGE_CRITICAL"; then
|
|
|
|
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
|
|
|
|
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $CRL_FILE ($TIME_LEFT days left)"
|
|
|
|
elif check_range "$TIME_LEFT" "$RANGE_WARNING"; then
|
2019-07-23 22:28:09 +02:00
|
|
|
if [ "$OUTPUT_EXIT_STATUS" -eq 0 ]; then
|
2019-08-08 01:32:29 +02:00
|
|
|
OUTPUT_EXIT_STATUS=$STATE_WARNING
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
2019-08-08 01:32:29 +02:00
|
|
|
OUTPUT_DETAIL_WARNING="$OUTPUT_DETAIL_WARNING $CRL_FILE ($TIME_LEFT days left)"
|
2019-07-23 22:28:09 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
\?)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-08-08 01:32:29 +02:00
|
|
|
if [ -z "$CRL_FILE" ]; then
|
|
|
|
echo "UNKNOWN: no file tested."
|
|
|
|
exit $STATE_UNKNOWN
|
|
|
|
fi
|
|
|
|
|
2019-07-23 22:28:09 +02:00
|
|
|
case "$OUTPUT_EXIT_STATUS" in
|
|
|
|
'0')
|
|
|
|
printf "OK"
|
|
|
|
;;
|
|
|
|
'1')
|
|
|
|
printf "WARNING %s" "$OUTPUT_DETAIL_WARNING"
|
|
|
|
;;
|
|
|
|
'2')
|
|
|
|
printf "CRITICAL %s" "$OUTPUT_DETAIL_CRITICAL"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "UNKNOWN"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2019-08-08 01:32:29 +02:00
|
|
|
# Perfdata
|
|
|
|
#printf "|%s\n" "$OUTPUT_PERFDATA"
|
|
|
|
printf "\n"
|
2019-07-23 22:28:09 +02:00
|
|
|
|
2019-08-08 01:32:29 +02:00
|
|
|
# Exit with return status
|
|
|
|
exit $OUTPUT_EXIT_STATUS
|