system: remove last bits of clog (circular logging) support, closes https://github.com/opnsense/core/issues/5892

This commit is contained in:
Ad Schellevis 2022-07-19 20:13:00 +02:00
parent e58d7de7d4
commit 868c9531cd
4 changed files with 8 additions and 33 deletions

View File

@ -37,7 +37,7 @@ import argparse
import ujson
import subprocess
sys.path.insert(0, "/usr/local/opnsense/site-python")
from log_helper import reverse_log_reader, fetch_clog
from log_helper import reverse_log_reader
from params import update_params
@ -107,12 +107,8 @@ if __name__ == '__main__':
if os.path.isfile('/var/log/filter.log'):
filter_logs.append('/var/log/filter.log')
for filter_log in filter_logs:
for filename in filter_logs:
do_exit = False
try:
filename = fetch_clog(filter_log)
except Exception as e:
filename = filter_log
for record in reverse_log_reader(filename):
if record['line'].find('filterlog') > -1:
rule = dict()

View File

@ -57,9 +57,9 @@ if (isset($opts['m']) && isset($opts['f'])) {
system_syslog_start();
}
// non syslog files, in case service doesn't use our default syslog naming
$filename = "{$basename}.log";
if (is_file($filename)) {
// remove legacy clog file
@unlink($filename);
system_syslog_start();
// XXX: should probably add some plugin hook for this.

View File

@ -39,7 +39,7 @@ import datetime
import glob
from logformats import FormatContainer, BaseLogFormat
sys.path.insert(0, "/usr/local/opnsense/site-python")
from log_helper import reverse_log_reader, fetch_clog
from log_helper import reverse_log_reader
import argparse
if __name__ == '__main__':
@ -85,13 +85,9 @@ if __name__ == '__main__':
filter_regexp = re.compile('.*')
row_number = 0
for log_filename in log_filenames:
if os.path.exists(log_filename):
format_container = FormatContainer(log_filename)
try:
filename = fetch_clog(log_filename)
except Exception as e:
filename = log_filename
for filename in log_filenames:
if os.path.exists(filename):
format_container = FormatContainer(filename)
for rec in reverse_log_reader(filename):
row_number += 1
if rec['line'] != "" and filter_regexp.match(('%s' % rec['line']).lower()):

View File

@ -1,5 +1,5 @@
"""
Copyright (c) 2015-2019 Ad Schellevis <ad@opnsense.org>
Copyright (c) 2015-2022 Ad Schellevis <ad@opnsense.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -74,20 +74,3 @@ def reverse_log_reader(filename, block_size=81920, start_pos=None):
if file_byte_start == 0 and bol == -1:
yield {'line': data.strip().strip('\u0000'), 'pos': len(data)}
def fetch_clog(input_log):
""" fetch clog file (circular log)
:param input_log: clog input file
:return: stringIO
"""
with open(input_log, 'r+b') as fd:
# clog to memory
mm = mmap.mmap(fd.fileno(), 0)
# unpack clog information struct
clog_footer = struct.unpack('iiii', mm[-16:]) # cf_magic, cf_wrap, cf_next, cf_max, cf_lock
if mm[-20:-16] != b'CLOG':
raise Exception('not a valid clog file')
# concat log file into new output stream, start at current wrap position
output_stream = StringIO(mm[clog_footer[1]:-20].decode() + mm[:clog_footer[1]].decode())
output_stream.seek(0)
return output_stream