2015-06-22 22:47:27 +02:00
|
|
|
"""
|
|
|
|
.. module: lemur.common.health
|
|
|
|
:platform: Unix
|
2018-05-29 19:18:16 +02:00
|
|
|
:copyright: (c) 2018 by Netflix Inc., see AUTHORS for more
|
2015-06-22 22:47:27 +02:00
|
|
|
:license: Apache, see LICENSE for more details.
|
|
|
|
|
|
|
|
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
|
|
|
"""
|
|
|
|
from flask import Blueprint
|
2017-05-23 02:15:41 +02:00
|
|
|
from lemur.database import db
|
2017-10-24 23:04:51 +02:00
|
|
|
from lemur.extensions import sentry
|
2015-06-22 22:47:27 +02:00
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
mod = Blueprint("healthCheck", __name__)
|
2015-06-22 22:47:27 +02:00
|
|
|
|
2015-07-21 22:06:13 +02:00
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
@mod.route("/healthcheck")
|
2015-06-22 22:47:27 +02:00
|
|
|
def health():
|
2017-05-23 02:15:41 +02:00
|
|
|
try:
|
|
|
|
if healthcheck(db):
|
2019-05-16 16:57:02 +02:00
|
|
|
return "ok"
|
2017-10-24 23:04:51 +02:00
|
|
|
except Exception:
|
|
|
|
sentry.captureException()
|
2019-05-16 16:57:02 +02:00
|
|
|
return "db check failed"
|
2017-05-23 02:15:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def healthcheck(db):
|
|
|
|
with db.engine.connect() as connection:
|
2019-05-16 16:57:02 +02:00
|
|
|
connection.execute("SELECT 1;")
|
2017-05-23 02:15:41 +02:00
|
|
|
return True
|