-
Notifications
You must be signed in to change notification settings - Fork 1
/
zmzcoreport
executable file
·112 lines (97 loc) · 3.79 KB
/
zmzcoreport
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/perl
# Report the versions of the Zimbra Connector for Outlook currently in use
# based on the Zimbra mailbox.log file(s).
#
# This script will report a space separated list of login date, name and
# address, the ZCO versioni, and the most recent date this version wasi
# used and where this entry can be found in the log file.
#
# All versions should also be reported as "[unauthorized]" due to the fact
# that the username won't be available until after the user was logged in
# (use fgrep if you want to skip these lines).
#
# It accepts an optional first parameter to specify the location of the
# log file(s).
#
# Please be patient when running this script.
#
#
# Copyright (c) 2013, Silpion IT-Solutions GmbH <http://www.silpion.de>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use 5.010;
use strict;
use warnings;
use Data::Dumper;
my $logdir = $ARGV[0] || '/opt/zimbra/log';
die "Log directory '$logdir' not found" unless -d $logdir;
my $debug = 0;
$| = $debug;
my $data = {};
foreach my $logfile ("$logdir/mailbox.log", reverse sort glob "$logdir/mailbox.log.*.gz") {
print "$logfile\n" if $debug & 1;
print "+" if $debug & 2;
my $fh;
if ($logfile =~ /\.gz$/) {
open($fh, "-|", "gunzip -c $logfile") or die "Could not gunzip '$logfile': $!";
}
else {
open($fh, "<", $logfile) or die "Could not open '$logfile': $!";
}
my $lineno = 0;
foreach my $line (<$fh>) {
$lineno++;
chomp($line);
next unless $line;
my @line = split(/ +\[?/, $line, 4);
push(@line, split(/\] +\[/, pop(@line), 2));
push(@line, split(/\]? +(?:- +)?/, pop(@line), 3));
my $date = join('', split(/-/, $line[0]));
next unless $date =~ /^20[0-9]{6}$/;
my %attrs = split(/[;=]/, $line[4]);
my($ua, $version) = split(qr(/), ($attrs{ua} || 'undef/undef'), 2);
next unless $ua eq 'ZimbraConnectorForOutlook';
my $user = $attrs{aname} || $attrs{name} || '[unauthenticated]';
$data->{$user}->{$version} ||= { date => 0 };
if ($data->{$user}->{$version}->{date} <= $date) {
$data->{$user}->{$version} = {
date => $date,
addr => $attrs{'ip'} || '[unknown]',
file => $logfile,
line => $lineno,
};
}
print "." if $debug & 2;
}
}
print "\n" if $debug & 2;
foreach my $user (sort keys %{$data}) {
foreach my $version (sort keys %{$data->{$user}}) {
print(join(" ",
$user,
$version,
$data->{$user}->{$version}->{date},
$data->{$user}->{$version}->{addr},
$data->{$user}->{$version}->{file} . ":" . $data->{$user}->{$version}->{line},
) . "\n");
}
}