From b0049df36626f78fd79853875245847b518b72b6 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Mon, 28 Oct 2024 14:15:17 +0530 Subject: [PATCH] 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 --- self-diagnostics/Makefile | 2 +- .../files/usr/sbin/self-diagnostics | 106 ++++++++++++------ .../self-diagnostics/helper/var_state_dump.sh | 13 +++ .../self-diagnostics/helper/wifi_assoclist.sh | 0 .../helper/wifi_radio_scan.sh | 0 .../helper/wifi_radio_status.sh | 0 .../share/self-diagnostics/spec/config.json | 4 +- .../share/self-diagnostics/spec/system.json | 10 +- .../usr/share/self-diagnostics/spec/wifi.json | 9 +- 9 files changed, 96 insertions(+), 48 deletions(-) create mode 100755 self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh mode change 100644 => 100755 self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_assoclist.sh mode change 100644 => 100755 self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_scan.sh mode change 100644 => 100755 self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_status.sh diff --git a/self-diagnostics/Makefile b/self-diagnostics/Makefile index 9f5274d11..186e19004 100644 --- a/self-diagnostics/Makefile +++ b/self-diagnostics/Makefile @@ -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 diff --git a/self-diagnostics/files/usr/sbin/self-diagnostics b/self-diagnostics/files/usr/sbin/self-diagnostics index ebd0f03c0..5b690fa70 100755 --- a/self-diagnostics/files/usr/sbin/self-diagnostics +++ b/self-diagnostics/files/usr/sbin/self-diagnostics @@ -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 } diff --git a/self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh b/self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh new file mode 100755 index 000000000..41359de9a --- /dev/null +++ b/self-diagnostics/files/usr/share/self-diagnostics/helper/var_state_dump.sh @@ -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 diff --git a/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_assoclist.sh b/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_assoclist.sh old mode 100644 new mode 100755 diff --git a/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_scan.sh b/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_scan.sh old mode 100644 new mode 100755 diff --git a/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_status.sh b/self-diagnostics/files/usr/share/self-diagnostics/helper/wifi_radio_status.sh old mode 100644 new mode 100755 diff --git a/self-diagnostics/files/usr/share/self-diagnostics/spec/config.json b/self-diagnostics/files/usr/share/self-diagnostics/spec/config.json index 23151def4..fda43cb53 100644 --- a/self-diagnostics/files/usr/share/self-diagnostics/spec/config.json +++ b/self-diagnostics/files/usr/share/self-diagnostics/spec/config.json @@ -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", diff --git a/self-diagnostics/files/usr/share/self-diagnostics/spec/system.json b/self-diagnostics/files/usr/share/self-diagnostics/spec/system.json index c1a5d284e..cf4933408 100644 --- a/self-diagnostics/files/usr/share/self-diagnostics/spec/system.json +++ b/self-diagnostics/files/usr/share/self-diagnostics/spec/system.json @@ -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", diff --git a/self-diagnostics/files/usr/share/self-diagnostics/spec/wifi.json b/self-diagnostics/files/usr/share/self-diagnostics/spec/wifi.json index 1fa64ada9..c57c1afe8 100644 --- a/self-diagnostics/files/usr/share/self-diagnostics/spec/wifi.json +++ b/self-diagnostics/files/usr/share/self-diagnostics/spec/wifi.json @@ -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",