combine error logging with optional verbose message
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Jérémy Lecour 2019-03-20 22:34:41 +01:00
parent 53d87dccd3
commit bad0d7fa98

View file

@ -125,10 +125,17 @@ IS_NRPEDAEMON=1
IS_ALERTBOOT=1
IS_RSYNC=1
# Verbose function
verbose() {
msg="${1:-$(cat /dev/stdin)}"
[ "${VERBOSE}" -eq 1 ] && [ -n "${msg}" ] && echo "${msg}"
# logging function
failed() {
test=$1
shift
comments=$@
if [ -n "${comments}" ] && [ "${VERBOSE}" = 1 ]; then
printf "%s FAILED! %s\n" "${test}" "${comments}" 2>&1
else
printf "%s FAILED!\n" "${test}" 2>&1
fi
}
# Source configuration file
@ -267,19 +274,16 @@ if [ -e /etc/debian_version ]; then
if [ "$IS_LISTCHANGESCONF" = 1 ]; then
if is_debianversion stretch; then
if is_installed apt-listchanges; then
echo 'IS_LISTCHANGESCONF FAILED!'
verbose "apt-listchanges must not be installed on Stretch"
failed "IS_LISTCHANGESCONF" "apt-listchanges must not be installed on Stretch"
fi
else
if [ -e "/etc/apt/listchanges.conf" ]; then
lines=$(grep -cE "(which=both|confirm=1)" /etc/apt/listchanges.conf)
if [ $lines != 2 ]; then
echo 'IS_LISTCHANGESCONF FAILED!'
verbose "apt-listchanges config is incorrect"
failed "IS_LISTCHANGESCONF" "apt-listchanges config is incorrect"
fi
else
echo 'IS_LISTCHANGESCONF FAILED!'
verbose "apt-listchanges config is missing"
failed "IS_LISTCHANGESCONF" "apt-listchanges config is missing"
fi
fi
fi
@ -345,18 +349,15 @@ if [ -e /etc/debian_version ]; then
if is_installed mysql-server; then
# You can configure MYSQL_ADMIN in evocheck.cf
if ! grep -qs "$MYSQL_ADMIN" /root/.my.cnf; then
echo 'IS_MYSQLUTILS FAILED!'
verbose 'mysqladmin missing in /root/.my.cnf'
failed "IS_MYSQLUTILS" "mysqladmin missing in /root/.my.cnf"
fi
if ! test -x /usr/bin/mytop; then
if ! test -x /usr/local/bin/mytop; then
echo 'IS_MYSQLUTILS FAILED!'
verbose 'mytop binary missing'
failed "IS_MYSQLUTILS" "mytop binary missing"
fi
fi
if ! grep -qs debian-sys-maint /root/.mytop; then
echo 'IS_MYSQLUTILS FAILED!'
verbose 'debian-sys-maint missing in /root/.mytop'
failed "IS_MYSQLUTILS" "debian-sys-maint missing in /root/.mytop"
fi
fi
fi
@ -605,8 +606,7 @@ if [ -e /etc/debian_version ]; then
reservedBlockCount=$(dumpe2fs -h "$part" 2>/dev/null | grep -e "Reserved block count:" | grep -Eo "[0-9]+")
percentage=$(python -c "print(int(round(float(${reservedBlockCount})/${blockCount}*100)))")
if [ "$percentage" -lt 5 ]; then
echo 'IS_TUNE2FS_M5 FAILED!'
verbose "Partition $part has less than 5% reserved blocks!"
failed "IS_TUNE2FS_M5" "Partition ${part} has less than 5% reserved blocks!"
fi
done
fi