diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 39c9a470..9e3e25c6 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -287,6 +287,8 @@ def initialize_scheduler(): hours=12, minutes=0, seconds=0) schedule_job(activity_pinger.check_recently_added, 'Check for recently added items', hours=0, minutes=0, seconds=seconds) + schedule_job(activity_pinger.check_server_response, 'Check for server response', + hours=0, minutes=0, seconds=seconds) # If we're not using websockets then fall back to polling if not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER: diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py index baa280d2..9db9dd32 100644 --- a/plexpy/activity_pinger.py +++ b/plexpy/activity_pinger.py @@ -20,6 +20,7 @@ import plexpy import time monitor_lock = threading.Lock() +ping_count = 0 def check_active_sessions(ws_request=False): @@ -219,3 +220,22 @@ def check_recently_added(): # Fire off notifications threading.Thread(target=notification_handler.notify_timeline, kwargs=dict(timeline_data=item, notify_action='created')).start() + + +def check_server_response(): + + with monitor_lock: + pms_connect = pmsconnect.PmsConnect() + response = pms_connect.get_server_response() + global ping_count + + if not response: + ping_count += 1 + logger.warn(u"PlexPy Monitor :: Unable to get a response from the server, ping attempt %s." % str(ping_count)) + + if ping_count == 3: + # Fire off notifications + threading.Thread(target=notification_handler.notify_timeline, + kwargs=dict(notify_action='down')).start() + else: + ping_count = 0 \ No newline at end of file diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 9ab4fd80..e647b34c 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -1648,4 +1648,17 @@ class PmsConnect(object): 'children': parents} } - return key_list \ No newline at end of file + return key_list + + """ + Check for a server response. + + Output: bool + """ + def get_server_response(self): + response = self.get_server_list() + + if not response: + return False + else: + return True