* Mon Sep 01 2025 Brian Read <brianr@koozali.org> 11.1-4.sme
- More fixes for Journal bytes instead of characters [SME: 13117]
This commit is contained in:
@@ -98,7 +98,7 @@ log_dir_path = "/var/log/mailstats"
|
|||||||
# Check if the directory exists, and create it if it doesn't
|
# Check if the directory exists, and create it if it doesn't
|
||||||
if not os.path.exists(log_dir_path):
|
if not os.path.exists(log_dir_path):
|
||||||
os.makedirs(log_dir_path)
|
os.makedirs(log_dir_path)
|
||||||
logging.basicConfig(level=logging.DEBUG, # Default level of messages to log
|
logging.basicConfig(level=logging.INFO, # Default level of messages to log
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.StreamHandler(), # Log to console
|
logging.StreamHandler(), # Log to console
|
||||||
@@ -242,14 +242,22 @@ def get_logs_from_Journalctl(date='yesterday'):
|
|||||||
|
|
||||||
# Retrieve logs within the time range
|
# Retrieve logs within the time range
|
||||||
logs = []
|
logs = []
|
||||||
|
log_count = 0
|
||||||
|
error_count = 0
|
||||||
for entry in j:
|
for entry in j:
|
||||||
|
try:
|
||||||
entry_timestamp = entry.get('__REALTIME_TIMESTAMP', None)
|
entry_timestamp = entry.get('__REALTIME_TIMESTAMP', None)
|
||||||
entry_microseconds = int(entry_timestamp.timestamp() * 1_000_000)
|
entry_microseconds = int(entry_timestamp.timestamp() * 1_000_000)
|
||||||
if entry_timestamp and since_microseconds <= entry_microseconds <= until_microseconds:
|
if entry_timestamp and since_microseconds <= entry_microseconds <= until_microseconds:
|
||||||
|
log_count += 1
|
||||||
# takeout ASCII Escape sequences from the message
|
# takeout ASCII Escape sequences from the message
|
||||||
entry['MESSAGE'] = strip_ansi_codes(entry['MESSAGE'])
|
entry['MESSAGE'] = strip_ansi_codes(entry['MESSAGE'])
|
||||||
logs.append(entry)
|
logs.append(entry)
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"Error - log line: {log_count} {entry['_PID']} {entry['SYSLOG_IDENTIFIER']} : {e}")
|
||||||
|
error_count += 1
|
||||||
|
if error_count:
|
||||||
|
logging.info(f"Had {error_count} errors on journal import - probably non character bytes")
|
||||||
# Sort logs by __REALTIME_TIMESTAMP in ascending order
|
# Sort logs by __REALTIME_TIMESTAMP in ascending order
|
||||||
sorted_logs = sorted(logs, key=lambda x: x.get("__REALTIME_TIMESTAMP", 0))
|
sorted_logs = sorted(logs, key=lambda x: x.get("__REALTIME_TIMESTAMP", 0))
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ Summary: Daily mail statistics for SME Server
|
|||||||
%define name smeserver-mailstats
|
%define name smeserver-mailstats
|
||||||
Name: %{name}
|
Name: %{name}
|
||||||
%define version 11.1
|
%define version 11.1
|
||||||
%define release 3
|
%define release 4
|
||||||
Version: %{version}
|
Version: %{version}
|
||||||
Release: %{release}%{?dist}
|
Release: %{release}%{?dist}
|
||||||
License: GPL
|
License: GPL
|
||||||
@@ -35,6 +35,9 @@ A script that via cron.d e-mails mail statistics to admin on a daily basis.
|
|||||||
See http://www.contribs.org/bugzilla/show_bug.cgi?id=819
|
See http://www.contribs.org/bugzilla/show_bug.cgi?id=819
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Sep 01 2025 Brian Read <brianr@koozali.org> 11.1-4.sme
|
||||||
|
- More fixes for Journal bytes instead of characters [SME: 13117]
|
||||||
|
|
||||||
* Mon Sep 01 2025 Brian Read <brianr@koozali.org> 11.1-3.sme
|
* Mon Sep 01 2025 Brian Read <brianr@koozali.org> 11.1-3.sme
|
||||||
- Sort out ASCII escape codes in return from journalctl API [SME: 13117]
|
- Sort out ASCII escape codes in return from journalctl API [SME: 13117]
|
||||||
- Add in Status enabled t default for mailstats DB [SME: 13118]
|
- Add in Status enabled t default for mailstats DB [SME: 13118]
|
||||||
|
Reference in New Issue
Block a user