mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Fix some log table styling.
Refresh user list on start-up and schedule refresh every 12 hours. Handle malformed lines when reading Plex logs slightly more gracefully. Send back empty list instead of None on some plex.tv requests.
This commit is contained in:
parent
0810584b46
commit
b4f1bddc02
6 changed files with 63 additions and 30 deletions
|
@ -19,11 +19,13 @@ var log_table_options = {
|
|||
"columnDefs": [
|
||||
{
|
||||
"targets": [0],
|
||||
"width": "15%"
|
||||
"width": "15%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
"targets": [1],
|
||||
"width": "10%"
|
||||
"width": "10%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
"targets": [2],
|
||||
|
|
|
@ -19,11 +19,13 @@ var plex_log_table_options = {
|
|||
"columnDefs": [
|
||||
{
|
||||
"targets": [0],
|
||||
"width": "15%"
|
||||
"width": "15%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
"targets": [1],
|
||||
"width": "10%"
|
||||
"width": "10%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
"targets": [2],
|
||||
|
|
|
@ -29,7 +29,7 @@ import uuid
|
|||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.interval import IntervalTrigger
|
||||
|
||||
from plexpy import versioncheck, logger, monitor
|
||||
from plexpy import versioncheck, logger, monitor, plextv
|
||||
import plexpy.config
|
||||
|
||||
PROG_DIR = None
|
||||
|
@ -162,6 +162,10 @@ def initialize(config_file):
|
|||
else:
|
||||
LATEST_VERSION = CURRENT_VERSION
|
||||
|
||||
# Refresh the users list on startup
|
||||
if CONFIG.PMS_TOKEN:
|
||||
plextv.refresh_users()
|
||||
|
||||
# Store the original umask
|
||||
UMASK = os.umask(0)
|
||||
os.umask(UMASK)
|
||||
|
@ -249,16 +253,21 @@ def initialize_scheduler():
|
|||
# Check if scheduler should be started
|
||||
start_jobs = not len(SCHED.get_jobs())
|
||||
|
||||
#Update check
|
||||
# Update check
|
||||
if CONFIG.CHECK_GITHUB_INTERVAL:
|
||||
minutes = CONFIG.CHECK_GITHUB_INTERVAL
|
||||
else:
|
||||
minutes = 0
|
||||
schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes)
|
||||
|
||||
# Start checking for new sessions every minute
|
||||
if CONFIG.PMS_IP:
|
||||
schedule_job(monitor.check_active_sessions, 'Check for active sessions', hours=0, minutes=0, seconds=60)
|
||||
|
||||
# Refresh the users list every 12 hours (we will make this configurable later)
|
||||
if CONFIG.PMS_TOKEN:
|
||||
schedule_job(plextv.refresh_users, 'Refresh users list', hours=12, minutes=0, seconds=0)
|
||||
|
||||
# Start scheduler
|
||||
if start_jobs and len(SCHED.get_jobs()):
|
||||
try:
|
||||
|
|
|
@ -32,13 +32,23 @@ def get_log_tail(window=20):
|
|||
return []
|
||||
|
||||
log_lines = tail(logfile, window)
|
||||
|
||||
line_error = False
|
||||
clean_lines = []
|
||||
for i in log_lines:
|
||||
log_time = i.split(' [')[0]
|
||||
log_level = i.split('] ', 1)[1].split(' - ',1)[0]
|
||||
log_msg = i.split('] ', 1)[1].split(' - ',1)[1]
|
||||
full_line = [log_time, log_level, log_msg]
|
||||
clean_lines.append(full_line)
|
||||
try:
|
||||
log_time = i.split(' [')[0]
|
||||
log_level = i.split('] ', 1)[1].split(' - ',1)[0]
|
||||
log_msg = i.split('] ', 1)[1].split(' - ',1)[1]
|
||||
full_line = [log_time, log_level, log_msg]
|
||||
clean_lines.append(full_line)
|
||||
except:
|
||||
line_error = True
|
||||
full_line = ['', '', 'Unable to parse log line.']
|
||||
clean_lines.append(full_line)
|
||||
|
||||
if line_error:
|
||||
logger.error('PlexPy was unable to parse some lines of the Plex Media Server log.')
|
||||
|
||||
return clean_lines
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, helpers, plexwatch
|
||||
from plexpy import logger, helpers, plexwatch, db
|
||||
|
||||
from xml.dom import minidom
|
||||
from httplib import HTTPSConnection
|
||||
|
@ -21,6 +21,29 @@ from httplib import HTTPSConnection
|
|||
import base64
|
||||
import plexpy
|
||||
|
||||
def refresh_users():
|
||||
logger.info("Requesting users list refresh...")
|
||||
result = PlexTV().get_full_users_list()
|
||||
pw_db = db.DBConnection()
|
||||
|
||||
if len(result) > 0:
|
||||
for item in result:
|
||||
control_value_dict = {"username": item['username']}
|
||||
new_value_dict = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"thumb": item['thumb'],
|
||||
"email": item['email'],
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted']
|
||||
}
|
||||
|
||||
pw_db.upsert('plexpy_users', new_value_dict, control_value_dict)
|
||||
|
||||
logger.info("Users list refreshed.")
|
||||
else:
|
||||
logger.warn("Unable to refresh users list.")
|
||||
|
||||
|
||||
class PlexTV(object):
|
||||
"""
|
||||
|
@ -232,8 +255,10 @@ class PlexTV(object):
|
|||
xml_parse = minidom.parseString(own_account)
|
||||
except Exception, e:
|
||||
logger.warn("Error parsing XML for Plex account details: %s" % e)
|
||||
return []
|
||||
except:
|
||||
logger.warn("Error parsing XML for Plex account details.")
|
||||
return []
|
||||
|
||||
xml_head = xml_parse.getElementsByTagName('user')
|
||||
if not xml_head:
|
||||
|
@ -286,8 +311,10 @@ class PlexTV(object):
|
|||
xml_parse = minidom.parseString(sync_list)
|
||||
except Exception, e:
|
||||
logger.warn("Error parsing XML for Plex sync lists: %s" % e)
|
||||
return []
|
||||
except:
|
||||
logger.warn("Error parsing XML for Plex sync lists.")
|
||||
return []
|
||||
|
||||
xml_head = xml_parse.getElementsByTagName('SyncList')
|
||||
|
||||
|
|
|
@ -903,24 +903,7 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
def refresh_users_list(self, **kwargs):
|
||||
plex_tv = plextv.PlexTV()
|
||||
result = plex_tv.get_full_users_list()
|
||||
myDB = db.DBConnection()
|
||||
|
||||
for item in result:
|
||||
control_value_dict = {"username": item['username']}
|
||||
new_value_dict = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"thumb": item['thumb'],
|
||||
"email": item['email'],
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted']
|
||||
}
|
||||
|
||||
myDB.upsert('plexpy_users', new_value_dict, control_value_dict)
|
||||
|
||||
logger.info("Users list refreshed.")
|
||||
plextv.refresh_users()
|
||||
raise cherrypy.HTTPRedirect("users")
|
||||
|
||||
@cherrypy.expose
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue