feat: Add SHZ log inspection and HighGo database querying capabilities
- Introduced `inspect-shz-logs` skill for inspecting local and production logs with bounded read-only commands. - Added `view.sh` script for log viewing with options for following logs and filtering by keywords. - Created `query-shz-highgo` skill for querying the SHZ HighGo database through an SSH gateway. - Implemented read-only SQL execution with strict controls on allowed statements and query structure. - Added new domain and mapper classes for managing outdoor fair job associations. - Enhanced `OutdoorFairController` to support job listing and management for outdoor fairs. - Created SQL scripts for initializing outdoor fair job data and managing menu visibility.
This commit is contained in:
109
.claude/skills/inspect-shz-logs/scripts/view.sh
Executable file
109
.claude/skills/inspect-shz-logs/scripts/view.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
skill_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
project_dir="$(cd "${skill_dir}/../../.." && pwd)"
|
||||
local_log="${project_dir}/.local/logs/backend.log"
|
||||
|
||||
ssh_host="root@39.98.44.136"
|
||||
ssh_port="6022"
|
||||
remote_log_dir="/opt/service/project/shz-backend/logs"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
view.sh local [lines] [--follow]
|
||||
view.sh online [backend|error|info|user] [lines] [--follow]
|
||||
|
||||
Examples:
|
||||
view.sh local 200
|
||||
view.sh local 100 --follow
|
||||
view.sh online backend 200
|
||||
view.sh online error 500 --follow
|
||||
EOF
|
||||
}
|
||||
|
||||
validate_lines() {
|
||||
local lines="$1"
|
||||
if [[ ! "${lines}" =~ ^[0-9]+$ ]] || (( lines < 1 || lines > 5000 )); then
|
||||
echo "Lines must be an integer between 1 and 5000: ${lines}" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
validate_follow() {
|
||||
local follow="${1:-}"
|
||||
if [[ -n "${follow}" && "${follow}" != "--follow" ]]; then
|
||||
echo "Unknown option: ${follow}" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
view_local() {
|
||||
local lines="${1:-200}"
|
||||
local follow="${2:-}"
|
||||
validate_lines "${lines}"
|
||||
validate_follow "${follow}"
|
||||
|
||||
if [[ ! -f "${local_log}" ]]; then
|
||||
echo "Local log does not exist: ${local_log}" >&2
|
||||
echo "Start the project first with: ./local.sh start" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${follow}" == "--follow" ]]; then
|
||||
tail -n "${lines}" -F -- "${local_log}"
|
||||
else
|
||||
tail -n "${lines}" -- "${local_log}"
|
||||
fi
|
||||
}
|
||||
|
||||
view_online() {
|
||||
local kind="${1:-backend}"
|
||||
local lines="${2:-200}"
|
||||
local follow="${3:-}"
|
||||
local remote_file
|
||||
|
||||
case "${kind}" in
|
||||
backend) remote_file="${remote_log_dir}/backend.log" ;;
|
||||
error) remote_file="${remote_log_dir}/sys-error.log" ;;
|
||||
info) remote_file="${remote_log_dir}/sys-info.log" ;;
|
||||
user) remote_file="${remote_log_dir}/sys-user.log" ;;
|
||||
*)
|
||||
echo "Unknown online log type: ${kind}" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
validate_lines "${lines}"
|
||||
validate_follow "${follow}"
|
||||
|
||||
if [[ "${follow}" == "--follow" ]]; then
|
||||
ssh -p "${ssh_port}" -o BatchMode=yes -o ConnectTimeout=10 "${ssh_host}" \
|
||||
tail -n "${lines}" -F -- "${remote_file}"
|
||||
else
|
||||
ssh -p "${ssh_port}" -o BatchMode=yes -o ConnectTimeout=10 "${ssh_host}" \
|
||||
tail -n "${lines}" -- "${remote_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
target="${1:-}"
|
||||
case "${target}" in
|
||||
local)
|
||||
[[ $# -le 3 ]] || { usage >&2; exit 2; }
|
||||
view_local "${2:-200}" "${3:-}"
|
||||
;;
|
||||
online)
|
||||
[[ $# -le 4 ]] || { usage >&2; exit 2; }
|
||||
view_online "${2:-backend}" "${3:-200}" "${4:-}"
|
||||
;;
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
usage >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user