Files
scripts-conlxsyslog03/conetadm/rvtools/check.pl
conetadm 5718e70f15 init
2024-11-14 21:11:06 +01:00

88 lines
2.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);
} else {
$ret+=2;
}
foreach ( sort keys %vmhostds) {
if ($vmhostds{$_}->{esx}->{dc} ne $vmhostds{$_}->{ds}->{dc}) {
# Ãrspringe Hosts deren Datastore "images" oder "tso_install" ist
next if ($vmhostds{$_}->{ds}->{datastore} eq "images" );
next if ($vmhostds{$_}->{ds}->{datastore} eq "tso_install" );
# Ãrspringe bestimmte Hostnamen
next if ($_ eq "tsoltlxlomd");
next if ($_ eq "tsoltlxlomu");
next if ($_ eq "tsolwebfeu");
next if ($_ eq "tsolwservicesd");
next if ($_ eq "tsolwservicesu");
# Ãrspringe VMs deren Name ... enthä
next if ($_ =~ /BOW/);
next if ($_ =~ /CTX/);
# 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;
printf "%-25s %-25s (%-3s) %-20s (%-3s)\n", $_, $vmhostds{$_}->{esx}->{hostname}, $vmhostds{$_}->{esx}->{dc}, $vmhostds{$_}->{ds}->{datastore}, $vmhostds{$_}->{ds}->{dc};
}
}
$ret=$ret + $addret;
print "Verteilung nicht ok\n" if ($ret & 1);
print "RVTools Datei nicht vorhanden\n" if ($ret & 2);
print "Es ist Montag\n" if ($ret & 4);
print "RET=$ret\n";
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;
}