114 lines
3.3 KiB
Perl
Executable File
114 lines
3.3 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
my %esxrz;
|
|
my %storagerz;
|
|
my %vmhostds;
|
|
|
|
my $addret=0;
|
|
my $ret=0;
|
|
# Fehler Flags MFD
|
|
# M: Montag
|
|
# F: File von RVTools nicht aktuell
|
|
# D: Datastore Verteilung nicht ok
|
|
|
|
my $M=`date +'%u'`;
|
|
$ret+=4 if ($M == "1");
|
|
|
|
read_csv ("esx-rz.csv", \%esxrz);
|
|
read_csv ("storage-rz.csv", \%storagerz);
|
|
if ( -e "VMsHostsDatastores.csv" ) {
|
|
read_csv2 ("VMsHostsDatastores.csv", \%vmhostds, \%esxrz, \%storagerz);
|
|
`cp VMsHostsDatastores.csv VMsHostsDatastores.last.csv`;
|
|
} else {
|
|
$ret+=2;
|
|
}
|
|
|
|
open OUT, ">output.html";
|
|
printf OUT "<html><body><p style=font-family:'Courier New'><br>\n";
|
|
printf OUT "Montags gibt's die Mail unabhängig vom Ergebnis der Prüfung.<br>\n" if ($ret & 4);
|
|
printf OUT "Die Prüfung kann nicht durchgeführt werden. Die Datei aus den RVTools fehlt.<br>\n" if ($ret & 2);
|
|
|
|
foreach ( sort keys %vmhostds) {
|
|
if ($vmhostds{$_}->{esx}->{dc} ne $vmhostds{$_}->{ds}->{dc}) {
|
|
|
|
# Üerspringe Hosts deren Datastore "images" oder "tso_install" ist
|
|
next if ($vmhostds{$_}->{ds}->{datastore} eq "images" );
|
|
next if ($vmhostds{$_}->{ds}->{datastore} eq "tso_install" );
|
|
|
|
# Üerspringe bestimmte Hostnamen
|
|
next if ($_ eq "tsoltlxlomd");
|
|
next if ($_ eq "tsoltlxlomu");
|
|
next if ($_ eq "tsolwebfeu");
|
|
next if ($_ eq "tsolwservicesd");
|
|
next if ($_ eq "tsolwservicesu");
|
|
|
|
# Üerspringe VMs deren Name ... enthä
|
|
next if ($_ =~ /BOW/);
|
|
next if ($_ =~ /CTX/);
|
|
next if ($_ =~ /^vCLS-/);
|
|
|
|
# FLW VM in FR4, DS in FR2 ist OK
|
|
next if ($_ =~ /^FLW/ and $vmhostds{$_}->{esx}->{dc} =~ /FR4/ );
|
|
|
|
# ungleiche Verteilung die nicht ignoriert werden kann
|
|
$addret=1;
|
|
my $line = sprintf "%-25s %-25s (%-3s) %-20s (%-3s)<br>\n", $_, $vmhostds{$_}->{esx}->{hostname}, $vmhostds{$_}->{esx}->{dc}, $vmhostds{$_}->{ds}->{datastore}, $vmhostds{$_}->{ds}->{dc};
|
|
$line =~ s/ / /g;
|
|
printf OUT "$line";
|
|
}
|
|
}
|
|
|
|
$ret=$ret + $addret;
|
|
unless ($ret & 2) {
|
|
printf OUT "Keine Unstimmigkeiten in der Verteilung gefunden.<br>\n" unless ($ret & 1);
|
|
}
|
|
|
|
printf OUT "</p></body></html>";
|
|
close OUT;
|
|
|
|
$ret=$ret + $addret;
|
|
|
|
# montag rv file fehlt unstimmigkeiten
|
|
if ( ($ret & 4) or ($ret & 2) or ($ret & 1) ) {
|
|
$pwd=`pwd`; chomp $pwd;
|
|
$usr = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
|
|
$hst=`hostname`; chomp $hst;
|
|
$bsn=`basename $0`; chomp $bsn;
|
|
$scr="$usr\@$hst:$pwd/$bsn";
|
|
`cat output.html | mailx "help\@conet.de" -a 'X-CONET-SRC: $scr' -a "Content-Type: text/html" -s "Mismatch in ESX Datastore Location"`;
|
|
}
|
|
unlink "VMsHostsDatastores.csv";
|
|
|
|
sub read_csv {
|
|
my ($file, $ref_hash) = @_;
|
|
open FILE, "$file" or die $!;
|
|
my $key;
|
|
my $val;
|
|
while (my $line = <FILE>) {
|
|
chomp($line);
|
|
($key, $val) = split /,/, $line;
|
|
$ref_hash->{$key} = $val;
|
|
}
|
|
close FILE;
|
|
}
|
|
|
|
sub read_csv2 {
|
|
my ($file, $ref_hash, $ref_esx, $ref_ds) = @_;
|
|
open FILE, "$file" or die $!;
|
|
my $key;
|
|
my $esx;
|
|
my $ds;
|
|
while (my $line = <FILE>) {
|
|
chomp($line);
|
|
$line =~ s/"//g; $line =~ s/\r//g;
|
|
($key, $esx, $ds) = split /,/, $line;
|
|
$ref_hash->{$key}->{esx}->{hostname} = $esx;
|
|
$ref_hash->{$key}->{esx}->{dc} = $ref_esx->{$esx};
|
|
|
|
$ref_hash->{$key}->{ds}->{datastore} = $ds;
|
|
$ref_hash->{$key}->{ds}->{dc} = $ref_ds->{$ds};
|
|
}
|
|
close FILE;
|
|
}
|
|
|