From a757b5aae3cc7f2dbae84448e4ba9260504bd226 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sat, 9 May 2026 08:37:04 -0700 Subject: [PATCH] fix: ingest-plex pulls all rotated logs and uses clean source IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pull all Plex Media Server*.log files (active + .1 through .5) - Local filenames: cass-plex_media_server.N.log → source_id includes host - mapfile for clean SSH list; separate ssh per file (no pipeline complexity) - Auto-restart after ingest instead of prompting --- manage.sh | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/manage.sh b/manage.sh index 1e129d8..bc34da6 100755 --- a/manage.sh +++ b/manage.sh @@ -196,21 +196,36 @@ case "$CMD" in ingest-plex) PLEX_HOST="${1:-cass}" - PLEX_LOG_PATH="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log" - TMP_LOG="/tmp/turnstone-plex-$(date +%s).log" + PLEX_LOG_DIR="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs" + TMP_DIR="/tmp/turnstone-plex-$$" + mkdir -p "$TMP_DIR" - info "Pulling Plex log from ${PLEX_HOST}…" - if ! ssh "$PLEX_HOST" "cat '${PLEX_LOG_PATH}'" > "$TMP_LOG" 2>&1; then - rm -f "$TMP_LOG" - error "SSH to ${PLEX_HOST} failed. Ensure 'ssh ${PLEX_HOST}' works without a password prompt." + info "Listing Plex logs on ${PLEX_HOST}…" + # Get list of all rotated + active Plex logs + mapfile -t REMOTE_LOGS < <(ssh "$PLEX_HOST" \ + "ls '${PLEX_LOG_DIR}'/Plex\ Media\ Server*.log 2>/dev/null") \ + || { rm -rf "$TMP_DIR"; error "SSH to ${PLEX_HOST} failed."; } + + if [[ ${#REMOTE_LOGS[@]} -eq 0 ]]; then + rm -rf "$TMP_DIR" + error "No Plex logs found on ${PLEX_HOST} at ${PLEX_LOG_DIR}" fi - LINES=$(wc -l < "$TMP_LOG") - success "Pulled ${LINES} lines from ${PLEX_HOST}" - info "Ingesting into ${DB}…" - "$PYTHON" scripts/ingest_corpus.py "$TMP_LOG" "$DB" - rm -f "$TMP_LOG" - success "Done. Restart the server to refresh: ./manage.sh restart" + for remote_path in "${REMOTE_LOGS[@]}"; do + # Plex Media Server.1.log → cass-plex_media_server.1.log + local_name="${PLEX_HOST}-$(basename "$remote_path" | tr ' ' '_' | tr '[:upper:]' '[:lower:]')" + local_path="${TMP_DIR}/${local_name}" + info " ← $(basename "$remote_path")" + ssh "$PLEX_HOST" "cat '${remote_path}'" > "$local_path" + done + + info "Ingesting ${#REMOTE_LOGS[@]} log file(s) into ${DB}…" + for f in "$TMP_DIR"/*.log; do + "$PYTHON" scripts/ingest_corpus.py "$f" "$DB" + done + rm -rf "$TMP_DIR" + info "Done. Restarting server…" + exec bash "$0" restart ;; build-fts)