Add Plex server down notification threshold setting

This commit is contained in:
JonnyWong16 2021-04-03 11:34:53 -07:00
parent 802dfe10be
commit 7045597c61
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
6 changed files with 38 additions and 9 deletions

View file

@ -1092,9 +1092,19 @@
</div>--> </div>-->
<div class="padded-header"> <div class="padded-header">
<h3>Remote Access Notifications</h3> <h3>Server Notifications</h3>
</div> </div>
<div class="form-group">
<label for="notify_server_connection_threshold">Plex Server Down Threshold</label>
<div class="row">
<div class="col-md-2">
<input type="text" class="form-control" data-parsley-type="integer" id="notify_server_connection_threshold" name="notify_server_connection_threshold" value="${config['notify_server_connection_threshold']}" size="5" data-parsley-min="60" data-parsley-trigger="change" data-parsley-errors-container="#notify_server_connection_threshold_error" required>
</div>
<div id="notify_server_connection_threshold_error" class="alert alert-danger settings-alert" role="alert"></div>
</div>
<p class="help-block">The duration (in seconds) for the Plex server to be down before sending a notification. Minimum 60, default 60.</p>
</div>
<div class="form-group"> <div class="form-group">
<label for="notify_remote_access_threshold">Remote Access Down Threshold</label> <label for="notify_remote_access_threshold">Remote Access Down Threshold</label>
<div class="row"> <div class="row">

View file

@ -493,7 +493,7 @@ def initialize_scheduler():
# Schedule job to reconnect server # Schedule job to reconnect server
schedule_job(activity_pinger.connect_server, 'Check for server response', schedule_job(activity_pinger.connect_server, 'Check for server response',
hours=0, minutes=0, seconds=60, args=(False,)) hours=0, minutes=0, seconds=30, args=(False,))
schedule_job(web_socket.send_ping, 'Websocket ping', schedule_job(web_socket.send_ping, 'Websocket ping',
hours=0, minutes=0, seconds=0) hours=0, minutes=0, seconds=0)

View file

@ -522,10 +522,10 @@ class ReachabilityHandler(object):
pref = pms_connect.get_server_pref(pref='PublishServerOnPlexOnlineKey') pref = pms_connect.get_server_pref(pref='PublishServerOnPlexOnlineKey')
return helpers.bool_true(pref) return helpers.bool_true(pref)
def on_down(self, server_response): def on_extdown(self, server_response):
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extdown', 'remote_access_info': server_response}) plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extdown', 'remote_access_info': server_response})
def on_up(self, server_response): def on_extup(self, server_response):
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extup', 'remote_access_info': server_response}) plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extup', 'remote_access_info': server_response})
def process(self): def process(self):
@ -552,9 +552,9 @@ class ReachabilityHandler(object):
plexpy.PLEX_REMOTE_ACCESS_UP = False plexpy.PLEX_REMOTE_ACCESS_UP = False
if not ACTIVITY_SCHED.get_job('on_extdown'): if not ACTIVITY_SCHED.get_job('on_extdown'):
logger.debug("Tautulli ReachabilityHandler :: Schedule remote access down callback in %d seconds.", logger.debug("Tautulli ReachabilityHandler :: Scheduling remote access down callback in %d seconds.",
plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD) plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD)
schedule_callback('on_extdown', func=self.on_down, args=[server_response], schedule_callback('on_extdown', func=self.on_extdown, args=[server_response],
seconds=plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD) seconds=plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD)
elif plexpy.PLEX_REMOTE_ACCESS_UP is False and not server_response['reason']: elif plexpy.PLEX_REMOTE_ACCESS_UP is False and not server_response['reason']:
@ -566,7 +566,7 @@ class ReachabilityHandler(object):
logger.debug("Tautulli ReachabilityHandler :: Cancelling scheduled remote access down callback.") logger.debug("Tautulli ReachabilityHandler :: Cancelling scheduled remote access down callback.")
schedule_callback('on_extdown', remove_job=True) schedule_callback('on_extdown', remove_job=True)
else: else:
self.on_up(server_response) self.on_extup(server_response)
elif plexpy.PLEX_REMOTE_ACCESS_UP is None: elif plexpy.PLEX_REMOTE_ACCESS_UP is None:
plexpy.PLEX_REMOTE_ACCESS_UP = self.is_reachable() plexpy.PLEX_REMOTE_ACCESS_UP = self.is_reachable()

View file

@ -171,6 +171,7 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0), 'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0),
'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2), 'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2),
'NOTIFY_NEW_DEVICE_INITIAL_ONLY': (int, 'Monitoring', 1), 'NOTIFY_NEW_DEVICE_INITIAL_ONLY': (int, 'Monitoring', 1),
'NOTIFY_SERVER_CONNECTION_THRESHOLD': (int, 'Monitoring', 60),
'PLEXPY_AUTO_UPDATE': (int, 'General', 0), 'PLEXPY_AUTO_UPDATE': (int, 'General', 0),
'REFRESH_LIBRARIES_INTERVAL': (int, 'Monitoring', 12), 'REFRESH_LIBRARIES_INTERVAL': (int, 'Monitoring', 12),
'REFRESH_LIBRARIES_ON_STARTUP': (int, 'Monitoring', 1), 'REFRESH_LIBRARIES_ON_STARTUP': (int, 'Monitoring', 1),

View file

@ -71,9 +71,14 @@ def on_connect():
if not plexpy.PLEX_SERVER_UP: if not plexpy.PLEX_SERVER_UP:
logger.info("Tautulli WebSocket :: The Plex Media Server is back up.") logger.info("Tautulli WebSocket :: The Plex Media Server is back up.")
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_intup'})
plexpy.PLEX_SERVER_UP = True plexpy.PLEX_SERVER_UP = True
if activity_handler.ACTIVITY_SCHED.get_job('on_intdown'):
logger.debug("Tautulli WebSocket :: Cancelling scheduled Plex server down callback.")
activity_handler.schedule_callback('on_intdown', remove_job=True)
else:
on_intup()
plexpy.initialize_scheduler() plexpy.initialize_scheduler()
if plexpy.CONFIG.WEBSOCKET_MONITOR_PING_PONG: if plexpy.CONFIG.WEBSOCKET_MONITOR_PING_PONG:
send_ping() send_ping()
@ -85,13 +90,25 @@ def on_disconnect():
if plexpy.PLEX_SERVER_UP: if plexpy.PLEX_SERVER_UP:
logger.info("Tautulli WebSocket :: Unable to get a response from the server, Plex server is down.") logger.info("Tautulli WebSocket :: Unable to get a response from the server, Plex server is down.")
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_intdown'})
plexpy.PLEX_SERVER_UP = False plexpy.PLEX_SERVER_UP = False
logger.debug("Tautulli WebSocket :: Scheduling Plex server down callback in %d seconds.",
plexpy.CONFIG.NOTIFY_SERVER_CONNECTION_THRESHOLD)
activity_handler.schedule_callback('on_intdown', func=on_intdown,
seconds=plexpy.CONFIG.NOTIFY_SERVER_CONNECTION_THRESHOLD)
activity_processor.ActivityProcessor().set_temp_stopped() activity_processor.ActivityProcessor().set_temp_stopped()
plexpy.initialize_scheduler() plexpy.initialize_scheduler()
def on_intdown():
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_intdown'})
def on_intup():
plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_intup'})
def reconnect(): def reconnect():
close() close()
logger.info("Tautulli WebSocket :: Reconnecting websocket...") logger.info("Tautulli WebSocket :: Reconnecting websocket...")

View file

@ -3167,6 +3167,7 @@ class WebInterface(object):
"notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD, "notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD,
"notify_continued_session_threshold": plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD, "notify_continued_session_threshold": plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD,
"notify_new_device_initial_only": checked(plexpy.CONFIG.NOTIFY_NEW_DEVICE_INITIAL_ONLY), "notify_new_device_initial_only": checked(plexpy.CONFIG.NOTIFY_NEW_DEVICE_INITIAL_ONLY),
"notify_server_connection_threshold": plexpy.CONFIG.NOTIFY_SERVER_CONNECTION_THRESHOLD,
"home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS), "home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS),
"home_stats_cards": json.dumps(plexpy.CONFIG.HOME_STATS_CARDS), "home_stats_cards": json.dumps(plexpy.CONFIG.HOME_STATS_CARDS),
"home_library_cards": json.dumps(plexpy.CONFIG.HOME_LIBRARY_CARDS), "home_library_cards": json.dumps(plexpy.CONFIG.HOME_LIBRARY_CARDS),