CACTI - POSTFIX - ISPConfig

Discussion in 'General' started by vaio1, Dec 3, 2009.

  1. vaio1

    vaio1 Member

    Hi guys,

    how can I monitorize the mails?
    I have found this script (attached here) that helps to get the data from the postfix but I don't know how can be used together the ISPConfig configuration.

    I mean that I don't find some information required by the stat script.

    fetch_mail_statistics.pl /var/log/mail.log /var/log/mailstats.db .1.3.6.1.4.1.2021.255 -g .1.3.6.1.4.1.2021.255

    where are those files?

    thanks in advance
     

    Attached Files:

  2. falko

    falko Super Moderator Howtoforge Staff

    What files?
     
  3. Mark_NL

    Mark_NL Member

    I'm using mailgraph.pl in combination with a cacti template someone made .. works perfectly :)
     
  4. vaio1

    vaio1 Member

    I would like to configure it too but I have found some problem.
    I use CentOS 5.4 & ISPConfig 2.

    Where do you have downloaded it?
     
  5. Mark_NL

    Mark_NL Member

    1. download mailgraph http://mailgraph.schweikert.ch/

    - open the tar.gz file (tar zxf mailgraph-1.14.tar.gz)
    - copy the file mailgraph.pl to dir: /usr/local/bin
    - copy the file mailgraph-init to dir: /etc/init.d/ and rename it to "mailgraph"

    (the following works on debian, i don't know if it works on centos as well, it's to create an autostart when the server reboots)
    - run: update-rc.d mailgraph defaults

    2. edit /etc/snmp/snmpd.conf and add these lines:
    Code:
    exec   mailcount_sent           /bin/cat /tmp/mailsent
    exec   mailcount_recv           /bin/cat /tmp/mailrecv
    exec   mailcount_reject         /bin/cat /tmp/mailrejected
    exec   mailcount_bounced        /bin/cat /tmp/mailbounced
    exec   mailcount_spam           /bin/cat /tmp/mailspam
    exec   mailcount_virus          /bin/cat /tmp/mailvirus
    
    3. restart snmpd (/etc/init.d/snmpd restart)

    4. Open the file mailgraph.pl and find the sub "update" (search for "sub update($)")

    5. Replace the function with this one:
    Code:
    sub update($)
    {
    	my $t = shift;
    	my $m = $t - $t%$rrdstep;
    	init_rrd($m) unless $rrd_inited;
    	return 1 if $m == $this_minute;
    	return 0 if $m < $this_minute;
    
            `echo $sum{sent} > /tmp/mailsent`;
            `echo $sum{received} > /tmp/mailrecv`;
            `echo $sum{bounced} > /tmp/mailbounced`;
    	`echo $sum{rejected} > /tmp/mailrejected`;
    	`echo $sum{virus} > /tmp/mailvirus`;
            `echo $sum{spam} > /tmp/mailspam`;
    
    #	print "update $this_minute:$sum{sent}:$sum{received}:$sum{bounced}:$sum{rejected}:$sum{virus}:$sum{spam}\n" if $opt{verbose};
    #	RRDs::update $rrd, "$this_minute:$sum{sent}:$sum{received}:$sum{bounced}:$sum{rejected}" unless $opt{'only-virus-rrd'};
    #	RRDs::update $rrd_virus, "$this_minute:$sum{virus}:$sum{spam}" unless $opt{'only-mail-rrd'};
    #	if($m > $this_minute+$rrdstep) {
    #		for(my $sm=$this_minute+$rrdstep;$sm<$m;$sm+=$rrdstep) {
    #			print "update $sm:0:0:0:0:0:0 (SKIP)\n" if $opt{verbose};
    #			RRDs::update $rrd, "$sm:0:0:0:0" unless $opt{'only-virus-rrd'};
    #			RRDs::update $rrd_virus, "$sm:0:0" unless $opt{'only-mail-rrd'};
    #		}
    #	}
    	$this_minute = $m;
    	$sum{sent}=0;
    	$sum{received}=0;
    	$sum{bounced}=0;
    	$sum{rejected}=0;
    	$sum{virus}=0;
    	$sum{spam}=0;
    	return 1;
    }
    6. Start mailgraph (/etc/init.d/mailgraph start)

    What have we done so far:
    - Mailgraph will write it's totals to files in /tmp directory.
    - We've added some options for snmpd (so cacti can get the totals through snmp)

    7. Import the attached xml file in cacti
     

    Attached Files:

    Last edited: Dec 4, 2009
  6. vaio1

    vaio1 Member

    I don't understand this part of the installation:

    Code:
    See the file mailgraph-init for an example init script that you can use to
    start mailgraph at system boot.
    
    and then have I just copy the cgi file in the cgi folder of my website previously created on ISPConfig?

    The files contained inside the TAR archive are:
    Code:
    -rw-r--r-- 1 1000 1000  8519 29 ago  2007 CHANGES
    -rw-r--r-- 1 1000 1000 17976 29 ago  2007 COPYING
    -rwxr-xr-x 1 1000 1000  6898 29 ago  2007 mailgraph.cgi --------> /var/www/web2/cgi-bin/
    -rw-r--r-- 1 1000 1000   672 29 ago  2007 mailgraph.css
    -rw-r--r-- 1 1000 1000   777 29 ago  2007 mailgraph-init  -------> ???
    -rwxr-xr-x 1 1000 1000 29230 29 ago  2007 mailgraph.pl  -------> ???
    -rw-r--r-- 1 1000 1000  2683 29 ago  2007 README
    
     
    Last edited: Dec 4, 2009
  7. Mark_NL

    Mark_NL Member

    No, we're not going to use the cgi part of the script .. the cgi part is for when you want to view the stats in an image created by the cgi script (we don't want that, we want postfix to do it, so skip that)

    I've updated my previous post to make things more clear.
     
  8. vaio1

    vaio1 Member

    This command doesn't exist in CentOS: update-rc.d mailgraph defaults

    Other steps to do are:

    1. chmod 777 /etc/init.d/mailgraph
    2. /etc/init.d/mailgraph start

    Furthermore I get this message from CACTI:

    Code:
    12/04/2009 04:05:02 PM - CMDPHP: Poller[0] Host[1] DS[22] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mailv
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[21] SNMP: v3: 127.0.0.1, dsname: spam, oid: .1.3.6.1.4.1.2021.8.1.101.5, output: U
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[21] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mails
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[20] SNMP: v3: 127.0.0.1, dsname: send, oid: .1.3.6.1.4.1.2021.8.1.101.1, output: U
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[20] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mails
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[19] SNMP: v3: 127.0.0.1, dsname: reject, oid: .1.3.6.1.4.1.2021.8.1.101.3, output: U
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[19] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mailr
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[18] SNMP: v3: 127.0.0.1, dsname: recv, oid: .1.3.6.1.4.1.2021.8.1.101.2, output: U
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[18] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mailr
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[17] SNMP: v3: 127.0.0.1, dsname: bounced, oid: .1.3.6.1.4.1.2021.8.1.101.4, output: U
    12/04/2009 04:05:01 PM - CMDPHP: Poller[0] Host[1] DS[17] WARNING: Result from SNMP not valid. Partial Result: /bin/cat: /tmp/mailb 
    
     
    Last edited: Dec 4, 2009
  9. Mark_NL

    Mark_NL Member

    did you edit snmpd.conf? and restarted snmpd?


    run: /bin/cat /tmp/mailsent

    that does is return?
     
  10. vaio1

    vaio1 Member

    yes of course.
    I have restarted it after the edit.
     
  11. Mark_NL

    Mark_NL Member

    Is mailgraph running? (ps flax | grep mailgraph)

    Do the following files exist?

    /tmp/mailsent
    /tmp/mailrecv
    /tmp/mailrejected
    /tmp/mailbounced
    /tmp/mailspam
    /tmp/mailvirus
     
  12. vaio1

    vaio1 Member

    Code:
    #ps flax | grep mailgraph
    0     0  7925  7825  15   0   3940   720 pipe_w S+   pts/1      0:00          \_ grep mailgraph
    
    There are not any of these file in the /tmp

    /tmp/mailsent
    /tmp/mailrecv
    /tmp/mailrejected
    /tmp/mailbounced
    /tmp/mailspam
    /tmp/mailvirus
     
  13. Mark_NL

    Mark_NL Member

    Mailgraph is not running .. mailgraph creates those files ..

    Code:
    /etc/init.d/mailgraph start
    edit: if it won't start .. run

    /usr/local/bin/mailgraph.pl -l /var/log/syslog -d

    and see if you get errors
     
  14. vaio1

    vaio1 Member

    Code:
    # /etc/init.d/mailgraph start
    Starting mail statistics grapher: mailgraph
    
    Code:
    # ps flax | grep mailgraph
    0     0  8248  7825  15   0   3940   724 stext  S+   pts/1      0:00          \_ grep mailgraph
    
    No file has been created yet.
     
  15. Mark_NL

    Mark_NL Member

    read, what i typed in my previous post (below the init cmd)
     
  16. vaio1

    vaio1 Member

    executing /usr/local/bin/mailgraph.pl -l /var/log/syslog -d I don't get any result.
     
  17. Mark_NL

    Mark_NL Member

    I assume perl is installed on your machine:
    perl -MCPAN -e 'install File::Tail'

    you can also install "strace" and run:

    Code:
    strace /etc/init.d/mailgraph start
    and see what errors you get.

    (last reply, i'll help you further on monday, cya!)
     
  18. vaio1

    vaio1 Member

    Thanks for the help ... but maybe we can see again on monday :(

    Code:
    # perl -MCPAN -e 'install File::Tail'
    CPAN: Storable loaded ok
    Going to read /root/.cpan/Metadata
      Database was generated on Fri, 04 Dec 2009 00:39:45 GMT
    File::Tail is up to date.
    
    Code:
    # strace /etc/init.d/mailgraph start
    execve("/etc/init.d/mailgraph", ["/etc/init.d/mailgraph", "start"], [/* 21 vars */]) = 0
    brk(0)                                  = 0x916c000
    access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY)      = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=44205, ...}) = 0
    mmap2(NULL, 44205, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f97000
    close(3)                                = 0
    open("/lib/libtermcap.so.2", O_RDONLY)  = 3
    read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320J\274\0004\0\0\0"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0755, st_size=13084, ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f96000
    mmap2(0xbc4000, 14568, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xbc4000
    mmap2(0xbc7000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2) = 0xbc7000
    close(3)                                = 0
    open("/lib/libdl.so.2", O_RDONLY)       = 3
    read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0PZ\271\0004\0\0\0"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0755, st_size=16428, ...}) = 0
    mmap2(0xb95000, 12408, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb95000
    mmap2(0xb97000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xb97000
    close(3)                                = 0
    open("/lib/libc.so.6", O_RDONLY)        = 3
    read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340?\246\0004\0\0\0"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0755, st_size=1611564, ...}) = 0
    mmap2(0xa4e000, 1328580, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xa4e000
    mmap2(0xb8d000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13f) = 0xb8d000
    mmap2(0xb90000, 9668, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb90000
    close(3)                                = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f95000
    set_thread_area({entry_number:-1 -> 6, base_addr:0xb7f956c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
    mprotect(0xb97000, 4096, PROT_READ)     = 0
    mprotect(0xb8d000, 8192, PROT_READ)     = 0
    mprotect(0xa45000, 4096, PROT_READ)     = 0
    munmap(0xb7f97000, 44205)               = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    open("/dev/tty", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3
    close(3)                                = 0
    brk(0)                                  = 0x916c000
    brk(0x918d000)                          = 0x918d000
    open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=56438480, ...}) = 0
    mmap2(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7d95000
    close(3)                                = 0
    getuid32()                              = 0
    getgid32()                              = 0
    geteuid32()                             = 0
    getegid32()                             = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    time(NULL)                              = 1259943853
    open("/proc/meminfo", O_RDONLY)         = 3
    fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fa1000
    read(3, "MemTotal:      4145344 kB\nMemFre"..., 4096) = 771
    close(3)                                = 0
    munmap(0xb7fa1000, 4096)                = 0
    rt_sigaction(SIGCHLD, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigaction(SIGCHLD, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigaction(SIGINT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigaction(SIGINT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigaction(SIGQUIT, {0x1, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    uname({sys="Linux", node="server.software.com", ...}) = 0
    stat64("/root", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
    stat64(".", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
    getpid()                                = 13475
    open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=25462, ...}) = 0
    mmap2(NULL, 25462, PROT_READ, MAP_SHARED, 3, 0) = 0xb7f9b000
    close(3)                                = 0
    getppid()                               = 13474
    getpgrp()                               = 13474
    rt_sigaction(SIGCHLD, {0x807aa60, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    open("/etc/init.d/mailgraph", O_RDONLY|O_LARGEFILE) = 3
    ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfc6d3c8) = -1 ENOTTY (Inappropriate ioctl for device)
    _llseek(3, 0, [0], SEEK_CUR)            = 0
    read(3, "#!/bin/sh\n\n# $Id: mailgraph-init"..., 80) = 80
    _llseek(3, 0, [0], SEEK_SET)            = 0
    getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=1024}) = 0
    dup2(3, 255)                            = 255
    close(3)                                = 0
    fcntl64(255, F_SETFD, FD_CLOEXEC)       = 0
    fcntl64(255, F_GETFL)                   = 0x8000 (flags O_RDONLY|O_LARGEFILE)
    fstat64(255, {st_mode=S_IFREG|0777, st_size=777, ...}) = 0
    _llseek(255, 0, [0], SEEK_CUR)          = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    read(255, "#!/bin/sh\n\n# $Id: mailgraph-init"..., 777) = 777
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f9a000
    write(1, "Starting mail statistics grapher"..., 44Starting mail statistics grapher: mailgraph
    ) = 44
    stat64(".", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
    stat64("/bin/nice", {st_mode=S_IFREG|0755, st_size=20856, ...}) = 0
    access("/bin/nice", X_OK)               = 0
    access("/bin/nice", R_OK)               = 0
    stat64("/bin/nice", {st_mode=S_IFREG|0755, st_size=20856, ...}) = 0
    access("/bin/nice", X_OK)               = 0
    access("/bin/nice", R_OK)               = 0
    rt_sigprocmask(SIG_BLOCK, [INT CHLD], [], 8) = 0
    _llseek(255, -7, [770], SEEK_CUR)       = 0
    clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7f95708) = 13476
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
    rt_sigaction(SIGINT, {0x807b610, [], 0}, {SIG_DFL, [], 0}, 8) = 0
    waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13476
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    --- SIGCHLD (Child exited) @ 0 (0) ---
    waitpid(-1, 0xbfc6cca8, WNOHANG)        = -1 ECHILD (No child processes)
    sigreturn()                             = ? (mask now [])
    rt_sigaction(SIGINT, {SIG_DFL, [], 0}, {0x807b610, [], 0}, 8) = 0
    rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
    read(255, "exit 0\n", 777)              = 7
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    exit_group(0)                           = ?
    
    
     
  19. Mark_NL

    Mark_NL Member

    Back on the job, so let's see ..it's not perl, .. mailgraph uses rrdtool, but WE are not using it, so we might want to check if rrdtool is installed (it's still needed for cacti, so you need it indeed).

    check:
    Code:
    which rrdtool
     
  20. vaio1

    vaio1 Member

    Hi Mark!

    Code:
    # which rrdtool
    /usr/bin/rrdtool
    
    thanks for your kindly help
     

Share This Page