mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-20 21:33:18 -07:00
Merge pull request #289 from JonnyWong16/miscellaneous-fixes
Use Plex API to check remote access down
This commit is contained in:
commit
558f7873f5
8 changed files with 219 additions and 186 deletions
|
@ -405,9 +405,9 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="monitor_remote_access" name="monitor_remote_access" value="1" ${config['monitor_remote_access']}> Monitor Plex Remote Access
|
<input type="checkbox" class="monitor-settings" id="monitor_remote_access" name="monitor_remote_access" value="1" ${config['monitor_remote_access']}> Monitor Plex Remote Access
|
||||||
</label>
|
</label>
|
||||||
<p class="help-block">Enable to have PlexPy check if remote access to the Plex Media Server goes down. (Must have remote access set up in Plex.)</p>
|
<p class="help-block">Enable to have PlexPy check if remote access to the Plex Media Server goes down. Your server needs to have remote access enabled.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="padded-header">
|
<div class="padded-header">
|
||||||
|
@ -479,7 +479,12 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="movie_notify_enable" id="movie_notify_enable" value="1" ${config['movie_notify_enable']}> Enable Movie and TV Notifications
|
<input type="checkbox" name="movie_notify_enable" id="movie_notify_enable" value="1" ${config['movie_notify_enable']}> Enable Movie Notifications
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="tv_notify_enable" id="tv_notify_enable" value="1" ${config['tv_notify_enable']}> Enable TV Show Notifications
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
@ -527,7 +532,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
</div>
|
</div>
|
||||||
<div id="notify_recently_added_delay_error" class="alert alert-danger settings-alert" role="alert"></div>
|
<div id="notify_recently_added_delay_error" class="alert alert-danger settings-alert" role="alert"></div>
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block">Set the delay for recently added notifications to allow metadata to be processes. Minimum 60 seconds.</p>
|
<p class="help-block">Set the delay for recently added notifications to allow metadata to be processed. Minimum 60 seconds.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="padded-header">
|
<div class="padded-header">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%
|
<%
|
||||||
import plexpy
|
import plexpy
|
||||||
from plexpy import common
|
from plexpy import common
|
||||||
%>
|
%>
|
||||||
|
@ -130,7 +130,10 @@ from plexpy import common
|
||||||
<p class="help-block">PlexPy supports a wide variety of notification options. To set up a notification agent conifgure this in <strong>Settings -> Notification Agents</strong>
|
<p class="help-block">PlexPy supports a wide variety of notification options. To set up a notification agent conifgure this in <strong>Settings -> Notification Agents</strong>
|
||||||
after you have completed this setup wizard.</p><br/>
|
after you have completed this setup wizard.</p><br/>
|
||||||
<div class="wizard-input-section">
|
<div class="wizard-input-section">
|
||||||
<input type="checkbox" name="movie_notify_enable" id="movie_notify_enable" value="1" ${config['movie_notify_enable']}> Enable notifications on Movie and TV playback
|
<input type="checkbox" name="movie_notify_enable" id="movie_notify_enable" value="1" ${config['movie_notify_enable']}> Enable notifications on Movie playback
|
||||||
|
</div>
|
||||||
|
<div class="wizard-input-section">
|
||||||
|
<input type="checkbox" name="tv_notify_enable" id="tv_notify_enable" value="1" ${config['tv_notify_enable']}> Enable notifications on TV Show playback
|
||||||
</div>
|
</div>
|
||||||
<div class="wizard-input-section">
|
<div class="wizard-input-section">
|
||||||
<input type="checkbox" name="music_notify_enable" id="music_notify_enable" value="1" ${config['music_notify_enable']}> Enable notifications on Music playback
|
<input type="checkbox" name="music_notify_enable" id="music_notify_enable" value="1" ${config['music_notify_enable']}> Enable notifications on Music playback
|
||||||
|
|
|
@ -18,7 +18,6 @@ from plexpy import logger, pmsconnect, plextv, notification_handler, database, h
|
||||||
import threading
|
import threading
|
||||||
import plexpy
|
import plexpy
|
||||||
import time
|
import time
|
||||||
import urllib2
|
|
||||||
|
|
||||||
monitor_lock = threading.Lock()
|
monitor_lock = threading.Lock()
|
||||||
ext_ping_count = 0
|
ext_ping_count = 0
|
||||||
|
@ -226,37 +225,37 @@ def check_server_response():
|
||||||
|
|
||||||
with monitor_lock:
|
with monitor_lock:
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
internal_response = pms_connect.get_server_response()
|
server_response = pms_connect.get_server_response()
|
||||||
global int_ping_count
|
|
||||||
|
|
||||||
if not internal_response:
|
global int_ping_count
|
||||||
|
global ext_ping_count
|
||||||
|
|
||||||
|
# Check for internal server response
|
||||||
|
if not server_response:
|
||||||
int_ping_count += 1
|
int_ping_count += 1
|
||||||
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
|
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
|
||||||
% str(int_ping_count))
|
% str(int_ping_count))
|
||||||
|
# Reset internal ping counter
|
||||||
else:
|
else:
|
||||||
int_ping_count = 0
|
int_ping_count = 0
|
||||||
|
|
||||||
if plexpy.CONFIG.MONITOR_REMOTE_ACCESS:
|
# Check for remote access
|
||||||
plex_tv = plextv.PlexTV()
|
if server_response and plexpy.CONFIG.MONITOR_REMOTE_ACCESS:
|
||||||
external_response = plex_tv.get_server_response()
|
|
||||||
global ext_ping_count
|
|
||||||
|
|
||||||
if not external_response:
|
mapping_state = server_response['mapping_state']
|
||||||
ext_ping_count += 1
|
mapping_error = server_response['mapping_error']
|
||||||
logger.warn(u"PlexPy Monitor :: Plex remote access port mapping failed, ping attempt %s." \
|
|
||||||
% str(ext_ping_count))
|
|
||||||
else:
|
|
||||||
host = external_response[0]['host']
|
|
||||||
port = external_response[0]['port']
|
|
||||||
|
|
||||||
try:
|
# Check if the port is mapped
|
||||||
http_response = urllib2.urlopen('http://' + host + ':' + port)
|
if not mapping_state == 'mapped':
|
||||||
except urllib2.HTTPError, e:
|
|
||||||
ext_ping_count = 0
|
|
||||||
except urllib2.URLError, e:
|
|
||||||
ext_ping_count += 1
|
ext_ping_count += 1
|
||||||
logger.warn(u"PlexPy Monitor :: Unable to get an external response from the server, ping attempt %s." \
|
logger.warn(u"PlexPy Monitor :: Plex remote access port not mapped, ping attempt %s." \
|
||||||
% str(ext_ping_count))
|
% str(ext_ping_count))
|
||||||
|
# Check if the port is open
|
||||||
|
elif mapping_error == 'unreachable':
|
||||||
|
ext_ping_count += 1
|
||||||
|
logger.warn(u"PlexPy Monitor :: Plex remote access port mapped, but mapping failed, ping attempt %s." \
|
||||||
|
% str(ext_ping_count))
|
||||||
|
# Reset external ping counter
|
||||||
else:
|
else:
|
||||||
ext_ping_count = 0
|
ext_ping_count = 0
|
||||||
|
|
||||||
|
|
|
@ -394,8 +394,8 @@ class Api(object):
|
||||||
"grouping_global_history": bool(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
|
"grouping_global_history": bool(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
|
||||||
"grouping_user_history": bool(plexpy.CONFIG.GROUPING_USER_HISTORY),
|
"grouping_user_history": bool(plexpy.CONFIG.GROUPING_USER_HISTORY),
|
||||||
"grouping_charts": bool(plexpy.CONFIG.GROUPING_CHARTS),
|
"grouping_charts": bool(plexpy.CONFIG.GROUPING_CHARTS),
|
||||||
"tv_notify_enable": bool(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
|
||||||
"movie_notify_enable": bool(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
"movie_notify_enable": bool(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
||||||
|
"tv_notify_enable": bool(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
||||||
"music_notify_enable": bool(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
"music_notify_enable": bool(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
||||||
"tv_notify_on_start": bool(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
"tv_notify_on_start": bool(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
||||||
"movie_notify_on_start": bool(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
"movie_notify_on_start": bool(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
||||||
|
|
|
@ -30,8 +30,8 @@ def notify(stream_data=None, notify_action=None):
|
||||||
if not user_details['do_notify']:
|
if not user_details['do_notify']:
|
||||||
return
|
return
|
||||||
|
|
||||||
if stream_data['media_type'] == 'movie' or stream_data['media_type'] == 'episode':
|
if (stream_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
|
||||||
if plexpy.CONFIG.MOVIE_NOTIFY_ENABLE or plexpy.CONFIG.TV_NOTIFY_ENABLE:
|
or (stream_data['media_type'] == 'episode' and plexpy.CONFIG.TV_NOTIFY_ENABLE):
|
||||||
|
|
||||||
progress_percent = helpers.get_percent(stream_data['view_offset'], stream_data['duration'])
|
progress_percent = helpers.get_percent(stream_data['view_offset'], stream_data['duration'])
|
||||||
|
|
||||||
|
@ -110,8 +110,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif stream_data['media_type'] == 'track':
|
elif (stream_data['media_type'] == 'track' and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):
|
||||||
if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:
|
|
||||||
|
|
||||||
for agent in notifiers.available_notification_agents():
|
for agent in notifiers.available_notification_agents():
|
||||||
if agent['on_play'] and notify_action == 'play':
|
if agent['on_play'] and notify_action == 'play':
|
||||||
|
@ -170,6 +169,12 @@ def notify(stream_data=None, notify_action=None):
|
||||||
|
|
||||||
def notify_timeline(timeline_data=None, notify_action=None):
|
def notify_timeline(timeline_data=None, notify_action=None):
|
||||||
if timeline_data and notify_action:
|
if timeline_data and notify_action:
|
||||||
|
if (timeline_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
|
||||||
|
or ((timeline_data['media_type'] == 'show' or timeline_data['media_type'] == 'episode') \
|
||||||
|
and plexpy.CONFIG.TV_NOTIFY_ENABLE) \
|
||||||
|
or ((timeline_data['media_type'] == 'artist' or timeline_data['media_type'] == 'track') \
|
||||||
|
and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):
|
||||||
|
|
||||||
for agent in notifiers.available_notification_agents():
|
for agent in notifiers.available_notification_agents():
|
||||||
if agent['on_created'] and notify_action == 'created':
|
if agent['on_created'] and notify_action == 'created':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -179,6 +184,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif not timeline_data and notify_action:
|
elif not timeline_data and notify_action:
|
||||||
for agent in notifiers.available_notification_agents():
|
for agent in notifiers.available_notification_agents():
|
||||||
if agent['on_extdown'] and notify_action == 'extdown':
|
if agent['on_extdown'] and notify_action == 'extdown':
|
||||||
|
|
|
@ -463,22 +463,3 @@ class PlexTV(object):
|
||||||
break
|
break
|
||||||
|
|
||||||
return server_times
|
return server_times
|
||||||
|
|
||||||
def get_server_response(self):
|
|
||||||
response = self.get_plextv_server_list(output_format='xml')
|
|
||||||
|
|
||||||
server_url = []
|
|
||||||
|
|
||||||
try:
|
|
||||||
xml_head = response.getElementsByTagName('Server')
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
for a in xml_head:
|
|
||||||
if helpers.get_xml_attr(a, 'machineIdentifier') == plexpy.CONFIG.PMS_IDENTIFIER:
|
|
||||||
server_url.append({"host": helpers.get_xml_attr(a, 'host'),
|
|
||||||
"port": helpers.get_xml_attr(a, 'port')
|
|
||||||
})
|
|
||||||
break
|
|
||||||
|
|
||||||
return server_url
|
|
|
@ -271,6 +271,36 @@ class PmsConnect(object):
|
||||||
return request
|
return request
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Return account details.
|
||||||
|
|
||||||
|
Optional parameters: output_format { dict, json }
|
||||||
|
|
||||||
|
Output: array
|
||||||
|
"""
|
||||||
|
def get_account(self, output_format=''):
|
||||||
|
uri = '/myplex/account'
|
||||||
|
request = self.request_handler.make_request(uri=uri,
|
||||||
|
proto=self.protocol,
|
||||||
|
request_type='GET',
|
||||||
|
output_format=output_format)
|
||||||
|
|
||||||
|
return request
|
||||||
|
|
||||||
|
"""
|
||||||
|
Refresh Plex remote access port mapping.
|
||||||
|
|
||||||
|
Optional parameters: None
|
||||||
|
|
||||||
|
Output: None
|
||||||
|
"""
|
||||||
|
def put_refresh_reachability(self):
|
||||||
|
uri = '/myplex/refreshReachability'
|
||||||
|
request = self.request_handler.make_request(uri=uri,
|
||||||
|
proto=self.protocol,
|
||||||
|
request_type='PUT')
|
||||||
|
|
||||||
|
return request
|
||||||
|
"""
|
||||||
Return processed and validated list of recently added items.
|
Return processed and validated list of recently added items.
|
||||||
|
|
||||||
Parameters required: count { number of results to return }
|
Parameters required: count { number of results to return }
|
||||||
|
@ -1650,15 +1680,24 @@ class PmsConnect(object):
|
||||||
|
|
||||||
return key_list
|
return key_list
|
||||||
|
|
||||||
"""
|
|
||||||
Check for a server response.
|
|
||||||
|
|
||||||
Output: bool
|
|
||||||
"""
|
|
||||||
def get_server_response(self):
|
def get_server_response(self):
|
||||||
response = self.get_server_list()
|
# Refresh Plex remote access port mapping first
|
||||||
|
self.put_refresh_reachability()
|
||||||
|
account_data = self.get_account(output_format='xml')
|
||||||
|
|
||||||
if not response:
|
try:
|
||||||
return False
|
xml_head = account_data.getElementsByTagName('MyPlex')
|
||||||
else:
|
except:
|
||||||
return True
|
logger.warn("Unable to parse XML for get_server_response.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
server_response = {}
|
||||||
|
|
||||||
|
for a in xml_head:
|
||||||
|
server_response = {'mapping_state': helpers.get_xml_attr(a, 'mappingState'),
|
||||||
|
'mapping_error': helpers.get_xml_attr(a, 'mappingError'),
|
||||||
|
'public_address': helpers.get_xml_attr(a, 'publicAddress'),
|
||||||
|
'public_port': helpers.get_xml_attr(a, 'publicPort')
|
||||||
|
}
|
||||||
|
|
||||||
|
return server_response
|
|
@ -90,8 +90,8 @@ class WebInterface(object):
|
||||||
"pms_token": plexpy.CONFIG.PMS_TOKEN,
|
"pms_token": plexpy.CONFIG.PMS_TOKEN,
|
||||||
"pms_ssl": checked(plexpy.CONFIG.PMS_SSL),
|
"pms_ssl": checked(plexpy.CONFIG.PMS_SSL),
|
||||||
"pms_uuid": plexpy.CONFIG.PMS_UUID,
|
"pms_uuid": plexpy.CONFIG.PMS_UUID,
|
||||||
"tv_notify_enable": checked(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
|
||||||
"movie_notify_enable": checked(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
"movie_notify_enable": checked(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
||||||
|
"tv_notify_enable": checked(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
||||||
"music_notify_enable": checked(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
"music_notify_enable": checked(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
||||||
"tv_notify_on_start": checked(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
"tv_notify_on_start": checked(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
||||||
"movie_notify_on_start": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
"movie_notify_on_start": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
||||||
|
@ -423,8 +423,8 @@ class WebInterface(object):
|
||||||
"grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
|
"grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
|
||||||
"grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY),
|
"grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY),
|
||||||
"grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS),
|
"grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS),
|
||||||
"tv_notify_enable": checked(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
|
||||||
"movie_notify_enable": checked(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
"movie_notify_enable": checked(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
|
||||||
|
"tv_notify_enable": checked(plexpy.CONFIG.TV_NOTIFY_ENABLE),
|
||||||
"music_notify_enable": checked(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
"music_notify_enable": checked(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
|
||||||
"tv_notify_on_start": checked(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
"tv_notify_on_start": checked(plexpy.CONFIG.TV_NOTIFY_ON_START),
|
||||||
"movie_notify_on_start": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
"movie_notify_on_start": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
|
||||||
|
@ -486,7 +486,7 @@ class WebInterface(object):
|
||||||
checked_configs = [
|
checked_configs = [
|
||||||
"launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github",
|
"launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github",
|
||||||
"grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif", "pms_ssl",
|
"grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif", "pms_ssl",
|
||||||
"tv_notify_enable", "movie_notify_enable", "music_notify_enable", "monitoring_use_websocket",
|
"movie_notify_enable", "tv_notify_enable", "music_notify_enable", "monitoring_use_websocket",
|
||||||
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
|
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
|
||||||
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
|
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
|
||||||
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
|
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue