summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcrypt-expiry-check.in30
1 files changed, 18 insertions, 12 deletions
diff --git a/crypt-expiry-check.in b/crypt-expiry-check.in
index c24dfbc..7ce5eae 100755
--- a/crypt-expiry-check.in
+++ b/crypt-expiry-check.in
@@ -113,6 +113,17 @@ set_retcode()
[ ${RETCODE} -lt $1 ] && RETCODE=$1
}
+format_date()
+{
+ if echo "$*" | ${GREP} -qx '[0-9]\+'; then
+ ${DATE} '+%F' -d@"$*"
+ elif echo "$*" | ${GREP} -qx '[0-9]\+-[0-9]\+-[0-9]\+'; then
+ ${DATE} '+%F' -d"$*"
+ else
+ ${DATE} -d"$(echo "$*" | ${AWK} '{ print $1, $2, $4 }')" +%F
+ fi
+}
+
#####################################################################
# Purpose: Print a line with the expiraton interval
# Arguments:
@@ -125,20 +136,13 @@ set_retcode()
#####################################################################
prints()
{
- if echo "$4" | ${GREP} -qx '[0-9]\+'; then
- MIN_DATE=$(${DATE} '+%F' -d@$4)
- elif echo "$4" | ${GREP} -qx '[0-9]\+-[0-9]\+-[0-9]\+'; then
- MIN_DATE=$(${DATE} '+%F' -d$4)
- else
- MIN_DATE=$(date -d"$(echo $4 | ${AWK} '{ print $1, $2, $4 }')" +%F)
- fi
if ${ISSUER} && ! ${VALIDATION}
then
if ${NAGIOS}
then
- ${PRINTF} "%-35s %-17s %-8s %-11s %-4s %-30s\n" "$1:$2" "$6" "$3" "${MIN_DATE}" \|days="$5"
+ ${PRINTF} "%-35s %-17s %-8s %-11s %-4s %-30s\n" "$1:$2" "$6" "$3" "$4" \|days="$5"
else
- ${PRINTF} "%-35s %-17s %-8s %-11s %-4s %-30s\n" "$1:$2" "$6" "$3" "${MIN_DATE}" "$5"
+ ${PRINTF} "%-35s %-17s %-8s %-11s %-4s %-30s\n" "$1:$2" "$6" "$3" "$4" "$5"
fi
elif ${ISSUER} && ${VALIDATION}
then
@@ -148,9 +152,9 @@ prints()
then
if ${NAGIOS}
then
- ${PRINTF} "%-47s %-12s %-12s %-4s %-30s\n" "$1:$2" "$3" "${MIN_DATE}" \|days="$5"
+ ${PRINTF} "%-47s %-12s %-12s %-4s %-30s\n" "$1:$2" "$3" "$4" \|days="$5"
else
- ${PRINTF} "%-47s %-12s %-12s %-4s %-30s\n" "$1:$2" "$3" "${MIN_DATE}" "$5"
+ ${PRINTF} "%-47s %-12s %-12s %-4s %-30s\n" "$1:$2" "$3" "$4" "$5"
fi
else
${PRINTF} "%-35s %-35s %-32s\n" "$1:$2" "$7" "$8"
@@ -451,6 +455,7 @@ check_file_status() {
# Convert the date to seconds, and get the diff between NOW and the expiration date
CERTDIFF=$[${CERTDATE} - $(${DATE} +%s)]
+ CERTDATE=$(format_date "${CERTDATE}")
if [ ${CERTDIFF} -lt 0 ]
then
CERTDIFF=$[$[${CERTDIFF}+1]/3600/24-1]
@@ -519,6 +524,7 @@ check_gpg_key_status() {
fi
KEY_DIFF=$[${KEY_DATE} - $(${DATE} +%s)]
+ KEY_DATE=$(format_date "${KEY_DATE}")
if [ ${KEY_DIFF} -lt 0 ]
then
KEY_DIFF=$[$[${KEY_DIFF}+1]/3600/24-1]
@@ -534,7 +540,7 @@ check_gpg_key_status() {
elif [ ${KEY_DIFF} -lt ${FWARNDAYS} ]
then
- echo "The GPG key for ${GPG_ADDRESS} will expire on ${KEY_DATE_STR}" >> ${MAILOUT_TMP}
+ echo "The GPG key for ${GPG_ADDRESS} will expire on ${KEY_DATE}" >> ${MAILOUT_TMP}
prints "GPG" " ${GPG_ADDRESS}" "Expiring" "${KEY_DATE}" "${KEY_DIFF}" "" "" "" >> ${STDOUT_TMP}
set_retcode 1