예제 #1
0
    def find_session_ip(self, rating_key=None, machine_id=None):

        logger.debug(u"PlexPy ActivityProcessor :: Requesting log lines...")
        log_lines = log_reader.get_log_tail(window=5000, parsed=False)

        rating_key_line = 'ratingKey=' + rating_key
        rating_key_line_2 = 'metadata%2F' + rating_key
        machine_id_line = 'session=' + machine_id

        for line in reversed(log_lines):
            # We're good if we find a line with both machine id and rating key
            # This is usually when there is a transcode session
            if machine_id_line in line and (rating_key_line in line or rating_key_line_2 in line):
                # Currently only checking for ipv4 addresses
                ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)
                if ipv4:
                    # The logged IP will always be the first match and we don't want localhost entries
                    if ipv4[0] != '127.0.0.1':
                        # check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx)
                        #if '::ffff:' + ipv4[0] in line:
                        #    logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
                        #                 u"and machineIdentifier %s."
                        #                 % ('::ffff:' + ipv4[0], rating_key, machine_id))
                        #    return '::ffff:' + ipv4[0]
                        #else:
                        logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
                                        u"and machineIdentifier %s."
                                        % (ipv4[0], rating_key, machine_id))
                        return ipv4[0]

        logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on first pass. "
                     u"Attempting fallback check in 5 seconds...")

        # Wait for the log to catch up and read in new lines
        time.sleep(5)

        logger.debug(u"PlexPy ActivityProcessor :: Requesting log lines...")
        log_lines = log_reader.get_log_tail(window=5000, parsed=False)

        for line in reversed(log_lines):
            if 'GET /:/timeline' in line and (rating_key_line in line or rating_key_line_2 in line):
                # Currently only checking for ipv4 addresses
                # This method can return the wrong IP address if more than one user
                # starts watching the same media item around the same time.
                ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)
                if ipv4:
                    # The logged IP will always be the first match and we don't want localhost entries
                    if ipv4[0] != '127.0.0.1':
                        #if '::ffff:' + ipv4[0] in line:
                        #    logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
                        #                 ('::ffff:' + ipv4[0], rating_key))
                        #    return '::ffff:' + ipv4[0]
                        #else:
                        logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
                                        (ipv4[0], rating_key))
                        return ipv4[0]

        logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on fallback search. Not logging IP address.")

        return None
예제 #2
0
    def find_session_ip(self, rating_key=None, machine_id=None):

        logger.debug(u"PlexPy Monitor :: Requesting log lines...")
        log_lines = log_reader.get_log_tail(window=5000, parsed=False)

        rating_key_line = 'ratingKey=' + rating_key
        rating_key_line_2 = 'metadata%2F' + rating_key
        machine_id_line = 'session=' + machine_id

        for line in reversed(log_lines):
            # We're good if we find a line with both machine id and rating key
            # This is usually when there is a transcode session
            if machine_id_line in line and (rating_key_line in line
                                            or rating_key_line_2 in line):
                # Currently only checking for ipv4 addresses
                ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)
                if ipv4:
                    # The logged IP will always be the first match and we don't want localhost entries
                    if ipv4[0] != '127.0.0.1':
                        logger.debug(
                            u"PlexPy Monitor :: Matched IP address (%s) for stream ratingKey %s "
                            u"and machineIdentifier %s." %
                            (ipv4[0], rating_key, machine_id))
                        return ipv4[0]

        logger.debug(
            u"PlexPy Monitor :: Unable to find IP address on first pass. "
            u"Attempting fallback check in 5 seconds...")

        # Wait for the log to catch up and read in new lines
        time.sleep(5)

        logger.debug(u"PlexPy Monitor :: Requesting log lines...")
        log_lines = log_reader.get_log_tail(window=5000, parsed=False)

        for line in reversed(log_lines):
            if 'GET /:/timeline' in line and (rating_key_line in line
                                              or rating_key_line_2 in line):
                # Currently only checking for ipv4 addresses
                # This method can return the wrong IP address if more than one user
                # starts watching the same media item around the same time.
                ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)
                if ipv4:
                    # The logged IP will always be the first match and we don't want localhost entries
                    if ipv4[0] != '127.0.0.1':
                        logger.debug(
                            u"PlexPy Monitor :: Matched IP address (%s) for stream ratingKey %s."
                            % (ipv4[0], rating_key))
                        return ipv4[0]

        logger.debug(
            u"PlexPy Monitor :: Unable to find IP address on fallback search. Not logging IP address."
        )

        return None
예제 #3
0
    def get_plex_log(self, window=1000, **kwargs):
        log_lines = []
        try:
            log_lines = {'data': log_reader.get_log_tail(window=window)}
        except:
            logger.warn("Unable to retrieve Plex Logs.")

        cherrypy.response.headers['Content-type'] = 'application/json'
        return json.dumps(log_lines)
예제 #4
0
파일: webserve.py 프로젝트: elRadix/plexpy
    def get_plex_log(self, window=1000, **kwargs):
        log_lines = []
        try:
            log_lines = {"data": log_reader.get_log_tail(window=window)}
        except:
            logger.warn("Unable to retrieve Plex Logs.")

        cherrypy.response.headers["Content-type"] = "application/json"
        return json.dumps(log_lines)