mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 13:50:17 +00:00
Merge pull request #4745 from pi-hole/tweak/debug
Add optional health check to Pi-hole databases in debug script
This commit is contained in:
commit
71d310c50f
3 changed files with 86 additions and 19 deletions
|
@ -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"
|
||||
}
|
||||
|
||||
database_permissions() {
|
||||
local permissions
|
||||
permissions=$(ls -lhd "${1}")
|
||||
log_write "${COL_GREEN}${permissions}${COL_NC}"
|
||||
}
|
||||
|
||||
analyze_gravity_list() {
|
||||
echo_current_diagnostic "Gravity Database"
|
||||
|
||||
local gravity_permissions
|
||||
gravity_permissions=$(ls -lhd "${PIHOLE_GRAVITY_DB_FILE}")
|
||||
log_write "${COL_GREEN}${gravity_permissions}${COL_NC}"
|
||||
database_permissions "${PIHOLE_GRAVITY_DB_FILE}"
|
||||
|
||||
# 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"
|
||||
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"
|
||||
}
|
||||
|
||||
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() {
|
||||
local pihole_log=("$@")
|
||||
local line
|
||||
|
@ -1431,7 +1491,7 @@ upload_to_tricorder() {
|
|||
if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then
|
||||
:
|
||||
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."
|
||||
fi
|
||||
fi
|
||||
|
@ -1460,6 +1520,7 @@ process_status
|
|||
ftl_full_status
|
||||
parse_setup_vars
|
||||
check_x_headers
|
||||
analyze_ftl_db
|
||||
analyze_gravity_list
|
||||
show_groups
|
||||
show_domainlist
|
||||
|
|
12
gravity.sh
12
gravity.sh
|
@ -870,15 +870,19 @@ gravity_Cleanup() {
|
|||
|
||||
database_recovery() {
|
||||
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}"
|
||||
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"
|
||||
|
||||
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}..."
|
||||
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"
|
||||
if [[ "${option}" != "force" ]]; then
|
||||
return
|
||||
|
|
24
pihole
24
pihole
|
@ -36,19 +36,20 @@ listFunc() {
|
|||
}
|
||||
|
||||
debugFunc() {
|
||||
local automated
|
||||
local web
|
||||
local automated
|
||||
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
|
||||
shift
|
||||
if [[ "$@" == *"-a"* ]]; then
|
||||
automated="true"
|
||||
fi
|
||||
if [[ "$@" == *"-w"* ]]; then
|
||||
web="true"
|
||||
fi
|
||||
for value in "$@"; do
|
||||
[[ "$value" == *"-a"* ]] && automated="true"
|
||||
[[ "$value" == *"-w"* ]] && web="true"
|
||||
[[ "$value" == *"-c"* ]] && check_database_integrity="true"
|
||||
[[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
|
||||
done
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -455,6 +456,7 @@ Whitelist/Blacklist Options:
|
|||
|
||||
Debugging Options:
|
||||
-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
|
||||
-f, flush Flush the Pi-hole log
|
||||
-r, reconfigure Reconfigure or Repair Pi-hole subsystems
|
||||
|
|
Loading…
Reference in a new issue