mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
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:
parent
7115c1734e
commit
b0049df366
9 changed files with 96 additions and 48 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=self-diagnostics
|
PKG_NAME:=self-diagnostics
|
||||||
PKG_VERSION:=1.0.9
|
PKG_VERSION:=1.0.10
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-2.0-only
|
PKG_LICENSE:=GPL-2.0-only
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,19 @@
|
||||||
JSON_OUT=0
|
JSON_OUT=0
|
||||||
SPEC_DIR="/usr/share/self-diagnostics/spec"
|
SPEC_DIR="/usr/share/self-diagnostics/spec"
|
||||||
SPEC_EXT_DIR="/etc/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"
|
REPORT_NAME="self-test-diagnostics"
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
COMPOPTS=""
|
COMPOPTS=""
|
||||||
TIMEOUT=5
|
TIMEOUT=5
|
||||||
|
JSON_OUT_BUFFER=""
|
||||||
|
|
||||||
cleanup()
|
cleanup()
|
||||||
{
|
{
|
||||||
[ -d "${REPORT_DIR}" ] && \
|
if [ -d "${REPORT_TEMP_DIR}" ]; then
|
||||||
rm -rf ${REPORT_DIR}
|
rm -rf ${REPORT_TEMP_DIR}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
@ -35,13 +38,20 @@ help()
|
||||||
|
|
||||||
log()
|
log()
|
||||||
{
|
{
|
||||||
log_file="${REPORT_DIR}/execution.log"
|
log_file="${REPORT_TEMP_DIR}/execution.log"
|
||||||
if [ "$VERBOSE" -eq 1 ]; then
|
if [ "$VERBOSE" -eq 1 ]; then
|
||||||
logger -t $0 "$*"
|
logger -p debug -t $0 "$*"
|
||||||
fi
|
fi
|
||||||
echo "[$(date +%Y:%m:%d-%H:%M:%S)] $*" >> ${log_file}
|
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
|
# Alias ubus to have a smaller 5-second timeout on all subsequent calls
|
||||||
ubus()
|
ubus()
|
||||||
{
|
{
|
||||||
|
|
@ -60,10 +70,26 @@ config_load()
|
||||||
local temp
|
local temp
|
||||||
local MODEL SERIAL
|
local MODEL SERIAL
|
||||||
|
|
||||||
log "# Starting Self diagnostics tests #"
|
# Default value for MODEL and SERIAL
|
||||||
|
MODEL="XXX"
|
||||||
|
SERIAL="FFFFFFFFFFFF"
|
||||||
|
|
||||||
MODEL="$(db get device.deviceinfo.ModelName)"
|
log "# Starting Self diagnostics tests #"
|
||||||
SERIAL="$(db get device.deviceinfo.SerialNumber)"
|
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)"
|
temp="$(uci -q get self-diagnostics.globals.extended_spec_dir)"
|
||||||
[ -d "${temp}" ] && \
|
[ -d "${temp}" ] && \
|
||||||
|
|
@ -94,7 +120,7 @@ exec_spec()
|
||||||
|
|
||||||
json_file="$1"
|
json_file="$1"
|
||||||
[ -z "$json_file" ] && {
|
[ -z "$json_file" ] && {
|
||||||
log "No/invalid spec json_file"
|
err_log "No/invalid spec json_file"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,12 +128,12 @@ exec_spec()
|
||||||
|
|
||||||
json_init
|
json_init
|
||||||
json_load_file "${json_file}" || {
|
json_load_file "${json_file}" || {
|
||||||
log "Failed to load ${json_file} spec file"
|
err_log "Failed to load ${json_file} spec file"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
name="$(basename ${json_file})"
|
name="$(basename ${json_file})"
|
||||||
export_path="${REPORT_DIR}/${name//.json/.log}"
|
export_path="${REPORT_TEMP_DIR}/${name//.json/.log}"
|
||||||
|
|
||||||
exec_skip=0
|
exec_skip=0
|
||||||
if json_is_a dependency array; then
|
if json_is_a dependency array; then
|
||||||
|
|
@ -122,7 +148,7 @@ exec_spec()
|
||||||
if [ "$type" == "file" ]; then
|
if [ "$type" == "file" ]; then
|
||||||
json_get_var file file
|
json_get_var file file
|
||||||
if [ ! -e "$file" ]; then
|
if [ ! -e "$file" ]; then
|
||||||
log "${json_file} has unmet file dependency $file"
|
err_log "${json_file} has unmet file dependency $file"
|
||||||
exec_skip=1
|
exec_skip=1
|
||||||
json_select ..
|
json_select ..
|
||||||
continue
|
continue
|
||||||
|
|
@ -135,7 +161,7 @@ exec_spec()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "${exec_skip}" -eq 1 ] && {
|
[ "${exec_skip}" -eq 1 ] && {
|
||||||
log "Dependency not satisfied for ${json_file}"
|
err_log "Dependency not satisfied for ${json_file}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,7 +175,10 @@ exec_spec()
|
||||||
for key in $keys; do
|
for key in $keys; do
|
||||||
if json_is_a $key object; then
|
if json_is_a $key object; then
|
||||||
json_select $key
|
json_select $key
|
||||||
|
local cmd_skip file
|
||||||
|
|
||||||
cmd_skip=0
|
cmd_skip=0
|
||||||
|
file=""
|
||||||
if json_is_a dependency array; then
|
if json_is_a dependency array; then
|
||||||
json_select "dependency"
|
json_select "dependency"
|
||||||
json_get_keys d_keys
|
json_get_keys d_keys
|
||||||
|
|
@ -174,7 +203,7 @@ exec_spec()
|
||||||
|
|
||||||
[ $cmd_skip -eq 1 ] && {
|
[ $cmd_skip -eq 1 ] && {
|
||||||
json_select ..
|
json_select ..
|
||||||
log "Dependency not satisfied for ${file}"
|
err_log "Dependency not satisfied for ${file}"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,24 +221,14 @@ exec_spec()
|
||||||
echo "# $description #">> $export_path
|
echo "# $description #">> $export_path
|
||||||
echo "# Exec [$cmd], timeout [$exec_timeout] #" >> $export_path
|
echo "# Exec [$cmd], timeout [$exec_timeout] #" >> $export_path
|
||||||
echo "##########################################" >> $export_path
|
echo "##########################################" >> $export_path
|
||||||
if [ "$VERBOSE" -eq 1 ]; then
|
eval timeout ${exec_timeout} $cmd >> $export_path 2>&1
|
||||||
if [[ "$cmd" == *"logread "* ]]; then
|
rc=$?
|
||||||
eval timeout ${exec_timeout} $cmd 2>&1 | tee -a $export_path
|
echo "######## Execution done return code $rc ######" >> $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
|
|
||||||
|
|
||||||
if [ "$rc" -eq 0 ]; then
|
if [ "$rc" -eq 0 ]; then
|
||||||
log "Execution [$cmd] completed"
|
log "Execution [$cmd] completed"
|
||||||
else
|
else
|
||||||
log "Execution [$cmd] Failed/Timeout with $rc exit code"
|
err_log "Execution [$cmd] Failed/Timeout with $rc exit code"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo >> $export_path
|
echo >> $export_path
|
||||||
|
|
@ -314,38 +333,51 @@ list_modules()
|
||||||
|
|
||||||
generate_report()
|
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" ] && rm "${filename}.tar"
|
||||||
[ -f "${filename}.tar.gz" ] && rm "${filename}.tar.gz"
|
[ -f "${filename}.tar.gz" ] && rm "${filename}.tar.gz"
|
||||||
|
|
||||||
log "# Report generation completed #"
|
log "# Report generation completed #"
|
||||||
cd ${REPORT_DIR} && {
|
cd ${REPORT_TEMP_DIR} && {
|
||||||
filename="${filename}.tar"
|
filename="${filename}.tar"
|
||||||
tar -cf "${filename}" *
|
tar -cf "${filename}" *
|
||||||
}
|
}
|
||||||
|
|
||||||
rm -r "$REPORT_DIR"
|
|
||||||
|
|
||||||
if [ -n "$COMPOPTS" ]; then
|
if [ -n "$COMPOPTS" ]; then
|
||||||
gzip -${COMPOPTS} -f "${filename}"
|
gzip -${COMPOPTS} -f "${filename}"
|
||||||
filename="${filename}.gz"
|
filename="${filename}.gz"
|
||||||
fi
|
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
|
if [ "${JSON_OUT}" -eq 1 ]; then
|
||||||
json_init
|
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
|
json_dump
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
[ ! -d "${SPEC_DIR}" ] && {
|
[ ! -d "${SPEC_DIR}" ] && {
|
||||||
log "# ${SPEC_DIR} does not exits"
|
log "# ${SPEC_DIR} does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh
Executable file
13
self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh
Executable 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
|
||||||
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_assoclist.sh
Normal file → Executable file
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_assoclist.sh
Normal file → Executable file
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_scan.sh
Normal file → Executable file
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_scan.sh
Normal file → Executable file
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_status.sh
Normal file → Executable file
0
self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_status.sh
Normal file → Executable file
|
|
@ -18,8 +18,8 @@
|
||||||
"cmd": "uci export"
|
"cmd": "uci export"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Runtime Configuration",
|
"description": "Runtime Configuration (/var/state/)",
|
||||||
"cmd": "cat /var/state/*"
|
"cmd": "sh /usr/share/self-diagnostics/helper/var_state_dump.sh"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Firmware Environment",
|
"description": "Firmware Environment",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@
|
||||||
"description": "Board Info",
|
"description": "Board Info",
|
||||||
"cmd": "ubus call system board"
|
"cmd": "ubus call system board"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "System Log",
|
||||||
|
"cmd": "logread"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"description": "Running Processes",
|
"description": "Running Processes",
|
||||||
"cmd": "top -b -n 1"
|
"cmd": "top -b -n 1"
|
||||||
|
|
@ -21,13 +25,9 @@
|
||||||
"description": "Kernel Parameters",
|
"description": "Kernel Parameters",
|
||||||
"cmd": "sysctl -A 2>/dev/null"
|
"cmd": "sysctl -A 2>/dev/null"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"description": "System Log",
|
|
||||||
"cmd": "timeout 5 logread -l 1000"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"description": "Driver Message",
|
"description": "Driver Message",
|
||||||
"cmd": "timeout 5 dmesg"
|
"cmd": "dmesg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "PCI Devices",
|
"description": "PCI Devices",
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,18 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "WiFi Radio Status",
|
"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",
|
"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",
|
"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",
|
"description": "List Wireless Devices",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue