diff --git a/tests/routes/health_test.py b/tests/routes/health_test.py index 25a20d31..cb36bb87 100644 --- a/tests/routes/health_test.py +++ b/tests/routes/health_test.py @@ -159,8 +159,8 @@ def test_sgx(skale_bp, skale): assert data == { 'payload': { 'sgx_server_url': SGX_SERVER_URL, - 'status': 0, - 'status_name': 'CONNECTED', + 'status_zmq': True, + 'status_https': True, 'sgx_wallet_version': version, 'sgx_keyname': TEST_SGX_KEYNAME, }, diff --git a/web/routes/health.py b/web/routes/health.py index 9ca41aa5..f2336747 100644 --- a/web/routes/health.py +++ b/web/routes/health.py @@ -18,8 +18,6 @@ # along with this program. If not, see . import logging -import telnetlib -from enum import Enum from http import HTTPStatus @@ -27,7 +25,6 @@ from sgx import SgxClient -from urllib.parse import urlparse from core.node import get_check_report, get_skale_node_version from core.node import get_current_nodes from core.schains.checks import SChainChecks @@ -38,7 +35,6 @@ from core.schains.ima import get_ima_log_checks from core.schains.external_config import ExternalState from tools.sgx_utils import SGX_CERTIFICATES_FOLDER, SGX_SERVER_URL -from tools.configs import ZMQ_PORT, ZMQ_TIMEOUT from web.models.schain import SChainRecord from web.helper import ( construct_err_response, @@ -51,11 +47,6 @@ BLUEPRINT_NAME = 'health' -class SGXStatus(Enum): - CONNECTED = 0 - NOT_CONNECTED = 1 - - health_bp = Blueprint(BLUEPRINT_NAME, __name__) @@ -137,27 +128,28 @@ def ima_log_checks(): @health_bp.route(get_api_url(BLUEPRINT_NAME, 'sgx'), methods=['GET']) def sgx_info(): logger.debug(request) - sgx = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER) + status_zmq = False + status_https = False + version = None + sgx = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER, zmq=True) try: - status = sgx.get_server_status() - version = sgx.get_server_version() - except Exception as e: # todo: catch specific error - edit sgx.py - logger.info(e) - status = 1 - version = None - sgx_host = urlparse(SGX_SERVER_URL).hostname - tn = telnetlib.Telnet() - zmq_status = 0 + if sgx.zmq.get_server_status() == 0: + status_zmq = True + version = sgx.zmq.get_server_version() + except Exception as err: + logger.error(f'Cannot make SGX ZMQ check {err}') + sgx_https = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER) try: - tn.open(sgx_host, ZMQ_PORT, timeout=ZMQ_TIMEOUT) + if sgx_https.get_server_status() == 0: + status_https = True + if version is None: + version = sgx_https.get_server_version() except Exception as err: - zmq_status = 1 - logger.error(err) - else: - tn.close() + logger.error(f'Cannot make SGX HTTPS check {err}') + res = { - 'status': zmq_status, - 'status_name': SGXStatus(status).name, + 'status_zmq': status_zmq, + 'status_https': status_https, 'sgx_server_url': SGX_SERVER_URL, 'sgx_keyname': g.config.sgx_key_name, 'sgx_wallet_version': version