mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Merge pull request #4162 from yubiuser/debug_tail_log
Add tail of pihole.log to debug output
This commit is contained in:
commit
118c0d209d
1 changed files with 67 additions and 49 deletions
|
@ -1281,56 +1281,74 @@ analyze_gravity_list() {
|
||||||
IFS="$OLD_IFS"
|
IFS="$OLD_IFS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obfuscated_pihole_log() {
|
||||||
|
local pihole_log=("$@")
|
||||||
|
local line
|
||||||
|
local error_to_check_for
|
||||||
|
local line_to_obfuscate
|
||||||
|
local obfuscated_line
|
||||||
|
for line in "${pihole_log[@]}"; do
|
||||||
|
# A common error in the pihole.log is when there is a non-hosts formatted file
|
||||||
|
# that the DNS server is attempting to read. Since it's not formatted
|
||||||
|
# correctly, there will be an entry for "bad address at line n"
|
||||||
|
# So we can check for that here and highlight it in red so the user can see it easily
|
||||||
|
error_to_check_for=$(echo "${line}" | grep 'bad address at')
|
||||||
|
# Some users may not want to have the domains they visit sent to us
|
||||||
|
# To that end, we check for lines in the log that would contain a domain name
|
||||||
|
line_to_obfuscate=$(echo "${line}" | grep ': query\|: forwarded\|: reply')
|
||||||
|
# If the variable contains a value, it found an error in the log
|
||||||
|
if [[ -n ${error_to_check_for} ]]; then
|
||||||
|
# So we can print it in red to make it visible to the user
|
||||||
|
log_write " ${CROSS} ${COL_RED}${head_line}${COL_NC} (${FAQ_BAD_ADDRESS})"
|
||||||
|
else
|
||||||
|
# If the variable does not a value (the current default behavior), so do not obfuscate anything
|
||||||
|
if [[ -z ${OBFUSCATE} ]]; then
|
||||||
|
log_write " ${line}"
|
||||||
|
# Othwerise, a flag was passed to this command to obfuscate domains in the log
|
||||||
|
else
|
||||||
|
# So first check if there are domains in the log that should be obfuscated
|
||||||
|
if [[ -n ${line_to_obfuscate} ]]; then
|
||||||
|
# If there are, we need to use awk to replace only the domain name (the 6th field in the log)
|
||||||
|
# so we substitute the domain for the placeholder value
|
||||||
|
obfuscated_line=$(echo "${line_to_obfuscate}" | awk -v placeholder="${OBFUSCATED_PLACEHOLDER}" '{sub($6,placeholder); print $0}')
|
||||||
|
log_write " ${obfuscated_line}"
|
||||||
|
else
|
||||||
|
log_write " ${line}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
analyze_pihole_log() {
|
analyze_pihole_log() {
|
||||||
echo_current_diagnostic "Pi-hole log"
|
echo_current_diagnostic "Pi-hole log"
|
||||||
local head_line
|
local pihole_log_head=()
|
||||||
# Put the current Internal Field Separator into another variable so it can be restored later
|
local pihole_log_tail=()
|
||||||
OLD_IFS="$IFS"
|
local pihole_log_permissions
|
||||||
# Get the lines that are in the file(s) and store them in an array for parsing later
|
local logging_enabled
|
||||||
IFS=$'\r\n'
|
|
||||||
local pihole_log_permissions
|
logging_enabled=$(grep -c "^log-queries" /etc/dnsmasq.d/01-pihole.conf)
|
||||||
pihole_log_permissions=$(ls -ld "${PIHOLE_LOG}")
|
if [[ "${logging_enabled}" == "0" ]]; then
|
||||||
log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}"
|
# Inform user that logging has been disabled and pihole.log does not contain queries
|
||||||
local pihole_log_head=()
|
log_write "${INFO} Query logging is disabled"
|
||||||
mapfile -t pihole_log_head < <(head -n 20 ${PIHOLE_LOG})
|
log_write ""
|
||||||
log_write " ${COL_CYAN}-----head of $(basename ${PIHOLE_LOG})------${COL_NC}"
|
fi
|
||||||
local error_to_check_for
|
# Put the current Internal Field Separator into another variable so it can be restored later
|
||||||
local line_to_obfuscate
|
OLD_IFS="$IFS"
|
||||||
local obfuscated_line
|
# Get the lines that are in the file(s) and store them in an array for parsing later
|
||||||
for head_line in "${pihole_log_head[@]}"; do
|
IFS=$'\r\n'
|
||||||
# A common error in the pihole.log is when there is a non-hosts formatted file
|
pihole_log_permissions=$(ls -ld "${PIHOLE_LOG}")
|
||||||
# that the DNS server is attempting to read. Since it's not formatted
|
log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}"
|
||||||
# correctly, there will be an entry for "bad address at line n"
|
mapfile -t pihole_log_head < <(head -n 20 ${PIHOLE_LOG})
|
||||||
# So we can check for that here and highlight it in red so the user can see it easily
|
log_write " ${COL_CYAN}-----head of $(basename ${PIHOLE_LOG})------${COL_NC}"
|
||||||
error_to_check_for=$(echo "${head_line}" | grep 'bad address at')
|
obfuscated_pihole_log "${pihole_log_head[@]}"
|
||||||
# Some users may not want to have the domains they visit sent to us
|
log_write ""
|
||||||
# To that end, we check for lines in the log that would contain a domain name
|
mapfile -t pihole_log_tail < <(tail -n 20 ${PIHOLE_LOG})
|
||||||
line_to_obfuscate=$(echo "${head_line}" | grep ': query\|: forwarded\|: reply')
|
log_write " ${COL_CYAN}-----tail of $(basename ${PIHOLE_LOG})------${COL_NC}"
|
||||||
# If the variable contains a value, it found an error in the log
|
obfuscated_pihole_log "${pihole_log_tail[@]}"
|
||||||
if [[ -n ${error_to_check_for} ]]; then
|
log_write ""
|
||||||
# So we can print it in red to make it visible to the user
|
# Set the IFS back to what it was
|
||||||
log_write " ${CROSS} ${COL_RED}${head_line}${COL_NC} (${FAQ_BAD_ADDRESS})"
|
IFS="$OLD_IFS"
|
||||||
else
|
|
||||||
# If the variable does not a value (the current default behavior), so do not obfuscate anything
|
|
||||||
if [[ -z ${OBFUSCATE} ]]; then
|
|
||||||
log_write " ${head_line}"
|
|
||||||
# Othwerise, a flag was passed to this command to obfuscate domains in the log
|
|
||||||
else
|
|
||||||
# So first check if there are domains in the log that should be obfuscated
|
|
||||||
if [[ -n ${line_to_obfuscate} ]]; then
|
|
||||||
# If there are, we need to use awk to replace only the domain name (the 6th field in the log)
|
|
||||||
# so we substitute the domain for the placeholder value
|
|
||||||
obfuscated_line=$(echo "${line_to_obfuscate}" | awk -v placeholder="${OBFUSCATED_PLACEHOLDER}" '{sub($6,placeholder); print $0}')
|
|
||||||
log_write " ${obfuscated_line}"
|
|
||||||
else
|
|
||||||
log_write " ${head_line}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
log_write ""
|
|
||||||
# Set the IFS back to what it was
|
|
||||||
IFS="$OLD_IFS"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tricorder_use_nc_or_curl() {
|
tricorder_use_nc_or_curl() {
|
||||||
|
|
Loading…
Reference in a new issue