self-diagnostics: 1.0.10

- Print report_dir along with report_file
- Stop verbose logging of exec_cmds to prevent syslog overflow
- Increased timeouts of wifi diagnotics scripts
- Added report_dir in error output, if failed to generate tar
This commit is contained in:
Vivek Kumar Dutta 2024-10-28 14:15:17 +05:30
parent 7115c1734e
commit b0049df366
9 changed files with 96 additions and 48 deletions

View file

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=self-diagnostics
PKG_VERSION:=1.0.9
PKG_VERSION:=1.0.10
PKG_RELEASE:=1
PKG_LICENSE:=GPL-2.0-only

View file

@ -5,16 +5,19 @@
JSON_OUT=0
SPEC_DIR="/usr/share/self-diagnostics/spec"
SPEC_EXT_DIR="/etc/self-diagnostics/spec"
REPORT_DIR="$(mktemp -p /var/log/ -d)"
REPORT_PATH="/var/log/"
REPORT_TEMP_DIR="$(mktemp -p ${REPORT_PATH} -d)"
REPORT_NAME="self-test-diagnostics"
VERBOSE=0
COMPOPTS=""
TIMEOUT=5
JSON_OUT_BUFFER=""
cleanup()
{
[ -d "${REPORT_DIR}" ] && \
rm -rf ${REPORT_DIR}
if [ -d "${REPORT_TEMP_DIR}" ]; then
rm -rf ${REPORT_TEMP_DIR}
fi
}
trap cleanup EXIT
@ -35,13 +38,20 @@ help()
log()
{
log_file="${REPORT_DIR}/execution.log"
log_file="${REPORT_TEMP_DIR}/execution.log"
if [ "$VERBOSE" -eq 1 ]; then
logger -t $0 "$*"
logger -p debug -t $0 "$*"
fi
echo "[$(date +%Y:%m:%d-%H:%M:%S)] $*" >> ${log_file}
}
err_log()
{
log_file="${REPORT_TEMP_DIR}/execution.log"
logger -p err -t $0 "$*"
echo "[$(date +%Y:%m:%d-%H:%M:%S) ERR] $*" >> ${log_file}
}
# Alias ubus to have a smaller 5-second timeout on all subsequent calls
ubus()
{
@ -60,10 +70,26 @@ config_load()
local temp
local MODEL SERIAL
log "# Starting Self diagnostics tests #"
# Default value for MODEL and SERIAL
MODEL="XXX"
SERIAL="FFFFFFFFFFFF"
MODEL="$(db get device.deviceinfo.ModelName)"
SERIAL="$(db get device.deviceinfo.SerialNumber)"
log "# Starting Self diagnostics tests #"
if [ "${JSON_OUT}" -eq 1 ]; then
json_init
json_add_string "report_dir" "${REPORT_PATH}"
JSON_OUT_BUFFER="$(json_dump)"
else
echo "report_dir: ${REPORT_PATH}"
fi
temp="$(db -q get device.deviceinfo.ModelName)"
[ -d "${temp}" ] && \
MODEL="${temp}"
temp="$(db -q get device.deviceinfo.SerialNumber)"
[ -d "${temp}" ] && \
SERIAL="${temp}"
temp="$(uci -q get self-diagnostics.globals.extended_spec_dir)"
[ -d "${temp}" ] && \
@ -94,7 +120,7 @@ exec_spec()
json_file="$1"
[ -z "$json_file" ] && {
log "No/invalid spec json_file"
err_log "No/invalid spec json_file"
return 1
}
@ -102,12 +128,12 @@ exec_spec()
json_init
json_load_file "${json_file}" || {
log "Failed to load ${json_file} spec file"
err_log "Failed to load ${json_file} spec file"
return 1
}
name="$(basename ${json_file})"
export_path="${REPORT_DIR}/${name//.json/.log}"
export_path="${REPORT_TEMP_DIR}/${name//.json/.log}"
exec_skip=0
if json_is_a dependency array; then
@ -122,7 +148,7 @@ exec_spec()
if [ "$type" == "file" ]; then
json_get_var file file
if [ ! -e "$file" ]; then
log "${json_file} has unmet file dependency $file"
err_log "${json_file} has unmet file dependency $file"
exec_skip=1
json_select ..
continue
@ -135,7 +161,7 @@ exec_spec()
fi
[ "${exec_skip}" -eq 1 ] && {
log "Dependency not satisfied for ${json_file}"
err_log "Dependency not satisfied for ${json_file}"
return 0
}
@ -149,7 +175,10 @@ exec_spec()
for key in $keys; do
if json_is_a $key object; then
json_select $key
local cmd_skip file
cmd_skip=0
file=""
if json_is_a dependency array; then
json_select "dependency"
json_get_keys d_keys
@ -174,7 +203,7 @@ exec_spec()
[ $cmd_skip -eq 1 ] && {
json_select ..
log "Dependency not satisfied for ${file}"
err_log "Dependency not satisfied for ${file}"
continue
}
@ -192,24 +221,14 @@ exec_spec()
echo "# $description #">> $export_path
echo "# Exec [$cmd], timeout [$exec_timeout] #" >> $export_path
echo "##########################################" >> $export_path
if [ "$VERBOSE" -eq 1 ]; then
if [[ "$cmd" == *"logread "* ]]; then
eval timeout ${exec_timeout} $cmd 2>&1 | tee -a $export_path
rc=$?
else
eval timeout ${exec_timeout} $cmd 2>&1 | tee -a $export_path | logger -t self-diagnostics
rc=$?
fi
else
eval timeout ${exec_timeout} $cmd >> $export_path 2>&1
rc=$?
fi
echo "######## Execution return code $rc ######" >> $export_path
eval timeout ${exec_timeout} $cmd >> $export_path 2>&1
rc=$?
echo "######## Execution done return code $rc ######" >> $export_path
if [ "$rc" -eq 0 ]; then
log "Execution [$cmd] completed"
else
log "Execution [$cmd] Failed/Timeout with $rc exit code"
err_log "Execution [$cmd] Failed/Timeout with $rc exit code"
fi
echo >> $export_path
@ -314,38 +333,51 @@ list_modules()
generate_report()
{
local filename report_path
local filename
report_path="$(dirname "${REPORT_DIR}")"
filename="${report_path}/${REPORT_NAME}"
filename="${REPORT_PATH}/${REPORT_NAME}"
[ -f "${filename}.tar" ] && rm "${filename}.tar"
[ -f "${filename}.tar.gz" ] && rm "${filename}.tar.gz"
log "# Report generation completed #"
cd ${REPORT_DIR} && {
cd ${REPORT_TEMP_DIR} && {
filename="${filename}.tar"
tar -cf "${filename}" *
}
rm -r "$REPORT_DIR"
if [ -n "$COMPOPTS" ]; then
gzip -${COMPOPTS} -f "${filename}"
filename="${filename}.gz"
fi
# Move logs if failed to generate tar
if [ ! -f "${filename}" ]; then
mv ${REPORT_TEMP_DIR}/*.log ${REPORT_PATH}/
fi
if [ "${JSON_OUT}" -eq 1 ]; then
json_init
json_add_string result "${filename}"
json_load "${JSON_OUT_BUFFER}"
if [ -f "${filename}" ]; then
json_add_string result "${filename}"
else
log "error: Failed to generate report tar, check logs in ${REPORT_PATH}"
json_add_string error "Failed to generate report tar, check logs in ${REPORT_PATH}"
fi
json_dump
else
echo "${filename}"
if [ -f "${filename}" ]; then
echo "result: ${filename}"
else
log "error: Failed to generate report tar, check logs in ${REPORT_PATH}"
echo "error: Failed to generate report tar, check logs in ${REPORT_PATH}"
fi
fi
}
[ ! -d "${SPEC_DIR}" ] && {
log "# ${SPEC_DIR} does not exits"
log "# ${SPEC_DIR} does not exist"
exit 1
}

View file

@ -0,0 +1,13 @@
#!/bin/sh
function dump_var_state_file()
{
for f in `ls -1 /var/state/`; do
if [ -f "var/state/$f" ]; then
echo "cat /var/state/$f"
cat "/var/state/$f"
fi
done
}
dump_var_state_file

View file

@ -18,8 +18,8 @@
"cmd": "uci export"
},
{
"description": "Runtime Configuration",
"cmd": "cat /var/state/*"
"description": "Runtime Configuration (/var/state/)",
"cmd": "sh /usr/share/self-diagnostics/helper/var_state_dump.sh"
},
{
"description": "Firmware Environment",

View file

@ -13,6 +13,10 @@
"description": "Board Info",
"cmd": "ubus call system board"
},
{
"description": "System Log",
"cmd": "logread"
},
{
"description": "Running Processes",
"cmd": "top -b -n 1"
@ -21,13 +25,9 @@
"description": "Kernel Parameters",
"cmd": "sysctl -A 2>/dev/null"
},
{
"description": "System Log",
"cmd": "timeout 5 logread -l 1000"
},
{
"description": "Driver Message",
"cmd": "timeout 5 dmesg"
"cmd": "dmesg"
},
{
"description": "PCI Devices",

View file

@ -17,15 +17,18 @@
},
{
"description": "WiFi Radio Status",
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_radio_status.sh"
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_radio_status.sh",
"timeout": 10
},
{
"description": "Get radio scan",
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_radio_scan.sh"
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_radio_scan.sh",
"timeout": 10
},
{
"description": "Get Assoc List",
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_assoclist.sh"
"cmd": "sh /usr/share/self-diagnostics/helper/wifi_assoclist.sh",
"timeout": 10
},
{
"description": "List Wireless Devices",