From e300cde6042ca20cbb7e3aadcd986e4a7405034d Mon Sep 17 00:00:00 2001 From: brknkfr <4104421+brknkfr@users.noreply.github.com> Date: Mon, 27 Jan 2025 06:54:31 +0100 Subject: [PATCH] [jellyfin_sessions] Simple plugin to check active sessions on a jellyfin media system (#1476) * [jellyfin_sessions] A simple plugin to check active sessions on a jellyfin media system * Update plugins/jellyfin/jellyfin_sessions Co-authored-by: Kenyon Ralph --------- Co-authored-by: Sebastian L. Co-authored-by: Kenyon Ralph --- plugins/jellyfin/jellyfin_sessions | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 plugins/jellyfin/jellyfin_sessions diff --git a/plugins/jellyfin/jellyfin_sessions b/plugins/jellyfin/jellyfin_sessions new file mode 100755 index 00000000..abcc2a8e --- /dev/null +++ b/plugins/jellyfin/jellyfin_sessions @@ -0,0 +1,86 @@ +#!/usr/bin/env sh + +set -e + +: << =cut + +=head1 NAME + +jellyfin_sessions - Monitor active sessions on a jellyfin media system + +=head1 APPLICABLE SYSTEMS + +Jellyfin media system + +=head1 CONFIGURATION + +Requires a api key for the plugin and an installed jq, a command-line json +processor. + +You may specify the URL where to get the statistics. + + url - URL of jellyfin + max_time - Timeout curl - defaults to 3 seconds + interval - Interval in seconds to check + api_key - API key from jellyfin + + [jellyfin_sessions] + env.url http://127.0.0.1:8096 + env.max_time 3 + env.interval 600 + env.api_key + +=head1 AUTHOR + +Copyright (C) 2025 Sebastian L. (https://momou.ch) + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=manual + #%# capabilities=autoconf + +=cut + +. "$MUNIN_LIBDIR/plugins/plugin.sh" + +url=${url:-"http://127.0.0.1:8096"} +url_sessions="$url/Sessions" +max_time=${max_time:-3} +interval=${interval:-600} +api_key=${api_key:-} + +case $1 in + autoconf) + if [ -x "$(command -v curl)" ]; then + if [ -x "$(command -v jq)" ]; then + if [ -z "$api_key" ]; then + echo "no (api_key not set)" && exit 1 + else + curl -s -f -m "$max_time" -H "Authorization: MediaBrowser Token=$api_key" -I -X GET "$url_sessions" | grep -iq "Content-Type: application/json" && echo "yes" && exit 0 || echo "no (invalid or empty response from api endpoint ($url_sessions))" && exit 1 + fi + else + echo "no (jq not found)" && exit 1 + fi + else + echo "no (curl not found)" && exit 0 + fi + ;; + + config) + echo "graph_title Sessions on Jellyfin system" + echo "graph_vlabel sessions" + echo "sessions.label sessions" + exit 0 + ;; +esac + +if active_sessions=$(curl -s -f -m "$max_time" -H "Authorization: MediaBrowser Token=$api_key" -X GET "$url_sessions"?activeWithinSeconds="$interval" | jq '. | length') | grep -E "[0-9]+"; then + echo "sessions.value $active_sessions" +else + echo "sessions.value U" +fi +