diff --git a/app/modules/db/metric.py b/app/modules/db/metric.py index 71803fd8..db50f18f 100644 --- a/app/modules/db/metric.py +++ b/app/modules/db/metric.py @@ -59,8 +59,7 @@ def select_metrics(serv, service, **kwargs): query = model.select().where(model.serv == serv) # Add time-based filtering - from datetime import datetime, timedelta - now = datetime.now() + now = datetime.utcnow() if time_range == '1': # Last 1 minute @@ -83,7 +82,6 @@ def select_metrics(serv, service, **kwargs): # Order by date query = query.order_by(model.date.asc()) - # For longer time ranges, we can sample the data to reduce the number of points # This is similar to the original SQL's "group by `date` div X" or "rowid % X = 0" if mysql_enable == '1' and time_range not in ('1', '30'): diff --git a/app/modules/service/common.py b/app/modules/service/common.py index 17140ace..6fe47c4a 100644 --- a/app/modules/service/common.py +++ b/app/modules/service/common.py @@ -178,24 +178,31 @@ def overview_backends(server_ip: str, service: str) -> Union[str, dict]: if service not in ('nginx', 'apache'): format_file = config_common.get_file_format(service) config_dir = config_common.get_config_dir(service) - cfg = config_common.generate_config_path(service, server_ip) try: - sections = section_mod.get_sections(config_dir + roxywi_common.get_files(config_dir, format_file)[0], service=service) + config_file = roxywi_common.get_files(config_dir, format_file, server_ip) + if len(config_file) == 0: + raise 'there is no config file' + sections = section_mod.get_sections(config_dir + config_file[0], service=service) except Exception as e: + cfg = config_common.generate_config_path(service, server_ip) roxywi_common.logging('Roxy-WI server', str(e), roxywi=1) try: config_mod.get_config(server_ip, cfg, service=service) except Exception as e: - raise e + raise Exception('Cannot get config file: ' + str(e)) try: sections = section_mod.get_sections(cfg, service=service) except Exception as e: - raise e + raise Exception(f'Cannot get sections: {e}') else: sections = {} - sections_not_formated = section_mod.get_remote_sections(server_ip, service) + try: + sections_not_formated = section_mod.get_remote_sections(server_ip, service) + except Exception as e: + raise Exception(f'Cannot format backends: {e}') + for section in sections_not_formated.split('\r'): if section == '\n': continue diff --git a/app/views/server/views.py b/app/views/server/views.py index de79ac08..05d0ce10 100644 --- a/app/views/server/views.py +++ b/app/views/server/views.py @@ -169,10 +169,11 @@ class ServerView(MethodView): description: Server creation successful """ group = SupportClass.return_group_id(body) + server_ip = str(body.ip) kwargs = { 'hostname': body.hostname, - 'ip': str(body.ip), + 'ip': server_ip, 'group_id': group, 'type_ip': body.type_ip, 'enabled': body.enabled, @@ -191,11 +192,11 @@ class ServerView(MethodView): except Exception as e: return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot create a server') - roxywi_common.logging(body.ip, f'A new server {body.hostname} has been created', login=1, keep_history=1, service='server') + roxywi_common.logging(server_ip, f'A new server {body.hostname} has been created', login=1, keep_history=1, service='server') try: - server_mod.update_server_after_creating(body.hostname, str(body.ip)) + server_mod.update_server_after_creating(body.hostname, server_ip) except Exception as e: - roxywi_common.logging(body.ip, f'Cannot get system info from {body.hostname}: {e}', login=1, keep_history=1, service='server', mes_type='error') + roxywi_common.logging(server_ip, f'Cannot get system info from {body.hostname}: {e}', login=1, keep_history=1, service='server', mes_type='error') if self.is_api: return IdResponse(id=last_id).model_dump(mode='json'), 201 @@ -207,7 +208,7 @@ class ServerView(MethodView): lang = roxywi_common.get_user_lang_for_flask() kwargs = { 'groups': group_sql.select_groups(), - 'servers': server_sql.select_servers(server=body.ip), + 'servers': server_sql.select_servers(server=server_ip), 'lang': lang, 'masters': server_sql.select_servers(get_master_servers=1), 'sshs': cred_sql.select_ssh(group=group),