public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Oguz Bektas <o.bektas@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-log-tracker] fix #3657: allow parsing mail.log files
Date: Wed,  6 Oct 2021 13:46:16 +0200	[thread overview]
Message-ID: <20211006114616.1131543-1-o.bektas@proxmox.com> (raw)

with an optional "--maillog" parameter, we parse /var/log/mail.log.*
instead of /var/log/syslog.*

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
---
 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;
+                }
+                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",
+];
+
 const LOGFILES: [&str; 32] = [
     "/var/log/syslog",
     "/var/log/syslog.1",
-- 
2.30.2





             reply	other threads:[~2021-10-06 11:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 11:46 Oguz Bektas [this message]
2021-10-06 11:51 ` Thomas Lamprecht
2021-10-06 13:28   ` Stoiko Ivanov
2021-10-06 13:41     ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211006114616.1131543-1-o.bektas@proxmox.com \
    --to=o.bektas@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal