-
Notifications
You must be signed in to change notification settings - Fork 0
/
zimbralicreport
executable file
·82 lines (67 loc) · 2 KB
/
zimbralicreport
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
#!/usr/bin/env perl
# Copyright (c) 2023 by Manuel Oetiker. All rights reserved
use strict;
use warnings;
my %replacements = (
'BE' => 'Business_Email',
'PE' => 'Professional_Edition',
'SE' => 'Standard_Edition'
);
sub fix {
my $string = shift;
$string =~ s/Business_Email/BusiEmail/g;
$string =~ s/Professional_Edition/ProfEmail/g;
$string =~ s/Standard_Edition/StandEmail/g;
return $string
}
my $newest_file;
my @files = glob("/opt/zurt/data/mailbox*");
@files = sort { -M $a <=> -M $b } @files;
if (!@files) {
print "3 \"Zimbra Licenses\" - No license statistic file found\n";
exit;
}
open my $file, '<', $files[0] or die "Could not open file: $!";
my $header = <$file>;
my %count_name_lictype_domain;
my %count_name_lictype;
my %all_lictypes;
while (<$file>) {
chomp;
my @columns = split ',';
my $domains = $columns[1];
my $lictype = $columns[2];
$lictype = $replacements{$lictype} if exists $replacements{$lictype};
$count_name_lictype_domain{$domains}{$lictype}++;
$count_name_lictype{$lictype}++;
$all_lictypes{$lictype} = 1; # Collect all unique license types
}
close $file;
foreach my $domains (keys %count_name_lictype_domain) {
print "0 \"Zimbra Licences $domains\" ";
my @count;
my @comment;
foreach my $lictype (keys %all_lictypes) {
my $count_lictype = $count_name_lictype_domain{$domains}{$lictype} || 0;
push @count,"$lictype=$count_lictype";
my $lictype_short = fix $lictype;
push @comment,"$lictype_short->$count_lictype";
}
print join("|",@count);
print " ";
print join(", ",@comment);
print "\n";
}
print "0 \"Zimbra Licences Summary\" ";
my @count;
my @comment;
foreach my $lictype (keys %all_lictypes) {
my $count_lictype = $count_name_lictype{$lictype} || 0;
push @count,"$lictype=$count_lictype";
my $lictype_short = fix $lictype;
push @comment,"$lictype_short->$count_lictype";
}
print join("|",@count);
print " ";
print join(", ",@comment);
print "\n";