Small logging fixes
pull/375/head
Aidaho 2024-02-17 15:28:34 +03:00
parent 8030a69a05
commit af25700ede
20 changed files with 47 additions and 42 deletions

View File

@ -2872,7 +2872,7 @@ def select_restart_services_settings(service: str) -> str:
return query_res
def select_service_setting(server_id: int, service: str, setting: str) -> int:
def select_service_setting(server_id: int, service: str, setting: str) -> str:
try:
result = ServiceSetting.get(
(ServiceSetting.server_id == server_id)

View File

@ -149,7 +149,7 @@ def logging(server_ip: str, action: str, **kwargs) -> None:
with open(log_file, 'a') as log:
log.write(mess)
except IOError as e:
print(f'<center><div class="alert alert-danger">Cannot write log. Please check log_path in config {e}</div></center>')
print(f'Cannot write log. Please check log_path in config {e}')
def keep_action_history(service: str, action: str, server_ip: str, login: str, user_ip: str):
@ -161,8 +161,9 @@ def keep_action_history(service: str, action: str, server_ip: str, login: str, u
user_ip = 'localhost'
if service == 'HA cluster':
cluster_name = sql.select_cluster_name(server_ip)
sql.insert_action_history(service, action, server_ip, user_id, user_ip, server_ip, cluster_name)
cluster_id = server_ip
cluster_name = sql.select_cluster_name(int(cluster_id))
sql.insert_action_history(service, action, int(cluster_id), user_id, user_ip, cluster_id, cluster_name)
else:
try:
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
@ -303,5 +304,5 @@ def handle_exceptions(ex: Exception, server_ip: str, message: str, **kwargs: Any
:return: None
"""
logging(server_ip, f'{message}: {ex}', **kwargs)
raise Exception(f'{message}: {ex}')
logging(server_ip, f'error: {message}: {ex}', **kwargs)
raise Exception(f'error: {message}: {ex}')

View File

@ -28,7 +28,7 @@ def create_user(new_user: str, email: str, password: str, role: str, activeuser:
except Exception as e:
roxywi_common.logging('error: Cannot send email for a new user', e, roxywi=1, login=1)
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot create a new user: {e}', roxywi=1, login=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot create a new user', roxywi=1, login=1)
def delete_user(user_id: int) -> str:
@ -50,7 +50,7 @@ def update_user(email, new_user, user_id, enabled, group_id, role_id):
try:
sql.update_user(new_user, email, role_id, user_id, enabled)
except Exception as e:
print(e)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot update user {new_user}', roxywi=1, login=1)
sql.update_user_role(user_id, group_id, role_id)
roxywi_common.logging(new_user, ' has been updated user ', roxywi=1, login=1)

View File

@ -1,12 +1,14 @@
import modules.db.sql as sql
from modules.db.db_model import HaCluster, HaClusterRouter, HaClusterVip, HaClusterVirt
import modules.common.common as common
import modules.server.server as server_mod
import modules.roxywi.common as roxywi_common
from modules.server.ssh import return_ssh_keys_path
import json
import app.modules.db.sql as sql
from app.modules.db.db_model import HaCluster, HaClusterRouter, HaClusterVip, HaClusterVirt
import app.modules.common.common as common
import app.modules.server.server as server_mod
import app.modules.roxywi.common as roxywi_common
from app.modules.server.ssh import return_ssh_keys_path
def create_cluster(cluster: object, group_id: int) -> str:
def create_cluster(cluster: json, group_id: int) -> str:
master_ip = None
vip = common.is_ip_or_dns(cluster['vip'])
syn_flood = int(cluster['syn_flood'])
@ -68,7 +70,7 @@ def create_cluster(cluster: object, group_id: int) -> str:
return str(cluster_id)
def update_cluster(cluster: object, group_id: int) -> str:
def update_cluster(cluster: json, group_id: int) -> str:
cluster_id = int(cluster['cluster_id'])
syn_flood = int(cluster['syn_flood'])
cluster_name = common.checkAjaxInput(cluster['name'])
@ -130,7 +132,7 @@ def delete_cluster(cluster_id: int) -> str:
return 'ok'
def update_vip(cluster_id: int, router_id: int, json_data: object, group_id: int) -> None:
def update_vip(cluster_id: int, router_id: int, json_data: json, group_id: int) -> None:
return_master = int(json_data['return_to_master'])
vip = common.is_ip_or_dns(json_data['vip'])
vip_id = sql.select_clusters_vip_id(cluster_id, router_id)
@ -159,7 +161,7 @@ def update_vip(cluster_id: int, router_id: int, json_data: object, group_id: int
roxywi_common.logging(cluster_id, f'Cluster VIP {vip} has been updated', keep_history=1, roxywi=1, service='HA cluster')
def insert_vip(cluster_id: int, json_data: object, group_id: int) -> None:
def insert_vip(cluster_id: int, json_data: json, group_id: int) -> None:
vip = common.is_ip_or_dns(json_data['vip'])
return_master = int(json_data['return_to_master'])
@ -185,7 +187,7 @@ def insert_vip(cluster_id: int, json_data: object, group_id: int) -> None:
roxywi_common.logging(cluster_id, f'New cluster VIP: {vip} has been created', keep_history=1, roxywi=1, service='HA cluster')
def update_slaves(json_data: object, router_id: int) -> None:
def update_slaves(json_data: json, router_id: int) -> None:
master_ip = None
cluster = json_data
cluster_id = int(json_data['cluster_id'])
@ -243,7 +245,7 @@ def update_slaves(json_data: object, router_id: int) -> None:
raise Exception(f'error: Cannot update server {value["ip"]}: {e}')
def add_or_update_virt(cluster: object, cluster_id: int, vip_id: int, group_id: int) -> None:
def add_or_update_virt(cluster: json, cluster_id: int, vip_id: int, group_id: int) -> None:
haproxy = 0
nginx = 0
apache = 0

View File

@ -390,13 +390,13 @@ def run_ansible(inv: dict, server_ips: str, ansible_role: str) -> object:
invent.write(str(inv))
except Exception as e:
server_mod.stop_ssh_agent(agent_pid)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot save inventory file', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot save inventory file', roxywi=1)
try:
result = ansible_runner.run(**kwargs)
except Exception as e:
server_mod.stop_ssh_agent(agent_pid)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot run Ansible', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot run Ansible', roxywi=1)
try:
server_mod.stop_ssh_agent(agent_pid)
@ -425,7 +425,7 @@ def service_actions_after_install(server_ips: str, service: str, json_data) -> N
try:
update_functions[service](server_ip)
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot activate {service} on server {server_ip}', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot activate {service} on server {server_ip}', roxywi=1)
if service != 'keepalived':
is_docker = json_data['services'][service]['docker']
@ -439,7 +439,7 @@ def install_service(service: str, json_data: str) -> object:
try:
json_data = json.loads(json_data)
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot parse JSON', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot parse JSON', roxywi=1)
generate_functions = {
'haproxy': generate_haproxy_inv,
@ -453,7 +453,7 @@ def install_service(service: str, json_data: str) -> object:
service_actions_after_install(server_ips, service, json_data)
return run_ansible(inv, server_ips, service), 201
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot install {service}', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot install {service}', roxywi=1)
def _install_ansible_collections():

View File

@ -175,7 +175,7 @@ def delete_smon(smon_id, user_group) -> str:
server_ip = smon_sql.get_agent_ip_by_id(agent_id)
smon_agent.delete_check(agent_id, server_ip, smon_id)
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot delete check: {e}', roxywi=1, login=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot delete check', roxywi=1, login=1)
try:
if smon_sql.delete_smon(smon_id, user_group):
roxywi_common.logging('SMON', ' The server from SMON has been delete ', roxywi=1, login=1)

View File

@ -47,7 +47,7 @@ def add_agent(data) -> int:
common_roxywi.logging(server_ip, 'A new SMON agent has been created', roxywi=1, login=1, keep_history=1, service='SMON')
return last_id
except Exception as e:
common_roxywi.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot create Agent', roxywi=1, login=1)
common_roxywi.handle_exceptions(e, 'Roxy-WI server', 'Cannot create Agent', roxywi=1, login=1)
def delete_agent(agent_id: int):
@ -57,7 +57,7 @@ def delete_agent(agent_id: int):
inv, server_ips = generate_agent_inc(server_ip, 'uninstall', agent_uuid)
run_ansible(inv, server_ips, 'smon_agent')
except Exception as e:
common_roxywi.handle_exceptions(e, server_ip, 'error: Cannot uninstall SMON agent', roxywi=1, login=1)
common_roxywi.handle_exceptions(e, server_ip, 'Cannot uninstall SMON agent', roxywi=1, login=1)
def update_agent(json_data):
@ -69,7 +69,7 @@ def update_agent(json_data):
try:
smon_sql.update_agent(agent_id, name, desc, enabled)
except Exception as e:
common_roxywi.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot update SMON agent: {agent_id}', roxywi=1, login=1)
common_roxywi.handle_exceptions(e, 'Roxy-WI server', f'Cannot update SMON agent: {agent_id}', roxywi=1, login=1)
def get_agent_headers(agent_id: int) -> dict:

View File

@ -5,18 +5,18 @@ from flask_login import login_required
from app.routes.ha import bp
from middleware import get_user_params, check_services
import modules.db.sql as sql
import modules.common.common as common
import modules.server.server as server_mod
import modules.roxywi.common as roxywi_common
import modules.service.keepalived as keepalived
import modules.service.ha_cluster as ha_cluster
import app.modules.db.sql as sql
import app.modules.common.common as common
import app.modules.server.server as server_mod
import app.modules.roxywi.common as roxywi_common
import app.modules.service.keepalived as keepalived
import app.modules.service.ha_cluster as ha_cluster
@bp.before_request
@login_required
def before_request():
""" Protect all of the admin endpoints. """
""" Protect all the admin endpoints. """
pass

View File

@ -1,6 +1,7 @@
global_defs {
# Managed by Roxy-WI do not edit this file. Use HA cluster configuration instead
router_id LVS_DEVEL
enable_script_security
}
@ -13,6 +14,7 @@ vrrp_script chk_nginx {
}
{% endif %}
{%- if HAPROXY %}
#HAProxy health-check for keepalive
vrrp_script chk_haproxy {
@ -52,7 +54,7 @@ vrrp_instance VI_{{router}} {
advert_int 1
authentication {
auth_type PASS
auth_pass VerySecretPass
auth_pass VerySecr
}
virtual_ipaddress {
{{vip.vip}}

View File

Before

Width:  |  Height:  |  Size: 160 B

After

Width:  |  Height:  |  Size: 160 B

View File

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 148 B

View File

Before

Width:  |  Height:  |  Size: 201 B

After

Width:  |  Height:  |  Size: 201 B

View File

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

View File

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 146 B

View File

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 146 B

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -1775,25 +1775,25 @@ function showApacheLog(serv) {
} );
}
function checkSshConnect(ip) {
$.ajax( {
$.ajax({
url: "/app/server/check/ssh/" + ip,
// data: {
// token: $('#token').val()
// },
// type: "POST",
success: function( data ) {
success: function (data) {
if (data.indexOf('error:') != '-1') {
toastr.error(data)
} else if(data.indexOf('failed') != '-1') {
} else if (data.indexOf('failed') != '-1') {
toastr.error(data)
} else if(data.indexOf('Errno') != '-1') {
} else if (data.indexOf('Errno') != '-1') {
toastr.error(data)
} else {
toastr.clear();
toastr.success('Connect is accepted');
}
}
} );
});
}
function openChangeUserPasswordDialog(id) {
changeUserPasswordDialog(id);