Skip to content

Commit

Permalink
Merge branch 'v2.8.x' into monitor-stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed Sep 27, 2024
2 parents 5665cc8 + 3558fa2 commit d81affc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions tests/routes/health_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
44 changes: 18 additions & 26 deletions web/routes/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
import telnetlib
from enum import Enum
from http import HTTPStatus


from flask import Blueprint, g, request
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
Expand All @@ -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,
Expand All @@ -51,11 +47,6 @@
BLUEPRINT_NAME = 'health'


class SGXStatus(Enum):
CONNECTED = 0
NOT_CONNECTED = 1


health_bp = Blueprint(BLUEPRINT_NAME, __name__)


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d81affc

Please sign in to comment.