Add database integrity check to status API

This commit is contained in:
JonnyWong16 2019-05-11 10:18:45 -07:00
parent 4743538de8
commit f1376fb2ca
3 changed files with 28 additions and 6 deletions

2
API.md
View file

@ -2653,7 +2653,7 @@ Required parameters:
None
Optional parameters:
None
check (str): database
Returns:
json:

View file

@ -27,6 +27,12 @@ FILENAME = "tautulli.db"
db_lock = threading.Lock()
def integrity_check():
monitor_db = MonitorDatabase()
result = monitor_db.select_single('PRAGMA integrity_check')
return result
def drop_session_db():
monitor_db = MonitorDatabase()
monitor_db.action('DROP TABLE sessions')
@ -53,6 +59,7 @@ def delete_sessions():
logger.warn(u"Tautulli Database :: Unable to clear temporary sessions from database: %s." % e)
return False
def db_filename(filename=FILENAME):
""" Returns the filepath to the db """

View file

@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
import hashlib
import json
import os
import shutil
@ -57,7 +56,7 @@ import web_socket
from plexpy.api2 import API2
from plexpy.helpers import checked, addtoapi, get_ip, create_https_certificates, build_datatables_json, sanitize_out
from plexpy.session import get_session_info, get_session_user_id, allow_session_user, allow_session_library
from plexpy.webauth import AuthController, requireAuth, member_of
from plexpy.webauth import AuthController, requireAuth, member_of, check_auth
def serve_template(templatename, **kwargs):
@ -5858,7 +5857,7 @@ class WebInterface(object):
@cherrypy.expose
@requireAuth()
def support(self, query='', **kwargs):
def support(self, **kwargs):
return serve_template(templatename="support.html", title="Support")
@cherrypy.expose
@ -5872,7 +5871,7 @@ class WebInterface(object):
None
Optional parameters:
None
check (str): database
Returns:
json:
@ -5882,4 +5881,20 @@ class WebInterface(object):
```
"""
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
return {'result': 'success', 'message': 'Ok'}
status = {'result': 'success', 'message': 'Ok'}
if args or kwargs:
if not cherrypy.request.path_info == '/api/v2':
cherrypy.request.config['auth.require'] = []
check_auth()
if 'database' in (args[:1] or kwargs.get('check')):
result = database.integrity_check()
status.update(result)
if result['integrity_check'] == 'ok':
status['message'] = 'Database ok'
else:
status['result'] = 'error'
status['message'] = 'Database not ok'
return status