Results 1 to 4 of 4

Thread: Get sent and received messages count per user, per month

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    46
    Rep Power
    5

    Default Get sent and received messages count per user, per month

    Hi All!

    Maybe you know a tool which helps me to find statistics per user with count of sent and received messages.
    Director wants to see activity of users from some department per month - Jan, Feb, etc...

    zmmsgtrace can't help me because a log rotate.

  2. #2
    Join Date
    Dec 2009
    Location
    Michigan
    Posts
    454
    Rep Power
    6

    Default

    This is the script I use:

    Code:
    #!/bin/bash
    
    # ------------
    # Set up paths
    # ------------
    
    PATH=/opt/zimbra/bin:/opt/zimbra/postfix/sbin:/opt/zimbra/openldap/bin:/opt/zimbra/snmp/bin:/opt/zimbra/bdb/bin:/opt/zimbra/openssl/bin:/opt/zimbra/java/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    
    # --------------------
    # Initialize variables
    # --------------------
    
    workdir=/home/doug/work
    month=`date +%b`
    today=`date +%e`
    day=`date --date=yesterday +%e`
    year=`date +%Y`
    address_source=$1
    
    
    # -------------------------------------
    # If 1st day of the month, set month to
    # the previous month.  If it's the first
    # of the year and first day of the month
    # set year to the previous year
    # --------------------------------------
    
    if [ "$month" == "Jan" ]
    then
        echo "Month was hit"
        if [ "$today" == " 1" ] 
        then
    
            month=`date --date=yesterday +%b`
    	year=`date --date=yesterday +%Y`
    
        fi
    
            else
    
        if [ "$today" == " 1" ] 
        then
            month=`date --date=yesterday +%b`
        fi
    fi
    
    # -----------------
    # Send to addresses
    # -----------------
    
    case "$2" in
    
        'manager1')
    	    send_to="jdoud@fakedomain.com"
    	    ;;
    
        'manager2')
    	    send_to="amaurer@fakedomain.com"
    	    ;;
    	    
        'manager3')
    	    send_to="c_crangbo@fakedomain.com"
    	    ;;
    
        'mytesting')	
    	    send_to="dlytle@fakedomain.com"
    	    ;;
    
        'manager4')	
    	    send_to="jdavis@fakedomain.com"
    	    ;;
    
    esac
    
    # --------------------
    # Create email headers
    # --------------------
    
    echo "to:$send_to" >$workdir/report.$address_source.txt
    echo "from:summary@fakedomain.com" >>$workdir/report.$address_source.txt
    echo "subject:Account Activity Summary" >>$workdir/report.$address_source.txt
    
    # ------------------
    # Creates the report
    # ------------------
    
    echo " " >>$workdir/report.$address_source.txt
    echo "Account activity summary report				  `date +%m/%d/%Y`" >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    echo "Program name: mail_summary.sh" >>$workdir/report.$address_source.txt
    echo "Server: 10.0.0.12"  >>$workdir/report.$address_source.txt
    echo "Date created: 2012.05.25"  >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    echo "Date for query: $month $day, $year"  >>$workdir/report.$address_source.txt
    echo "____________________________________________________________________" >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    
    # ------------------------------
    # Scan logs, yesterday and today
    # for matches, count and total
    # ------------------------------
    
    while read addresses
    do
    
        accounts_listed=`expr $accounts_listed + 1`
    
        log1_received=`cat /var/log/mail.info.1|grep -i "$month $day"|grep -i "to=<$addresses>"|wc -l`
        log1_sent=`cat /var/log/mail.info.1|grep -i "$month $day"|grep -i "from=<$addresses>"|wc -l`
    
        log2_received=`cat /var/log/mail.info|grep -i "$month $day"|grep -i "to=<$addresses>"|wc -l`
        log2_sent=`cat /var/log/mail.info|grep -i "$month $day"|grep -i "from=<$addresses>"|wc -l`
    
        received=`expr $log1_received + $log2_received`
        sent=`expr $log1_sent + $log2_sent`
    
    # ----------------------------
    # Keep the length of the count
    # at 3 digits in length for
    # report layout
    # ---------------------------
    
        received_length=`expr length $received`
        sent_length=`expr length $sent`
    
        if [ $received_length ==  1 ]
        then 
    	received=00$received
        fi
    
        if [ $received_length ==  2 ]
        then 
    	received=0$received
        fi
    
        if [ $sent_length ==  1 ]
        then 
    	sent=00$sent
        fi
    
        if [ $sent_length ==  2 ]
        then 
    	sent=0$sent
        fi
    
    # ------------------------------
    # echo the results to the report
    # ------------------------------
    
    echo "Mail Received:  "$received -- "Sent: "$sent -- "E-Mail: "$addresses >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    
    done </home/doug/work/$address_source
    
    echo " " >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    echo "Total accounts in this summary: "$accounts_listed  >>$workdir/report.$address_source.txt
    echo " " >>$workdir/report.$address_source.txt
    
    
    # ------------------
    # Send out the email
    # ------------------
    
    /opt/zimbra/postfix/sbin/sendmail -t </$workdir/report.$address_source.txt
    I keep a list of email addresses for each manager in my work directory. 1 email address per line. The script is called once a day from CRON with:

    Code:
    /usr/local/bin/mail_summary.sh manager.address.list manager1 2>&1
    Just a note; if for some reason, Zimbra isn't able to deliver a message and it retries for up to 5 days, each subsequent try will increase the count for the sending email address.

    Doug
    Ben Franklin quote:

    "Those who would give up Essential Liberty to purchase a little Temporary Safety, deserve neither Liberty nor Safety."

  3. #3
    Join Date
    Dec 2009
    Posts
    46
    Rep Power
    5

    Default

    Thank you for sharing your scripts.

    As I understand right, this is solutions will works only with new items in logfile - and not from begining of the year (2013) because there are no logs older one month.

    I have Exim as MTA infront Zimbra and with Exilog can get needed info from DB but without internal messaging on Zimbrа.

  4. #4
    phoenix is offline Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,587
    Rep Power
    58

    Default

    Quote Originally Posted by blessendor View Post
    As I understand right, this is solutions will works only with new items in logfile - and not from begining of the year (2013) because there are no logs older one month.
    Why don't you install a central syslog server and forward the log files to that. You can use a syslog server that has MySQl as it's database and get the needed reports from that or you can install Splunk (there is a free version) and work some magic with it's reporting tools/features.
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

Similar Threads

  1. Replies: 6
    Last Post: 07-09-2013, 04:21 PM
  2. get a random sample of user account growth by month
    By anthonyclark in forum Developers
    Replies: 1
    Last Post: 10-10-2009, 10:36 PM
  3. Replies: 0
    Last Post: 09-11-2009, 07:50 PM
  4. draft messages mailbox count is off by one
    By phingers in forum Administrators
    Replies: 1
    Last Post: 07-18-2009, 08:03 AM
  5. How to figure out total messages received per month
    By colin7151 in forum Administrators
    Replies: 0
    Last Post: 01-18-2008, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •