Ad Widget

Collapse

Postfix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Razique
    Junior Member
    • Sep 2009
    • 19

    #16
    Hi All,
    thanks a ton for your script frater I had to tweak it a bit in order to make it work. I use a compiled version of Zabbix (Version 1.8.3). The zabbix_sender binary requires extra argument. So I added two variables :
    ZABBIX_HOST=The monitored server hostname (see /etc/zabbix/zabbix_agentd.conf)
    ZABBIX_SERVER=The IP address of the Zabbix server

    and at line 16 I added two arguments : the -s $ZABBIX_HOST and -z $ZABBIX_SERVER
    Here is the final script :
    Code:
    #!/bin/bash
    
    MAILLOG=/var/log/mail.log
    DAT1=/tmp/zabbix-postfix-offset.dat
    DAT2=$(mktemp)
    PFLOGSUMM=/home/john/pflogsumm.pl
    ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
    ZABBIX_HOST=DA_FUNKY_SERVER
    ZABBIX_SERVER=8.8.8.8
    DEBUG=1
    
    function zsend {
      key="postfix[`echo "$1" | tr ' -' '_' | tr '[A-Z]' '[a-z]' | tr -cd [a-z_]`]"
      value=`grep -m 1 "$1" $DAT2 | awk '{print $1}'`
      [ ${DEBUG} -ne 0 ] && echo "Send key \"${key}\" with value \"${value}\"" >&2
      /usr/local/bin/zabbix_sender -s $ZABBIX_HOST -z $ZABBIX_SERVER -c $ZABBIX_CONF -k "${key}" -o "${value}" 2>&1 >/dev/null
    }
    
    /usr/sbin/logtail -f$MAILLOG -o$DAT1 | $PFLOGSUMM -h 0 -u 0 --no_bounce_detail --no_deferral_detail --no_reject_detail --no_no_msg_size --no_smtpd_warnings > $DAT2
    
    zsend received
    zsend delivered
    zsend forwarded
    zsend deferred
    zsend bounced
    zsend rejected
    zsend held
    zsend discarded
    zsend "reject warnings"
    zsend "bytes received"
    zsend "bytes delivered"
    zsend senders
    zsend recipients
    
    rm $DAT2
    I also changed the name for the postfix[recipients] item. The item was "postfix[bytes_recipient]" which is not the key send by the script (plus the item was meaningless ).

    I also added a graph for that template (I set the unit to the collected values as "mails" except for the two items that return bytes), and 4 triggers which make sure the queue doesn't hold more than 400 mails, and I also check the deferred/ rejected mails.
    Here is how the scoreboard looks like :

    The template has been updated, you can download the attachment

    zbx_templates_export.xml
    Last edited by Razique; 29-12-2010, 23:53.

    Comment

    • frater
      Senior Member
      • Oct 2010
      • 340

      #17
      Originally posted by Razique
      Hi All,
      thanks a ton for your script frater I had to tweak it a bit in order to make it work. I use a compiled version of Zabbix (Version 1.8.3). The zabbix_sender binary requires extra argument. So I added two variables :
      ZABBIX_HOST=The monitored server hostname (see /etc/zabbix/zabbix_agentd.conf)
      ZABBIX_SERVER=The IP address of the Zabbix server

      and at line 16 I added two arguments : the -s $ZABBIX_HOST and -z $ZABBIX_SERVER
      Here is the final script :
      You are free to change the script of course, but these extra arguments are really not necessary if the info in /etc/zabbix/zabbix_agentd.conf corresponds with the server.

      If the "HOSTNAME" in your /etc/zabbix/zabbix_agentd.conf doesn't match with the hostname in the server, the zabbix-agentd will work fine, but zabbix_sender doesn't. Your server will refuse the info coming from zabbix_sender.

      By specifying the HOSTNAME on the command-line you override the setting in /etc/zabbix/zabbix_agentd.conf.
      It's more elegant to use the info from /etc/zabbix/zabbix_agentd.conf as it will have all the parameters in one place....

      Zabbix shouldn't really accept data from the agent either if the hostname is incorrect. This is a demonstration how it leads to confusion.
      The script is fine as I posted it.
      It's understandable you changed it, but I would advice you to correct /etc/zabbix/zabbix_agentd.conf. Maybe the authors of Zabbix suddenly decide to change the behaviour of it in the next release.


      Thanks for the graphs.
      The server running postfix is doing the least in our network. sendmail is still doing the most.
      Last edited by frater; 30-12-2010, 14:18.
      Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

      Comment

      • Razique
        Junior Member
        • Sep 2009
        • 19

        #18
        Hi,
        well, the hostname is EXACTLY the same here :
        the name of the server (when I type : hostname)
        the name into the zabbix_agentd.conf
        the name the server has into zabbix (DNS name AND hostname)

        So I've 4 times the same name, and it didn't worked. When I added the option through the -z and -z option, it worked like a charm

        Comment

        • frater
          Senior Member
          • Oct 2010
          • 340

          #19
          Originally posted by Razique
          So I've 4 times the same name, and it didn't worked. When I added the option through the -z and -z option, it worked like a charm
          I can't do more than reply, it works fine with merely -c /etc/zabbix/zabbix_agentd.conf

          I noticed you put your offset-file somewhere else (in a home directory). Maybe the script is not allowed to read /etc/zabbix/zabbix_agentd.conf?

          I still recommend to find out why giving '-c /etc/zabbix/zabbix_agentd.conf' is not working for you. As I wrote in my previous post it's better that way.
          I'm sure you can omit '-c ...' completely in your config

          If I bump into something in the future I will get back on it.
          Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

          Comment

          • Razique
            Junior Member
            • Sep 2009
            • 19

            #20
            Hi Frater, thanks for your answer. I'm running the script as root (so the parsing of mail.log is possible).
            The /home is just for me a convenient way to keep my scripts organized: )
            For instance, without any use of your script, and a good server and agent conf :

            root@VM1:/home/MONITORING# zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k "postfix[recipients]" -o "29" -vv
            zabbix_sender [28093]: Warning: 'Hostname' parameter required
            sent: 0; skipped: 1; total: 1

            root@VM1:/home/MONITORING# cat /etc/zabbix/zabbix_agentd.conf | grep hostname
            hostname=VM1
            root@VM1:/home/MONITORING# zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k "postfix[recipients]" -o "29" -s VM1 -vv
            zabbix_sender [28139]: DEBUG: Answer [{
            "response":"success",
            "info":"Processed 1 Failed 0 Total 1 Seconds spent 0.000036"}]
            Info from server: "Processed 1 Failed 0 Total 1 Seconds spent 0.000036"
            sent: 1; skipped: 0; total: 1


            Weird eh


            ok I figured it out. For some reason, my conf. has the word hostname with a h not an H. So i changed to Hostname and it worked. For sure, i made a mistake, when i made the bulk deployment.
            thanks for the hint frater
            Last edited by Razique; 30-12-2010, 18:35.

            Comment

            • frater
              Senior Member
              • Oct 2010
              • 340

              #21
              Originally posted by Razique
              ok I figured it out. For some reason, my conf. has the word hostname with a h not an H. So i changed to Hostname and it worked. For sure, i made a mistake, when i made the bulk deployment.
              thanks for the hint frater
              Understandable why it was difficult to find out why it wasn't working.
              Zabbix is a bit strange that it allows you to add an agent with a completely different hostname and when zabbix_sender connects it is suddenly case-sensitive.

              well... now we know ;-)
              Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

              Comment

              • Razique
                Junior Member
                • Sep 2009
                • 19

                #22
                Hi,
                another thing I had :
                postfix[bytes_received]] error: Type of received value [2067k] is not suitable for value type [Numeric (unsigned)]

                I had to switch to numeric (float) for the two items, now it works

                Comment

                • qix
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Oct 2006
                  • 423

                  #23
                  It works!

                  I'd like to thank the original author and frater for this.
                  I'd didn't have to figure this one out myself thanks to you guys

                  Thanks a bunch!
                  With kind regards,

                  Raymond

                  Comment

                  • gigatec
                    Junior Member
                    • Sep 2011
                    • 15

                    #24
                    There seems to be an issue with the sender script, 'cause pflogsumm adds a 'k' if the amount of transmitted data is over a certain level:

                    Code:
                    Send key "postfix[bytes_received]" with value "4756k"
                    Send key "postfix[bytes_delivered]" with value "4756k"
                    The result on the server-side is

                    Code:
                     24886:20111001:124634.973 Item [server19:postfix[bytes_delivered]] became not supported: Type of received value [4756k] is not suitable for value type [Numeric (unsigned)]
                     24886:20111001:124634.973 Item [server19:postfix[bytes_received]] became not supported: Type of received value [4756k] is not suitable for value type [Numeric (float)]
                    Changing the value type to 'text' seems to be a bad solution, because I can't calculate with a text item...

                    I could not find a switch in pflogsumm to always output in bytes.

                    Any ideas / solutions are welcome ,-)

                    Regards
                    Stephan

                    pflogsumm 1.1.3 on debian squeeze, zabbix 1.8.7

                    Comment

                    • frater
                      Senior Member
                      • Oct 2010
                      • 340

                      #25
                      Several solutions:

                      You could patch pflogsumm....

                      Code:
                      # Some constants used by display routines.  I arbitrarily chose to
                      # display in kilobytes and megabytes at the 512k and 512m boundaries,
                      # respectively.  Season to taste.
                      $divByOneKAt   = 524288;        # 512k
                      $divByOneMegAt = 536870912;     # 512m
                      $oneK          = 1024;          # 1k
                      $oneMeg        = 1048576;       # 1m
                      • making the divByOneKAt and divByOneMegAt incredibly high....
                      • patch "1024" to "1000" and "1048576" to "1000000" and replace the line "value=`grep -m 1 "$1" $DAT2 | awk '{print $1}'`" with "value=`grep -m 1 "$1" $DAT2 | awk '{print $1}' | sed 's/k/000/;s/m/000000/'`" (if you don't patch pflogsumm the values just wouldn't be exact)
                      • don't patch pflogsumm and replace those lines with this code

                        value=`grep -m 1 "$1" $DAT2 | awk '{print $1}'`
                        case "`echo ${value} | tr -cd 'km'`" in
                        k)
                        multiplier=1024
                        ;;
                        m)
                        multiplier=1048576
                        ;;
                        *)
                        multiplier=1
                        ;;
                        esac
                        value=`echo "${value}" | tr -cd '0-9'`
                        let value*=${multiplier}



                      I tried to think of some one-liner in awk, but this will do..
                      So, just replace the script with this code...


                      Code:
                      #!/bin/bash
                      
                      MAILLOG=/var/log/mail.log
                      DAT1=/tmp/zabbix-postfix-offset.dat
                      DAT2=$(mktemp)
                      PFLOGSUMM=/usr/sbin/pflogsumm
                      ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
                      DEBUG=1
                      
                      function zsend {
                        key="postfix[`echo "$1" | tr ' -' '_' | tr '[A-Z]' '[a-z]' | tr -cd [a-z_]`]"
                        value=`grep -m 1 "$1" $DAT2 | awk '{print $1}' | awk '/k|m/{p = /k/?1:2}{printf "%d\n", int($1) * 1024 ^ p}'`
                      
                        [ ${DEBUG} -ne 0 ] && echo "Send key \"${key}\" with value \"${value}\"" >&2
                        /usr/bin/zabbix_sender -c $ZABBIX_CONF -k "${key}" -o "${value}" 2>&1 >/dev/null
                      }
                      
                      /usr/sbin/logtail -f$MAILLOG -o$DAT1 | $PFLOGSUMM -h 0 -u 0 --no_bounce_detail --no_deferral_detail --no_reject_detail --no_no_msg_size --no_smtpd_warnings > $DAT2
                      
                      zsend received
                      zsend delivered
                      zsend forwarded
                      zsend deferred
                      zsend bounced
                      zsend rejected
                      zsend held
                      zsend discarded
                      zsend "reject warnings"
                      zsend "bytes received"
                      zsend "bytes delivered"
                      zsend senders
                      zsend recipients
                      
                      rm $DAT2

                      PS... Just to emphasize: the last solution is the best... Just replace the script I wrote with this new one and leave pflogsumm alone.....

                      EDIT:

                      Thanks to Grail, Druuna and CRTS I came up with better code to change the kbytes and mbytes back to bytes.
                      http://www.linuxquestions.org/questi...=1#post4487802
                      Last edited by frater; 02-10-2011, 10:34.
                      Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

                      Comment

                      • gigatec
                        Junior Member
                        • Sep 2011
                        • 15

                        #26
                        Perfect - thank you very much!

                        Regards
                        Stephan

                        Comment

                        • frater
                          Senior Member
                          • Oct 2010
                          • 340

                          #27
                          Someone using openBSD asked me to create a workaround for "grep -m 1".
                          It seems their grep doesn't support the "-m 1" like our GNU-version.

                          Code:
                          grep -m 1 "$1" $DAT2
                          can be replaced with
                          Code:
                          grep "$1" $DAT2 | head -n1
                          It's not exactly the same, but it does work here.
                          Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

                          Comment

                          • SrTunes
                            Member
                            • Feb 2013
                            • 37

                            #28
                            Help

                            I need to monitoring two itens that pflogsumm don't show, virus and spam.
                            How can I do this?

                            Comment

                            • ocin
                              Junior Member
                              • Feb 2014
                              • 1

                              #29
                              As this uses active checks and I wanted passive ones I put together a script which makes that possible: http://lifeisabug.com/postfix-statis...assive-checks/

                              Improvements welcome.

                              Comment

                              • RX8
                                Junior Member
                                • Nov 2014
                                • 1

                                #30
                                Hi,

                                when i try to run the script that u posted up there i get the following error and cant figure out what the exact problem is.
                                Did everything as mentioned above.

                                zabbix-postfix.sh: 10: zabbix-postfix.sh: function: not found
                                Send key "postfix[]" with value ""
                                zabbix-postfix.sh: 16: zabbix-postfix.sh: Syntax error: "}" unexpected
                                cheers

                                Comment

                                Working...