Le 28/05/2011 16:02, Evan Martin a écrit : > I'd like to keep statistics on the number and total size of messages > received for each virtual domain each day. Similar idea to quotas, > except I want to keep the stats even for virtual aliases (forwarded to > external addresses), not just mailboxes. Ideally I'd like to insert a > record for each message into a PostgreSQL DB, which I could then query > for any period of time I want. > > Could anyone suggest the best approach to this? I've read the FILTER > README and I think filters can be used to do this, but is there a > simpler, faster way? I don't need to actually filter messages, I only > want to be notified about each message and I would need to know its size > and recipient (the real RCPT TO recipient, not the one in the To/Cc > headers). Or is there already something that does this? >
you can parse postfix logs. assuming you have a single instance of postfix (thus you have one qmgr): *) for /qmgr log lines, store the queueid and the size to your database. so you'd have a table qmgrlog with - id - time stamp - queueid - size - optional: from - optional: status (default to 0, then to set to 1 if you see "removed" in a /qmgr log line) *) for /smtp, /lmtp and /pipe log lines (be sure to exclude smtpd when matching smtp), store the queueid as well as all "field=value" parts that you need. so you'd have a table say deliverylog with - id - time stamp - logger (typically "postfix/smtp" and so on. note that the "postfix" part mpay be changed using syslog_name) - queueid - to - orig_to - relay - status - optional: delay - optional dsn - optional: the trailing text such as "(250 2.0.0 from ....)" the relay= will help you if you have a content filter. note that you can also play with syslog_name to make it easier to detect before and after filter deliveries. you can either - have a "tail -F" like script that parses logs continuously, (if your system doesn't support the '-F' flag, you'll need to use '-f' but you then need to detect log file rotation). - or have a script that runs periodically. then you need to keep info on where you stopped before. in many prog languages [for example: perl], you can use a seek function...