diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index d857479a..976fe680 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -1037,7 +1037,7 @@

- +
@@ -1070,6 +1070,21 @@

--> +
+

Remote Access Notifications

+
+ +
+ +
+
+ +
+ +
+

The duration (in seconds) for Plex remote access to be down before sending a notification. Minimum 60, default 60.

+
+

Newsletters

diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index b51724dc..11b3a2af 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -535,6 +535,12 @@ class ReachabilityHandler(object): pref = pms_connect.get_server_pref(pref='PublishServerOnPlexOnlineKey') return helpers.bool_true(pref) + def on_down(self, server_response): + plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extdown', 'remote_access_info': server_response}) + + def on_up(self, server_response): + plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extup', 'remote_access_info': server_response}) + def process(self): # Check if remote access is enabled if not self.remote_access_enabled(): @@ -550,20 +556,30 @@ class ReachabilityHandler(object): if server_response: # Waiting for port mapping if server_response['mapping_state'] == 'waiting': - logger.warn("Tautulli Monitor :: Remote access waiting for port mapping.") + logger.warn("Tautulli ReachabilityHandler :: Remote access waiting for port mapping.") elif plexpy.PLEX_REMOTE_ACCESS_UP is not False and server_response['reason']: - logger.warn("Tautulli Monitor :: Remote access failed: %s" % server_response['reason']) - logger.info("Tautulli Monitor :: Plex remote access is down.") + logger.warn("Tautulli ReachabilityHandler :: Remote access failed: %s" % server_response['reason']) + logger.info("Tautulli ReachabilityHandler :: Plex remote access is down.") plexpy.PLEX_REMOTE_ACCESS_UP = False - plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extdown', 'remote_access_info': server_response}) + + if not ACTIVITY_SCHED.get_job('on_extdown'): + logger.debug("Tautulli ReachabilityHandler :: Schedule remote access down callback in %d seconds.", + plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD) + schedule_callback('on_extdown', func=self.on_down, args=[server_response], + seconds=plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD) elif plexpy.PLEX_REMOTE_ACCESS_UP is False and not server_response['reason']: - logger.info("Tautulli Monitor :: Plex remote access is back up.") + logger.info("Tautulli ReachabilityHandler :: Plex remote access is back up.") plexpy.PLEX_REMOTE_ACCESS_UP = True - plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_extup', 'remote_access_info': server_response}) + + if ACTIVITY_SCHED.get_job('on_extdown'): + logger.debug("Tautulli ReachabilityHandler :: Cancelling scheduled remote access down callback.") + schedule_callback('on_extdown', remove_job=True) + else: + self.on_up(server_response) elif plexpy.PLEX_REMOTE_ACCESS_UP is None: plexpy.PLEX_REMOTE_ACCESS_UP = self.is_reachable() diff --git a/plexpy/config.py b/plexpy/config.py index 8c4fab8d..4d704071 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -161,6 +161,7 @@ _CONFIG_DEFINITIONS = { 'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 300), 'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0), 'NOTIFY_RECENTLY_ADDED_UPGRADE': (int, 'Monitoring', 0), + 'NOTIFY_REMOTE_ACCESS_THRESHOLD': (int, 'Monitoring', 60), 'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0), 'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2), 'PLEXPY_AUTO_UPDATE': (int, 'General', 0), diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 98450e28..c8295e76 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -3026,6 +3026,7 @@ class WebInterface(object): "notify_group_recently_added_grandparent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT), "notify_group_recently_added_parent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT), "notify_recently_added_delay": plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_DELAY, + "notify_remote_access_threshold": plexpy.CONFIG.NOTIFY_REMOTE_ACCESS_THRESHOLD, "notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP), "notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD, "notify_continued_session_threshold": plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD,