From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1261772276 for ; Wed, 6 Oct 2021 14:03:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 01000C28A for ; Wed, 6 Oct 2021 14:03:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 598ECC27B for ; Wed, 6 Oct 2021 14:03:08 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D283645786 for ; Wed, 6 Oct 2021 13:53:04 +0200 (CEST) Message-ID: Date: Wed, 6 Oct 2021 13:51:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Thunderbird/93.0 Content-Language: en-US To: Oguz Bektas , pmg-devel@lists.proxmox.com References: <20211006114616.1131543-1-o.bektas@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20211006114616.1131543-1-o.bektas@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 1.199 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -1.964 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Subject: Re: [pmg-devel] [PATCH pmg-log-tracker] fix #3657: allow parsing mail.log files X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Oct 2021 12:03:39 -0000 On 06.10.21 13:46, Oguz Bektas wrote: > with an optional "--maillog" parameter, we parse /var/log/mail.log.* > instead of /var/log/syslog.* --mail-log and it may make sense to allow passing a base path to that, that would also allow easier evaluation like copy of the logs from the production system and run queries on another, not so important, system. > > Signed-off-by: Oguz Bektas > --- > src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 48 insertions(+), 1 deletion(-) > > diff --git a/src/main.rs b/src/main.rs > index b1d4f8c..13ca63b 100644 > --- a/src/main.rs > +++ b/src/main.rs > @@ -39,6 +39,11 @@ fn main() -> Result<(), Error> { > .help("Input file to use instead of /var/log/syslog, or '-' for stdin") > .value_name("INPUTFILE"), > ) > + .arg( > + Arg::with_name("maillog") > + .long("maillog") > + .help("Use /var/log/mail.log* files instead of /var/log/syslog") > + ) > .arg( > Arg::with_name("host") > .short("h") > @@ -1816,7 +1821,11 @@ impl Parser { > let filecount = self.count_files_in_time_range(); > for i in (0..filecount).rev() { > self.current_month = 0; > - if let Ok(file) = File::open(LOGFILES[i]) { > + let mut target_files = LOGFILES; > + if self.options.maillog { > + target_files = MAILLOGFILES; > + } that can be done nicer in rust avoiding mut completely, either use the fact that if statements can return expressions or the match feature, e.g. the former: let target_files = if self.options.maillog { MAILLOGFILES } else { LOGFILES }; avoiding mut is nicer for saner programs and allows often better optimizations. > + if let Ok(file) = File::open(target_files[i]) { > self.current_file_index = i; > if i > 1 { > let gzdecoder = read::GzDecoder::new(file); > @@ -1988,6 +1997,8 @@ impl Parser { > self.options.inputfile = inputfile.to_string(); > } > > + self.options.maillog = args.is_present("maillog"); > + > if let Some(start) = args.value_of("start") { > if let Ok(res) = time::strptime(&start, "%F %T") { > self.options.start = mkgmtime(&res); > @@ -2121,6 +2132,7 @@ struct Options { > end: libc::time_t, > limit: u64, > verbose: u32, > + maillog: bool, > exclude_greylist: bool, > exclude_ndr: bool, > } > @@ -2208,6 +2220,41 @@ fn mkgmtime(tm: &time::Tm) -> libc::time_t { > res > } > > +const MAILLOGFILES: [&str; 32] = [ > + "/var/log/mail.log", > + "/var/log/mail.log.1", > + "/var/log/mail.log.2.gz", > + "/var/log/mail.log.3.gz", > + "/var/log/mail.log.4.gz", > + "/var/log/mail.log.5.gz", > + "/var/log/mail.log.6.gz", > + "/var/log/mail.log.7.gz", > + "/var/log/mail.log.8.gz", > + "/var/log/mail.log.9.gz", > + "/var/log/mail.log.10.gz", > + "/var/log/mail.log.11.gz", > + "/var/log/mail.log.12.gz", > + "/var/log/mail.log.13.gz", > + "/var/log/mail.log.14.gz", > + "/var/log/mail.log.15.gz", > + "/var/log/mail.log.16.gz", > + "/var/log/mail.log.17.gz", > + "/var/log/mail.log.18.gz", > + "/var/log/mail.log.19.gz", > + "/var/log/mail.log.20.gz", > + "/var/log/mail.log.21.gz", > + "/var/log/mail.log.22.gz", > + "/var/log/mail.log.23.gz", > + "/var/log/mail.log.24.gz", > + "/var/log/mail.log.25.gz", > + "/var/log/mail.log.26.gz", > + "/var/log/mail.log.27.gz", > + "/var/log/mail.log.28.gz", > + "/var/log/mail.log.29.gz", > + "/var/log/mail.log.30.gz", > + "/var/log/mail.log.31.gz", > +]; could be an iterator (good if we want to allow an arbitrary base) or using a const fn (for a fixed one like here)... > + > const LOGFILES: [&str; 32] = [ > "/var/log/syslog", > "/var/log/syslog.1", >