evobackup/lib/bkctld-check
Victor LABORIE 842e57ba53 Big refactoring
* Jails are created on start and run in tmpfs
* All config files are on /etc/bkctld
* Cleaning of sshd_config and /etc/group
2020-01-08 14:46:18 +01:00

60 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
#
# Run check on jails (NRPE output)
# Usage: check
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
cur_time=$(date "+%s")
return=0
nb_crit=0
nb_warn=0
nb_ok=0
nb_unkn=0
output=""
grep -qE " ${MOUNT_POINT} " /etc/mtab
if [ "$?" -ne 0 ]; then
echo "Backup disk is not mounted on ${MOUNT_POINT} !\n"
echo "You need to run bkctld mount !"
exit 2
fi
for jail in $("${LIBDIR}/bkctld-list"); do
if [ -f "${LOGDIR}/${jail}/lastlog" ]; then
last_conn=$(stat --format=%Y "${LOGDIR}/${jail}/lastlog")
date_diff=$(( (cur_time - last_conn) / (60*60) ))
if [ "${date_diff}" -gt "${CRITICAL}" ]; then
nb_crit=$((nb_crit + 1))
output="${output}CRITICAL - ${jail} - ${date_diff} hours\n"
[ "${return}" -le 2 ] && return=2
elif [ "${date_diff}" -gt "${WARNING}" ]; then
nb_warn=$((nb_warn + 1))
output="${output}WARNING - ${jail} - ${date_diff} hours\n"
[ "${return}" -le 1 ] && return=1
else
nb_ok=$((nb_ok + 1))
output="${output}OK - ${jail} - ${date_diff} hours\n"
fi
else
nb_unkn=$((nb_unkn + 1))
output="${output}UNKNOWN - ${jail} doesn't have lastlog !\n"
[ "${return}" -le 3 ] && return=3
fi
done
[ "${return}" -ge 0 ] && header="OK"
[ "${return}" -ge 1 ] && header="WARNING"
[ "${return}" -ge 2 ] && header="CRITICAL"
[ "${return}" -ge 3 ] && header="UNKNOW"
printf "%s - %s UNK / %s CRIT / %s WARN / %s OK\n\n" "${header}" "${nb_unkn}" "${nb_crit}" "${nb_warn}" "${nb_ok}"
printf "${output}" | grep -E "^UNKNOW"
printf "${output}" | grep -E "^CRITICAL"
printf "${output}" | grep -E "^WARNING"
printf "${output}" | grep -E "^OK"
exit "${return}"