blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.66k stars 308 forks source link

Kill_stream.py does not work where no Tautulli public url is set, and Tautulli is configured with an http root (i.e. subfolder) #367

Closed NeeWii closed 1 year ago

NeeWii commented 1 year ago

Using "--richMessage discord" as a script argument, gave the following error messages:

2023-01-04 13:49:24 - INFO :: CP Server Thread-12 : Tautulli Notifiers :: Sending Webhook notification... 2023-01-04 13:49:24 - ERROR :: CP Server Thread-12 : Tautulli Notifiers :: Webhook notification failed. Verify your notification agent settings are correct. 2023-01-04 13:49:24 - ERROR :: CP Server Thread-12 : Tautulli Notifiers :: Request raised a HTTP error: [400] Bad Request (local client error). 2023-01-04 13:49:24 - DEBUG :: CP Server Thread-12 : Tautulli Notifiers :: Request response: {"embeds": ["0"]} 2023-01-04 13:49:24 - DEBUG :: Thread-57 (run_script) : Tautulli Notifiers :: Subprocess returned with status code 0.

From some searching online, this suggested Discord itself was rejecting one of the JSON elements. I commented out various bits of the kill_stream.py "discord_message" block until I found the culprit. I believe this is an issue with Discord rejecting the value of the TAUTULLI_LINK variable set within the kill_stream.py script itself, because the kill_stream.py script doesn't seem to account for setups that are configured using an "HTTP Root" in Tautulli settings --> Web Interface (i.e. the Tautulli url is set up as a subfolder, e.g.http://mydomain**/tautulli**), which is how my Tautulli instance is configured. Where an http root is configured, Tautulli's environmental public url variable defaults to "/tautulli/" (or at least, this is what the debug error info shows from the kill_stream.py script), rather than "/". The script is written to capture the latter scenario and revert to the localhost url instead, but not the former - it tries to pass "/tautulli/", which (I think) Discord identifies as an invalid url and rejects. The fix for me was as simple as going to Tautulli settings --> Web Interface --> Public Tautulli Domain, and ensuring that a url value is entered there (this could even just be a localhost url, but it has to be a valid url I think).

The alternative fix was to go into the kill_stream script itself and change line 74 from if TAUTULLI_PUBLIC_URL != '/': to if TAUTULLI_PUBLIC_URL != '/tautulli/': This will result in Tautulli's localhost address being sent to Discord as the TAUTULLI_LINK variable, which Discord accepts and so the notification works.

PROPOSED SOLUTION: To capture both scenarios, changing the "if" block at line 74 to the below (adding an embedded "if" to capture the http root scenario) seems to work.

`if TAUTULLI_PUBLIC_URL != '/': if TAUTULLI_PUBLIC_URL != '/tautulli/':

Check to see if there is a public URL set in Tautulli

    TAUTULLI_LINK = TAUTULLI_PUBLIC_URL
else:
    TAUTULLI_LINK = TAUTULLI_URL`

(Apologies I don't know how to get the above code to indent properly in Github). Perhaps there is a neater way of doing this also though!

blacktwin commented 1 year ago

The fix for me was as simple as going to Tautulli settings --> Web Interface --> Public Tautulli Domain, and ensuring that a url value is entered there

I'm not understanding the issue then? Sounds like Tautulli wasn't configured correctly, this caused issues with the script, you fixed the configuration, now the script works. Is that correct?

NeeWii commented 1 year ago

I guess that depends on what you consider correct configuration of Tautulli? I have never had any need until now to have put anything in that field, Tautulli works perfectly well without it - so I imagine many others similarly don't fill this out. The script as it stands even acknowledges that a user might not have entered a public url in that configuration (i.e. the first IF statement seems designed to capture that, "if TAUTULLI_PUBLIC_URL != '/':"), it just doesn't capture instances where a user has configured tautulli with an http root and hasn't entered a public url in that field.

The suggested tweak to the script above would capture that scenario. Alternatively, even just adding a comment in the readme in the discord notifications section, that a public url needs to be entered for the script to work properly for discord notifications (when an http root is configured), would achieve the same goal.

JonnyWong16 commented 1 year ago

if TAUTULLI_PUBLIC_URL != '/tautulli/' won't work if someone has configured a different http root (e.g. /stats).

Better to check if TAUTULLI_PUBLIC_URL.startswith('http').