This repository has been archived by the owner on Jan 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathzimbraCOS-Builder.pl
118 lines (99 loc) · 2.98 KB
/
zimbraCOS-Builder.pl
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
113
114
115
116
117
118
#!/usr/bin/perl
use strict;
use warnings;
#
# Keith McDermott (keithmcd@purdue.edu)
# 2014-02-03
#
# This script is designed to print out a chart showing all zimbra COS and which servers are associated with each
#
# This script should run from the LDAP master replica in a multi-server install.
#
# Yes, this is a perl script that calls outside apps often. It was the easiest way to interface to Zimbra.
#
# You will need to add your Zimbra mailbox server names as a regex string on line 58 in place of HOSTNAMEREGEX. E.g.: hostname[1-6][0-9]
# You will need to add your Zimbra server names as a regex on line 61 in place of HOSTNAMEWILDCARD. E.g.: hostname.*.domain.com
# If needed, you may want to adjust the printf formatting in the print* subs to better suit your naming convention lengths.
# DEBUGGING: Set to 0 to turn it off, 1 to turn it on
my $DEBUG = 0;
my %HOSTS;
my %COS;
init();
sub init
{
#Set initial code and then begin
getCOS();
getHosts();
printChart();
}
sub getCOS
{
#Get all of the COS in the Zimbra environment
my $tmpCOS = qx(su - zimbra -c "zmprov gac");
foreach my $line (split /[\r\n]+/, $tmpCOS)
{
#Get all the hosts assigned with this specific COS
print "Working with COS: $line\n" if $DEBUG;
#Get a list of all of the hosts in the pool.
# These will be hostId entries.
# Later, we can correlate these to the "friendly" hostnames.
my $hostPool = qx(su - zimbra -c "zmprov gc $line zimbramailhostpool" | grep "zimbraMailHostPool" | cut -d: -f2);
print "Host pool: $hostPool\n" if $DEBUG;
$COS{$line} = $hostPool;
}
}
sub getHosts
{
#Get all of the Zimbra mailbox hosts in the enivronment
my $tmpHosts = qx(su - zimbra -c 'zmprov gas -v -e' | egrep "cn:|zimbraId:" | paste - - | egrep "HOSTNAMEREGEX");
foreach my $line (split /[\n\r]+/, $tmpHosts)
{
my $host = $1 if $line =~ /(HOSTNAMEWILDCARD)/;
my $hostID = $1 if $line =~ /zimbraId: (.*)/;
print "Found: $host, $hostID\n" if $DEBUG;
$HOSTS{$host} = $hostID;
}
}
sub printChart
{
printHeader();
#Iterate through each mailbox server. Print which Zimbra COS it is in
foreach my $host ( sort keys %HOSTS )
{
print "Host: $host ($HOSTS{$host})\n" if $DEBUG;
printf '%-28.27s', $host;
checkHost( $HOSTS{$host} );
print "\n";
}
}
sub printHeader
{
#Obviously, print a header line
printf '%-28.27s', "Hostname";
foreach ( sort keys %COS )
{
printf '%-8.7s', $_;
}
print "\n";
#Next, loop through and print a line
printf '%-28.27s', "------------------------------";
foreach ( keys %COS )
{
printf '%-8.7s', "----------";
}
print "\n";
}
sub checkHost
{
#When given a hostname, cross off which COS that host is in
my $host = shift;
foreach my $cos ( sort keys %COS )
{
print "Parsing $cos...\n" if $DEBUG;
my %hostPool;
foreach my $poolHost ( $COS{$cos} )
{
$poolHost =~ /.*$host.*/ ? printf '%-8.7s',"X" : printf '%-8.7s',"";
}
}
}