Add database healthy checks to debug script

Fix health check output comparison in gravity script as well
Add note about waiting time

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König 2022-05-29 09:51:33 +02:00
parent e0baf4c7ec
commit b486786041
No known key found for this signature in database
GPG key ID: 4CDA6F249DD2B485
3 changed files with 86 additions and 19 deletions

View file

@ -1259,12 +1259,21 @@ show_messages() {
show_FTL_db_entries "Pi-hole diagnosis messages" "SELECT count (message) as count, datetime(max(timestamp),'unixepoch','localtime') as 'last timestamp', type, message, blob1, blob2, blob3, blob4, blob5 FROM message GROUP BY type, message, blob1, blob2, blob3, blob4, blob5;" "6 19 20 60 20 20 20 20 20" show_FTL_db_entries "Pi-hole diagnosis messages" "SELECT count (message) as count, datetime(max(timestamp),'unixepoch','localtime') as 'last timestamp', type, message, blob1, blob2, blob3, blob4, blob5 FROM message GROUP BY type, message, blob1, blob2, blob3, blob4, blob5;" "6 19 20 60 20 20 20 20 20"
} }
database_permissions() {
local permissions
permissions=$(ls -lhd "${1}")
log_write "${COL_GREEN}${permissions}${COL_NC}"
}
analyze_gravity_list() { analyze_gravity_list() {
echo_current_diagnostic "Gravity Database" echo_current_diagnostic "Gravity Database"
local gravity_permissions database_permissions "${PIHOLE_GRAVITY_DB_FILE}"
gravity_permissions=$(ls -lhd "${PIHOLE_GRAVITY_DB_FILE}")
log_write "${COL_GREEN}${gravity_permissions}${COL_NC}" # if users want to check database integrity
if [[ "${CHECK_DATABASE}" = true ]]; then
database_integrity_check "${PIHOLE_FTL_DB_FILE}"
fi
show_db_entries "Info table" "SELECT property,value FROM info" "20 40" show_db_entries "Info table" "SELECT property,value FROM info" "20 40"
gravity_updated_raw="$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")" gravity_updated_raw="$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")"
@ -1286,6 +1295,57 @@ analyze_gravity_list() {
IFS="$OLD_IFS" IFS="$OLD_IFS"
} }
analyze_ftl_db() {
echo_current_diagnostic "Pi-hole FTL Query Database"
database_permissions "${PIHOLE_FTL_DB_FILE}"
# if users want to check database integrity
if [[ "${CHECK_DATABASE}" = true ]]; then
database_integrity_check "${PIHOLE_FTL_DB_FILE}"
fi
}
database_integrity_check(){
local result
local database="${1}"
log_write "${INFO} Checking integrity of ${database} ... (this can take several minutes)"
result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1)"
if [[ ${result} = "ok" ]]; then
log_write "${TICK} Integrity of ${database} intact"
log_write "${INFO} Checking foreign key constraints of ${database} ... (this can take several minutes)"
unset result
result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1)"
if [[ -z ${result} ]]; then
log_write "${TICK} No foreign key errors in ${database}"
else
log_write "${CROSS} ${COL_RED}Foreign key errors in ${database} found.${COL_NC}"
while IFS= read -r line ; do
log_write " $line"
done <<< "$result"
fi
else
log_write "${CROSS} ${COL_RED}Integrity errors in ${database} found.\n${COL_NC}"
while IFS= read -r line ; do
log_write " $line"
done <<< "$result"
fi
}
check_database_integrity() {
echo_current_diagnostic "Gravity Database"
database_permissions "${PIHOLE_GRAVITY_DB_FILE}"
database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}"
echo_current_diagnostic "Pi-hole FTL Query Database"
database_permissions "${PIHOLE_FTL_DB_FILE}"
database_integrity_check "${PIHOLE_FTL_DB_FILE}"
}
obfuscated_pihole_log() { obfuscated_pihole_log() {
local pihole_log=("$@") local pihole_log=("$@")
local line local line
@ -1431,7 +1491,7 @@ upload_to_tricorder() {
if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then
: :
else else
log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}" log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}"
log_write " * Please try again or contact the Pi-hole team for assistance." log_write " * Please try again or contact the Pi-hole team for assistance."
fi fi
fi fi
@ -1460,6 +1520,7 @@ process_status
ftl_full_status ftl_full_status
parse_setup_vars parse_setup_vars
check_x_headers check_x_headers
analyze_ftl_db
analyze_gravity_list analyze_gravity_list
show_groups show_groups
show_domainlist show_domainlist

View file

@ -870,15 +870,19 @@ gravity_Cleanup() {
database_recovery() { database_recovery() {
local result local result
local str="Checking integrity of existing gravity database" local str="Checking integrity of existing gravity database (this can take a while)"
local option="${1}" local option="${1}"
echo -ne " ${INFO} ${str}..." echo -ne " ${INFO} ${str}..."
if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)"; then result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)"
if [[ ${result} = "ok" ]]; then
echo -e "${OVER} ${TICK} ${str} - no errors found" echo -e "${OVER} ${TICK} ${str} - no errors found"
str="Checking foreign keys of existing gravity database" str="Checking foreign keys of existing gravity database (this can take a while)"
echo -ne " ${INFO} ${str}..." echo -ne " ${INFO} ${str}..."
if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)"; then unset result
result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)"
if [[ -z ${result} ]]; then
echo -e "${OVER} ${TICK} ${str} - no errors found" echo -e "${OVER} ${TICK} ${str} - no errors found"
if [[ "${option}" != "force" ]]; then if [[ "${option}" != "force" ]]; then
return return

24
pihole
View file

@ -36,19 +36,20 @@ listFunc() {
} }
debugFunc() { debugFunc() {
local automated local automated
local web local web
local check_database_integrity
# Pull off the `debug` leaving passed call augmentation flags in $1
shift
# Pull off the `debug` leaving passed call augmentation flags in $1 for value in "$@"; do
shift [[ "$value" == *"-a"* ]] && automated="true"
if [[ "$@" == *"-a"* ]]; then [[ "$value" == *"-w"* ]] && web="true"
automated="true" [[ "$value" == *"-c"* ]] && check_database_integrity="true"
fi [[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
if [[ "$@" == *"-w"* ]]; then done
web="true"
fi
AUTOMATED=${automated:-} WEBCALL=${web:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh AUTOMATED=${automated:-} WEBCALL=${web:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
exit 0 exit 0
} }
@ -455,6 +456,7 @@ Whitelist/Blacklist Options:
Debugging Options: Debugging Options:
-d, debug Start a debugging session -d, debug Start a debugging session
Add '-c' or '--check-database' to include a Pi-hole database integrity check
Add '-a' to automatically upload the log to tricorder.pi-hole.net Add '-a' to automatically upload the log to tricorder.pi-hole.net
-f, flush Flush the Pi-hole log -f, flush Flush the Pi-hole log
-r, reconfigure Reconfigure or Repair Pi-hole subsystems -r, reconfigure Reconfigure or Repair Pi-hole subsystems