Monkey Albino

Linux altar53.supremepanel53.com 4.18.0-553.8.1.lve.el8.x86_64 #1 SMP Thu Jul 4 16:24:39 UTC 2024 x86_64
/ lib64/ nagios/ plugins/

//lib64/nagios/plugins/check_backup.sh

#!/bin/bash

set -o pipefail

BACKUPDIR="/mnt/backup"
FIND=$(which find)
FINDOPTS=(-maxdepth 1 -type d -name \*-\* -mtime +10)
HEAD=$(which head)
HEADOPTS="-1"
TR=$(which tr)
TROPTS=(-d '/mnt/backup/')
WC=$(which wc)
WCOPTS="-l"
RPM=$(which rpm)
SUDO=$(which sudo)
GREP=$(which grep)
GREPSTRING="Install"
DATE=$(which date)
DATEOPTS="+%s"
RPMOPTS="-qi basesystem"
CUT=$(which cut)
CUTOPTS=(-d':' -f2)
SUDOPTS="-l"
SED=$(which sed)
SEDOPTS=('s/Install Date: //g')

INIT="$[$[$($DATE $DATEOPTS)-$($DATE -d "$($RPM $RPMOPTS | $GREP -w $GREPSTRING | $SED "${SEDOPTS[@]}")" $DATEOPTS)]/60/60/24]"

OLDEST_BACKUP=$($SUDO $FIND "$BACKUPDIR" "${FINDOPTS[@]}" | $TR "${TROPTS[@]}" | $HEAD $HEADOPTS)

COUNT_BACKUP=$($SUDO $FIND "$BACKUPDIR" "${FINDOPTS[@]:0:6}" | $WC "$WCOPTS")

[[ ! -d "$BACKUPDIR" ]] && \

printf "\360\237\231\200 " && \
echo "UNKNOWN:" $BACKUPDIR "does not exist." && \
exit 3

[[ ! -z "$OLDEST_BACKUP" ]] && \

printf "\360\237\222\200 " && \
echo "CRITICAL:" $OLDEST_BACKUP "is the oldest backup date and it is older than the acceptable 10 days." && \
exit 2

[[ "$COUNT_BACKUP" -gt 3 ]] && \
printf "\360\237\222\200 " && \
echo "CRITICAL:" "Kept backup dates are" $COUNT_BACKUP "which is more than the maximum 3 backup dates." && \
exit 2

[[ "$COUNT_BACKUP" -le 1 ]] && [[ "$INIT" -ge 10 ]] && \
printf "\360\237\222\200 " && \
echo "CRITICAL:" "Kept backup dates are" $COUNT_BACKUP "which is less than the minimum 2 backup dates." && \
exit 2

printf "\360\237\222\232 " && \
echo "OK:" "Kept backup dates are" $COUNT_BACKUP "and the oldest backup" $OLDEST_BACKUP "is less than 10 days old." && \
exit 0