From 26fb409da54ce596f9128c680319dbe87184a2a8 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sat, 27 Jun 2026 14:04:53 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20Emby=204.9=20API=20breakage=20in=20sessio?= =?UTF-8?q?n=20report=20=E2=80=94=20update=20activity=20types=20and=20Item?= =?UTF-8?q?s=20UserId=20requirement;=20fix=20local=20outside=20function=20?= =?UTF-8?q?in=20cert=5Fmonitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Monitors/cert_monitor.sh | 2 +- Monitors/emby_session_report.sh | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Monitors/cert_monitor.sh b/Monitors/cert_monitor.sh index de1e71d..3ebcbe8 100755 --- a/Monitors/cert_monitor.sh +++ b/Monitors/cert_monitor.sh @@ -263,7 +263,7 @@ echo "" # Per-domain results — problems always shown with days remaining; healthy only with --log for domain in "${CERT_MONITOR_DOMAINS[@]}"; do [[ -z "$domain" ]] && continue - local _days="${DOMAIN_DAYS[$domain]:-?}" _exp="${DOMAIN_EXPIRY[$domain]:-unknown}" + _days="${DOMAIN_DAYS[$domain]:-?}" _exp="${DOMAIN_EXPIRY[$domain]:-unknown}" case "${DOMAIN_STATUS[$domain]:-UNKN}" in OK) log " $ICON_SUCCESS $domain — healthy (${_days}d, expires ${_exp})" ;; WARN) warn " $ICON_WARN $domain — warning (${_days}d, expires ${_exp})" ;; diff --git a/Monitors/emby_session_report.sh b/Monitors/emby_session_report.sh index e4995e8..b921448 100755 --- a/Monitors/emby_session_report.sh +++ b/Monitors/emby_session_report.sh @@ -257,31 +257,28 @@ REPORT_START=$(date -d "${EMBY_REPORT_DAYS} days ago" '+%Y-%m-%dT00:00:00.000Z') ACTIVITY=$(emby_api "System/ActivityLog/Entries?MinDate=${REPORT_START}&Limit=1000" \ 2>/dev/null) || { warn "Could not fetch activity log"; ACTIVITY="{}"; } +# Emby 4.9 event types changed: VideoPlayback → playback.stop (completed session) TOTAL_PLAYS=$(echo "$ACTIVITY" | \ - jq '[.Items // [] | .[] | select(.Type == "VideoPlayback" or .Type == "AudioPlayback")] | length' \ - 2>/dev/null || echo 0) - -TRANSCODE_PLAYS=$(echo "$ACTIVITY" | \ - jq '[.Items // [] | .[] | select(.Type == "VideoPlaybackUnplugged" or - (.Type == "VideoPlayback" and (.Overview // "" | contains("Transcode"))))] | length' \ + jq '[.Items // [] | .[] | select(.Type == "playback.stop")] | length' \ 2>/dev/null || echo 0) echo " $ICON_EMBY Total play events: $TOTAL_PLAYS" - -if [[ "$TOTAL_PLAYS" -gt 0 ]]; then - TRANSCODE_PCT=$(awk "BEGIN {printf \"%.0f\", ($TRANSCODE_PLAYS / $TOTAL_PLAYS) * 100}") - DIRECT_PCT=$(( 100 - TRANSCODE_PCT )) - echo " $ICON_EMBY Direct play: ~${DIRECT_PCT}%" - echo " $ICON_EMBY Transcoded: ~${TRANSCODE_PCT}%" - log "$ICON_EMBY Activity: $TOTAL_PLAYS plays — ~${DIRECT_PCT}% direct / ~${TRANSCODE_PCT}% transcode" -fi +[[ "$TOTAL_PLAYS" -gt 0 ]] && log "$ICON_EMBY Activity: $TOTAL_PLAYS plays" echo "" # ── Top Content ─────────────────────────────────────────────────────────────────────────────── echo "━━━ $ICON_EMBY Top ${EMBY_REPORT_TOP_N} Content ━━━" -TOP_ITEMS=$(emby_api "Items?SortBy=DatePlayed&SortOrder=Descending&Limit=${EMBY_REPORT_TOP_N}&Recursive=true&Fields=Overview&IncludeItemTypes=Movie,Episode" \ - 2>/dev/null) || { warn "Could not fetch top content"; TOP_ITEMS="{}"; } +# Emby 4.9 requires a UserId on the Items endpoint — fetch admin ID first +EMBY_ADMIN_ID=$(emby_api "Users" 2>/dev/null | \ + jq -r '[.[] | select(.Policy.IsAdministrator == true)] | first | .Id // empty' 2>/dev/null) +if [[ -z "$EMBY_ADMIN_ID" ]]; then + warn "Could not resolve admin UserId — skipping top content" + TOP_ITEMS="{}" +else + TOP_ITEMS=$(emby_api "Users/${EMBY_ADMIN_ID}/Items?SortBy=DatePlayed&SortOrder=Descending&Limit=${EMBY_REPORT_TOP_N}&Recursive=true&Fields=Overview&IncludeItemTypes=Movie,Episode" \ + 2>/dev/null) || { warn "Could not fetch top content"; TOP_ITEMS="{}"; } +fi TOP_COUNT=$(echo "$TOP_ITEMS" | jq '.Items // [] | length' 2>/dev/null || echo 0) if [[ "$TOP_COUNT" -gt 0 ]]; then