Ad Widget

Collapse

postfix monitoring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cgillard
    Junior Member
    • May 2007
    • 6

    #1

    postfix monitoring

    Hello,

    I would like to monitor the queue of postfix:

    i will use this command postqueue -p | grep '*' | wc -l
    to have how many emails are waiting to be send.
    How can i use the result in zabbix ? (alert after 50 emails?)

    Thank you for your help
  • gryphius
    Member
    • Aug 2007
    • 30

    #2
    In your zabbix_agentd.conf create a line
    UserParameter=postfix.queue,postqueue -p | ...

    Then create an item postfix.queue in your zabbix server gui, and a trigger that fires if the value is > 50.

    You might consider using qshape instead of postqueue to get more detailed info though, because using qshape you can directly create items for let's say mails that have been in the hold queue longer than 10 minutes.

    Comment

    • cgillard
      Junior Member
      • May 2007
      • 6

      #3
      Thank you for your help but when i use this line
      UserParameter=postfix.queue,/usr/sbin/qshape |grep TOTAL|cut -c41,42

      I have an error : /usr/sbin/qshape: Can't exec "postconf": No such file or directory at /usr/sbin/qshape line 158.

      Must i add the path to the command ?

      Comment

      • gryphius
        Member
        • Aug 2007
        • 30

        #4
        Dealing with qshape requires a few tweaks, one thing is the PATH environment, the second thing is the permissions required to execute qshape.

        Here is how I did it.

        Created a script zbx_qshape.pl and put it in /usr/local/bin:
        Code:
        #!/usr/bin/perl
        # qshape wrapper for zabbix
        # Usage: zbx_qshape <queuename> <minutes>
        # Returns the number of messages in <queuename> that have been in there for <minutes>
        # <minutes> must be one of T (all,default), 5,10,20,40,80,160,320,640,1280,1280+
        # $Id: zbx_qshape.pl 9 2007-08-27 14:54:33Z oli $
        
        use strict;
        
        my $queue= @ARGV[0];
        my $time = @ARGV[1];
        
        #qshape return values index
        my %timeindex = (
        	'T' => 0,
        	'5' => 1,
        	'10' => 2,
        	'20' => 3,
        	'40' => 4,
        	'80' => 5,
         	'160' => 6,
        	'320' => 7,
        	'640' => 8,
        	'1280' => 9,
        	'1280+' => 10
        );
        my $index=$timeindex{$time};
        
        if(!$index){
        	$index=0;
        }
        
        #awk starts at 1, not at 0, and we're not interested in the word TOTAL at the beginning
        $index=$index+2;
        
        #we need to set the PATH var as qshape does rely on the environment
        my $command = "/usr/bin/env PATH=\$PATH:/usr/sbin /usr/sbin/qshape $queue | grep TOTAL | awk {'print \$$index'}";
        my $result ="-1";
        
        #print $command."\n";
        $result = qx@$command@;
        chomp($result);
        print "$result";
        Added the follwing line to sudoers (using visudo):
        Code:
        # zabbix privs
        zabbix ALL = NOPASSWD: /usr/local/bin/zbx_qshape.pl
        Added the following config options to zabbix_agentd.conf:
        Code:
        # Postfix (requires sudo entry!)
        UserParameter=postfix.holdtotal,sudo /usr/local/bin/zbx_qshape.pl hold T
        UserParameter=postfix.hold5,sudo /usr/local/bin/zbx_qshape.pl hold 5
        UserParameter=postfix.hold10,sudo /usr/local/bin/zbx_qshape.pl hold 10
        UserParameter=postfix.hold20,sudo /usr/local/bin/zbx_qshape.pl hold 20
        
        UserParameter=postfix.deferredtotal,sudo /usr/local/bin/zbx_qshape.pl deferred T
        
        UserParameter=postfix.deferred5,sudo /usr/local/bin/zbx_qshape.pl deferred 5
        UserParameter=postfix.deferred10,sudo /usr/local/bin/zbx_qshape.pl deferred 10
        UserParameter=postfix.deferred20,sudo /usr/local/bin/zbx_qshape.pl deferred 20
        I think you could also just create a single item
        Code:
        UserParameter=postfix.queue[*],sudo /usr/local/bin/zbx_qshape.pl $1 $2
        and then call the Item from zabbix like postfix.queue[hold,20], but as this runs with root privileges I wanted to be sure that no one can change the command.

        Comment

        • cgillard
          Junior Member
          • May 2007
          • 6

          #5
          well thank you for your help

          I have just a problem when i would like to create an item (fill the key with this value: UserParameter=postfix.queue[*],sudo /usr/local/bin/zbx_qshape.pl $1 $2) : which kind of item must i create (zabbix agents, ....) I have this error : Incorrect key format 'key_name[param1,param2,...]'

          When you ask to create a single item, i create it via de web interface . It's goob ?

          Comment

          • gryphius
            Member
            • Aug 2007
            • 30

            #6
            Sorry, maybe this wasn't explained very well.
            If you did your setup like I did with tons of lines in zabbix_agentd.conf like
            Code:
            UserParameter=postfix.holdtotal,sudo /usr/local/bin/zbx_qshape.pl hold T
            then the key in zabbix gui would just be 'postfix.holdtotal'

            If you use the dynamic (but possibly unsecure) form:
            Code:
            UserParameter=postfix.queue[*],sudo /usr/local/bin/zbx_qshape.pl $1 $2
            then the gui key should be something like 'postfix.queue[hold,T]'

            Item type is zabbix agent in both cases. Data tipe numeric(integer)

            Comment

            • cgillard
              Junior Member
              • May 2007
              • 6

              #7
              It's work fine

              Thank you for your help

              Comment

              • otheus
                Member
                • Mar 2009
                • 53

                #8
                I've taken a slightly different approach. Sudo is great, but it leaves behind log messages and so I avoid using it for daemon processes. Unfortunately, qshape is written in perl, and there's some difficulty getting around perl's "taint" mode which is automatically enabled when a program is somehow setuid. And without setuid, you either must degrade the permissions of the /var/spool/postfix directory, or you re-implement qshape. I chose the following approach -- more secure, but not for the faint of heart:
                • Patch qshape with the attached diff. Qshape uses the Find module which has an "untaint" feature; this patch enables that feature and sets the PATH per perl-taint requirements (see manpage on perlsec).
                • Create a wrapper program in C (also attached) which executes qshape. This also chdir's to / so that things work correctly.
                • Compile and install the C program somewhere (/usr/local/sbin perhaps) and do:
                  Code:
                  chown postfix.zabbix qshape.privileged
                  chmod 6750 qshape.privileged
                • Now update the UserParameter with this (on one line):
                  Code:
                  UserParameter=postfix.queue[ * ],
                      /usr/local/sbin/qshape.privileged -b 2 -t $2 /var/spool/postfix/$1 | 
                      awk '/TOTAL/ { print $(4);exit; }'

                The -b option says "Give me two time buckets" and the -t option is the time interval -- here in minutes. So if you configure zabbix with the following key:
                Code:
                postfix.queue[deferred,30]
                then you will get the number of messages in the deferred queue for longer than 30 minutes. In your description you can have: "Postfix queue $1 older than $2 minutes"

                This can be easily cloned and modified for a number of queues and queue times.

                (to my knowledge, there is no "original work" here, and all derived work is property of the public domain).
                Attached Files
                Last edited by otheus; 14-04-2009, 16:37.

                Comment

                Working...