EmailPRTG

PRTG Postfix Queues SSH Script

Here is the script i created to output postfix queue statistics to PRTG via an advanced SSH Sensor.

Copy it to /var/prtg/scriptsxml and chmod +x

#!/usr/bin/env perl

# postfix queue/s size
# author: Keith Rose

use strict;
use warnings;
use Symbol;
sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die “$0: opendir: $dir: $!\n”;
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
++$c;
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count(“$dir/$f”);
}
}
closedir($dh) or die “closedir: $dir: $!\n”;
return $c;
}
my $qdir = `postconf -h queue_directory`;
chomp($qdir);
chdir($qdir) or die “$0: chdir: $qdir: $!\n”;
printf “<prtg>”;
printf “<result>”;
printf “<channel>Incoming</channel>”;
printf “<value>%d</value>”,count(“incoming”);
printf “</result>”;

printf “<result>”;
printf “<channel>Active</channel>”;
printf “<value>%d</value>”,count(“active”);
printf “</result>”;
printf “<result>”;
printf “<channel>Deferred</channel>”;
printf “<value>%d</value>”,count(“deferred”);
printf “</result>”;
printf “<result>”;
printf “<channel>Bounce</channel>”;
printf “<value>%d</value>”,count(“bounce”);
printf “</result>”;

printf “<result>”;
printf “<channel>Hold</channel>”;
printf “<value>%d</value>”,count(“hold”);
printf “</result>”;
printf “<result>”;
printf “<channel>Corrupt</channel>”;
printf “<value>%d</value>”,count(“corrupt”);
printf “</result>”;
printf “</prtg>”;

Example output

[[email protected] scriptsxml]# ./check_queues.pl
<prtg><result><channel>Incoming</channel><value>13</value></result><result><channel>Active</channel><value>0</value></result><result><channel>Deferred</channel><value>41</value></result><result><channel>Bounce</channel><value>0</value></result><result><channel>Hold</channel><value>0</value></result><result><channel>Corrupt</channel><value>0</value></result></prtg>

PRTG Live view

postfix_live_prtg_script1

2 thoughts on “PRTG Postfix Queues SSH Script

  1. Hi

    I try you script give me this errors

    ./check_queues.pl: line 2: stfix: command not found
    ./check_queues.pl: line 5: use: command not found
    ./check_queues.pl: line 6: use: command not found
    ./check_queues.pl: line 7: use: command not found
    ./check_queues.pl: line 8: sub: command not found
    ./check_queues.pl: line 9: syntax error near unexpected token `$dir’
    ./check_queues.pl: line 9: ` my ($dir) = @_;’

Leave a Reply

Your e-mail address will not be published. Required fields are marked *