Backup automatico script del 2026-02-01 07:00
This commit is contained in:
@@ -14,6 +14,11 @@ import requests
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
DEFAULT_PATTERNS = ["*.log", "*_log.txt"]
|
||||
EXCLUDED_FILES = {
|
||||
"circondario_log.txt",
|
||||
"road_weather.log",
|
||||
"snow_radar.log",
|
||||
}
|
||||
TOKEN_FILE_HOME = os.path.expanduser("~/.telegram_dpc_bot_token")
|
||||
TOKEN_FILE_ETC = "/etc/telegram_dpc_bot_token"
|
||||
|
||||
@@ -21,7 +26,8 @@ TS_RE = re.compile(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})")
|
||||
|
||||
CATEGORIES = {
|
||||
"open_meteo_timeout": re.compile(
|
||||
r"timeout|timed out|Read timed out|Gateway Time-out|504", re.IGNORECASE
|
||||
r"timeout|timed out|Read timed out|Gateway Time-out|HTTP\s*504|status\s*504|\b504\b",
|
||||
re.IGNORECASE,
|
||||
),
|
||||
"ssl_handshake": re.compile(r"handshake", re.IGNORECASE),
|
||||
"permission_error": re.compile(r"PermissionError|permesso negato|Errno 13", re.IGNORECASE),
|
||||
@@ -207,6 +213,9 @@ def main():
|
||||
parser.add_argument("--log", action="append", help="Aggiungi un file log specifico")
|
||||
args = parser.parse_args()
|
||||
|
||||
run_ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"--- Log Monitor run {run_ts} ---")
|
||||
|
||||
if args.log:
|
||||
files = [p for p in args.log if os.path.exists(p)]
|
||||
else:
|
||||
@@ -215,6 +224,7 @@ def main():
|
||||
for pat in DEFAULT_PATTERNS:
|
||||
files.extend(sorted([str(p) for p in Path(BASE_DIR).glob(pat)]))
|
||||
files = sorted(set(files))
|
||||
files = [p for p in files if os.path.basename(p) not in EXCLUDED_FILES]
|
||||
|
||||
since = datetime.datetime.now() - datetime.timedelta(days=args.days)
|
||||
category_hits, per_file_counts, timeout_minutes, stale_logs = analyze_logs(files, since, args.max_lines)
|
||||
|
||||
Reference in New Issue
Block a user