Am 2015-09-08 10:13, schrieb Patrick Ben Koetter:
Nope. I'm looking for a (more) machine readable format.
Till the implementation of this mailq feature will make it to the
customers system
will take time either.
If you want to use mailq output, than you'll have to parse the current
format.
May be this module could help:
https://metacpan.org/pod/Postfix::Parse::Mailq
Try the attached script.
At the moment I need to know the top senders in a mail queue with more
than 2
million messages. I'd rather not dig in the logs, but use Postfix
internal
knowledge about messages currently in queue.
Other option would be - as viktor said - to reuse qshape code and modify
it
to output top senders. The relevant code is only about 100 lines.
Also perl, sorry ;-)
Markus
--
Markus Benning, https://markusbenning.de/
#!/usr/bin/env perl
use strict;
use warnings;
use Postfix::Parse::Mailq;
use File::Slurp;
sub usage {
print "usage: $0 [<file>|-]\n";
}
my $mailq_output;
if( @ARGV && $ARGV[0] eq '-') {
$mailq_output = read_file( *STDIN );
} elsif( @ARGV && -e $ARGV[0] ) {
$mailq_output = read_file( $ARGV[0] );
} elsif( @ARGV ) {
usage;
} else {
$mailq_output = `mailq`;
}
my $entries = Postfix::Parse::Mailq->read_string($mailq_output);
my $senders = {};
foreach my $entry (@$entries) {
my $sender = $entry->{'sender'};
if( ! defined $sender ) {
next;
}
if( ! defined $senders->{$sender} ) {
$senders->{$sender} = {
count => 0,
size => 0,
remaining_rcpts => 0,
};
}
$senders->{$sender}->{'count'}++;
$senders->{$sender}->{'size'} += $entry->{'size'};
$senders->{$sender}->{'remaining_rcpts'} += scalar @{ $entry->{remaining_rcpts} };
}
my @ordered = sort {
$senders->{$a}->{'count'}
<=>
$senders->{$b}->{'count'}
} keys %$senders;
printf("%30s %6s %10s %3s\n",
'address', 'count', 'size', 'remaining rcpt'
);
foreach my $sender ( @ordered ) {
printf("%30s %6d %10d %3d\n",
$sender,
$senders->{$sender}->{'count'},
$senders->{$sender}->{'size'},
$senders->{$sender}->{'remaining_rcpts'},
);
}