Skip to content

Commit

Permalink
Merge pull request #183 from Progress1/dup_logs
Browse files Browse the repository at this point in the history
Disable duplicities on the log screen if we have SYSLOG disabled
  • Loading branch information
milankowww authored Nov 29, 2023
2 parents 1fcc115 + aedeced commit 298e9e7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/bots/managers/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def log_critical(message):
sys_logger = None
log_debug("Unable to connect to syslog server!")
log_debug(ex)
else:
# disable log duplicities on the screen if we have SYSLOG disabled
sys_logger = None

def log_system_activity(module, message):
log_info("[{}] {}".format(module, message))
Expand Down
3 changes: 3 additions & 0 deletions src/collectors/managers/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def log_critical(message):
sys_logger = None
log_warning("Unable to connect to syslog server!")
log_warning(ex)
else:
# disable log duplicities on the screen if we have SYSLOG disabled
sys_logger = None

def log_system_activity(module, message):
log_info("[{}] {}".format(module, message))
Expand Down
20 changes: 3 additions & 17 deletions src/core/managers/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
gunicorn_logger.setLevel(logging.DEBUG)
sys_logger.setLevel(logging.DEBUG)



# alter the sensitive value for logging, based on LOG_SENSITIVE_DATA env variable:
#
# LOG_SENSITIVE_DATA=no (or undefined) - remove sensitive data
Expand All @@ -59,7 +57,6 @@ def sensitive_value(value):
else:
return '•••••'


# used to decrypt the encrypted secrets from the logs
# source: https://github.com/gdavid7/cryptocode/blob/main/cryptocode.py
# TODO: add a command line wrapper around this function
Expand Down Expand Up @@ -106,8 +103,6 @@ def generate_escaped_data(request_data):
data = re.sub(r'(^\s+)|(\s+$)', '', data)
return data



# send a debug message
def log_debug(message):
formatted_message = "[{}] {}".format(module_id,message)
Expand Down Expand Up @@ -168,36 +163,33 @@ def log_critical(message):
sys_logger = None
log_debug("Unable to connect to syslog server!")
log_debug(ex)

else:
# disable log duplicities on the screen if we have SYSLOG disabled
sys_logger = None

def resolve_ip_address():
headers_list = request.headers.getlist("X-Forwarded-For")
ip_address = headers_list[0] if headers_list else request.remote_addr
return ip_address


def resolve_method():
return request.method


def resolve_resource():
fp_len = len(request.full_path)
if request.full_path[fp_len - 1] == '?':
return request.full_path[:fp_len - 1]
else:
return request.full_path


def store_activity(activity_type, activity_detail, request_data = None):
LogRecord.store(resolve_ip_address(), None, None, None, None, module_id, activity_type, resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_user_activity(user, activity_type, activity_detail, request_data = None):
LogRecord.store(resolve_ip_address(), user.id, user.name, None, None, module_id, activity_type, resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_access_error_activity(user, activity_detail, request_data = None):
ip = resolve_ip_address()
log_text = "TARANIS NG Access Error (IP: {}, User ID: {}, User Name: {}, Method: {}, Resource: {}, Activity Detail: {}, Activity Data: {})".format(
Expand All @@ -220,7 +212,6 @@ def store_access_error_activity(user, activity_detail, request_data = None):
LogRecord.store(ip, user.id, user.name, None, None, module_id, "ACCESS_ERROR", resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_data_error_activity(user, activity_detail, request_data = None):
db.session.rollback()
ip = resolve_ip_address()
Expand All @@ -243,7 +234,6 @@ def store_data_error_activity(user, activity_detail, request_data = None):
LogRecord.store(ip, user.id, user.name, None, None, module_id, "DATA_ERROR", resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_data_error_activity_no_user(activity_detail, request_data = None):
db.session.rollback()
ip = resolve_ip_address()
Expand All @@ -264,7 +254,6 @@ def store_data_error_activity_no_user(activity_detail, request_data = None):
LogRecord.store(ip, None, None, None, None, module_id, "PUBLIC_ACCESS_DATA_ERROR", resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_auth_error_activity(activity_detail, request_data = None):
db.session.rollback()
log_text = "TARANIS NG Auth Error (Method: {}, Resource: {}, Activity Detail: {}, Activity Data: {})".format(
Expand All @@ -283,7 +272,6 @@ def store_auth_error_activity(activity_detail, request_data = None):
LogRecord.store(resolve_ip_address(), None, None, None, None, module_id, "AUTH_ERROR", resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_user_auth_error_activity(user, activity_detail, request_data = None):
db.session.rollback()
ip = resolve_ip_address()
Expand All @@ -304,12 +292,10 @@ def store_user_auth_error_activity(user, activity_detail, request_data = None):
LogRecord.store(ip, user.id, user.name, None, None, module_id, "AUTH_ERROR", resolve_resource(),
activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_system_activity(system_id, system_name, activity_type, activity_detail, request_data = None):
LogRecord.store(resolve_ip_address(), None, None, system_id, system_name, module_id, activity_type,
resolve_resource(), activity_detail, resolve_method(), generate_escaped_data(request_data))


def store_system_error_activity(system_id, system_name, activity_type, activity_detail, request_data = None):
db.session.rollback()
ip = resolve_ip_address()
Expand Down
3 changes: 3 additions & 0 deletions src/presenters/managers/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def log_critical(message):
sys_logger = None
log_debug("Unable to connect to syslog server!")
log_debug(ex)
else:
# disable log duplicities on the screen if we have SYSLOG disabled
sys_logger = None

def log_system_activity(module, message):
log_info("[{}] {}".format(module, message))
Expand Down
3 changes: 3 additions & 0 deletions src/publishers/managers/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def log_critical(message):
sys_logger = None
log_debug("Unable to connect to syslog server!")
log_debug(ex)
else:
# disable log duplicities on the screen if we have SYSLOG disabled
sys_logger = None

def log_system_activity(module, message):
log_info("[{}] {}".format(module, message))
Expand Down

0 comments on commit 298e9e7

Please sign in to comment.