Add setting to enable remote access monitoring

This commit is contained in:
Jonathan Wong 2015-11-19 19:40:50 -08:00
parent 9aea663754
commit fd43cf5dd4
6 changed files with 46 additions and 36 deletions

View file

@ -67,7 +67,7 @@ from plexpy import helpers
<div class="checkbox">
<label>
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_extdown" ${helpers.checked(data['on_extdown'])} class="toggle-switches">
Notify on Plex external port down
Notify on Plex remote access down
</label>
<p class="help-block">Trigger notification when the Plex Media Server cannot be reached externally.</p>
</div>

View file

@ -403,6 +403,12 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</label>
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental. Encrypted websocket is not currently supported.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="monitor_remote_access" name="monitor_remote_access" value="1" ${config['monitor_remote_access']}> Monitor Plex Remote Access
</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>
</div>
<div class="padded-header">
<h3>History Logging</h3>
@ -659,7 +665,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</ul>
</li>
<li>
<div class="link"><i class="fa fa-server fa-fw"></i>&nbsp;Plex External Port Down<i class="fa fa-chevron-down"></i></div>
<div class="link"><i class="fa fa-server fa-fw"></i>&nbsp;Plex Remote Access Down<i class="fa fa-chevron-down"></i></div>
<ul class="submenu">
<li>
<div class="form-group">
@ -1305,7 +1311,7 @@ $(document).ready(function() {
'X-Plex-Version': '${common.VERSION_NUMBER}',
'X-Plex-Platform': '${common.PLATFORM}',
'X-Plex-Platform-Version': '${common.PLATFORM_VERSION}',
'X-Plex-Client-Identifier': '${config['pms_uuid']}',
'X-Plex-Client-Identifier': '${config["pms_uuid"]}',
'Authorization': 'Basic ' + btoa($("#pms_username").val() + ':' + $("#pms_password").val())
},
error: function(jqXHR, textStatus, errorThrown) {

View file

@ -225,14 +225,22 @@ def check_recently_added():
def check_server_response():
with monitor_lock:
plex_tv = plextv.PlexTV()
external_response = plex_tv.get_server_response()
pms_connect = pmsconnect.PmsConnect()
internal_response = pms_connect.get_server_response()
global ext_ping_count
global int_ping_count
if not internal_response:
int_ping_count += 1
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
% str(int_ping_count))
else:
int_ping_count = 0
if plexpy.CONFIG.MONITOR_REMOTE_ACCESS:
plex_tv = plextv.PlexTV()
external_response = plex_tv.get_server_response()
global ext_ping_count
if not external_response:
ext_ping_count += 1
logger.warn(u"PlexPy Monitor :: Plex remote access port mapping failed, ping attempt %s." \
@ -252,18 +260,12 @@ def check_server_response():
else:
ext_ping_count = 0
if not internal_response:
int_ping_count += 1
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
% str(int_ping_count))
else:
int_ping_count = 0
if int_ping_count == 3:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
kwargs=dict(notify_action='intdown')).start()
if ext_ping_count == 3:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
kwargs=dict(notify_action='extdown')).start()
if int_ping_count == 3:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
kwargs=dict(notify_action='intdown')).start()

View file

@ -134,6 +134,7 @@ _CONFIG_DEFINITIONS = {
'MUSIC_NOTIFY_ON_STOP': (int, 'Monitoring', 0),
'MUSIC_NOTIFY_ON_PAUSE': (int, 'Monitoring', 0),
'MUSIC_LOGGING_ENABLE': (int, 'Monitoring', 0),
'MONITOR_REMOTE_ACCESS': (int, 'Monitoring', 0),
'MONITORING_INTERVAL': (int, 'Monitoring', 60),
'MONITORING_USE_WEBSOCKET': (int, 'Monitoring', 0),
'NMA_APIKEY': (str, 'NMA', ''),
@ -167,9 +168,9 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_ON_CREATED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_CREATED_BODY_TEXT': (str, 'Monitoring', '{title} was recently added to Plex.'),
'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_EXTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex external port is down.'),
'NOTIFY_ON_EXTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server remote access is down.'),
'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_INTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex server is down.'),
'NOTIFY_ON_INTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server is down.'),
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),

View file

@ -638,7 +638,7 @@ def build_server_notify_text(state=None):
if state == 'extdown':
# Default body text
body_text = 'The Plex external port is down.'
body_text = 'The Plex Media Server remote access is down.'
if on_extdown_subject and on_extdown_body:
try:
@ -660,7 +660,7 @@ def build_server_notify_text(state=None):
return [subject_text, body_text]
elif state == 'intdown':
# Default body text
body_text = 'The Plex server is down.'
body_text = 'The Plex Media Server is down.'
if on_intdown_subject and on_intdown_body:
try:

View file

@ -435,6 +435,7 @@ class WebInterface(object):
"tv_notify_on_pause": checked(plexpy.CONFIG.TV_NOTIFY_ON_PAUSE),
"movie_notify_on_pause": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_PAUSE),
"music_notify_on_pause": checked(plexpy.CONFIG.MUSIC_NOTIFY_ON_PAUSE),
"monitor_remote_access": checked(plexpy.CONFIG.MONITOR_REMOTE_ACCESS),
"monitoring_interval": plexpy.CONFIG.MONITORING_INTERVAL,
"monitoring_use_websocket": checked(plexpy.CONFIG.MONITORING_USE_WEBSOCKET),
"refresh_users_interval": plexpy.CONFIG.REFRESH_USERS_INTERVAL,
@ -490,7 +491,7 @@ class WebInterface(object):
"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",
"ip_logging_enable", "video_logging_enable", "music_logging_enable", "pms_is_remote", "home_stats_type",
"group_history_tables", "notify_consecutive", "notify_recently_added_grandparent"
"group_history_tables", "notify_consecutive", "notify_recently_added_grandparent", "monitor_remote_access"
]
for checked_config in checked_configs:
if checked_config not in kwargs: