#!/usr/bin/perl -w use Data::Dumper; my $debug = 0; #my $debug = 1; my $sudo = ''; $sudo = "sudo " if ($> != 0); chomp(my $hostname = ($#ARGV >= 0) ? $ARGV[0] : `hostname`); my ($autoconfig, $devconfig, $vmglob); $autoconfig = ($#ARGV >= 0) ? "$sudo vmoprcmd -h $hostname -autoconfig -t" : "$sudo tpautoconf -t"; #$devconfig = "$sudo vmoprcmd -h $hostname -devconfig -l | grep drive"; $devconfig = ($#ARGV >= 0) ? "$sudo vmoprcmd -h $hostname -devconfig -d | grep '^ *[0-9]'" : "$sudo tpconfig -d | grep '^ *[0-9]'"; $vmglob = "$sudo vmglob -listall -b | grep -i $hostname | grep '^drive'"; $vmglob_int_consistency = "$sudo vmglob -listall -b | grep '^drive' | grep "; my (%autoconfig_path_by_serial, %autoconfig_serial_by_path); my ($line, $serial, $path); print "Running [$autoconfig]...\n" if $debug; foreach $line (`$autoconfig`) { print $line if ($debug > 2); ($serial, $path) = (split(' ', $line))[4,9]; print "Got [$path][$serial] from autoconfig.\n" if ($debug > 1); $autoconfig_path_by_serial{$serial} = $path; $autoconfig_serial_by_path{$path} = $serial; } my (%devconfig_path_by_name, %devconfig_index_by_name); my ($index, $name); print "Running [$devconfig]...\n" if $debug; foreach $line (`$devconfig`) { print $line if ($debug > 2); ($index, $name, $path) = (split(' ', $line))[0,1,2]; print "Got [$index][$name][$path] from devconfig.\n" if ($debug > 1); if ($path =~ m/^\\/) { print " modified $path " if ($debug > 1); $path =~ s/\\//g; $path =~ s/\.//g; print "to $path\n" if ($debug > 1); } $devconfig_name_by_path{$path} = $name; $devconfig_index_by_path{$path} = $index; } my (%vmglob_name_by_serial, %vmglob_serial_by_name); print "Running [$vmglob]...\n" if $debug; foreach $line (`$vmglob`) { print $line if ($debug > 2); ($name, $serial) = (split(' ', $line))[1,2]; print "Got [$name][$serial] from vmglob.\n" if ($debug >1); $vmglob_name_by_serial{$serial} = $name; $vmglob_serial_by_name{$name} = $serial; } my %driveinfo; foreach $serial (keys %autoconfig_path_by_serial) { $driveinfo{$serial}->{'path'} = $autoconfig_path_by_serial{$serial}; $driveinfo{$serial}->{'name'} = $devconfig_name_by_path{$autoconfig_path_by_serial{$serial}}; $driveinfo{$serial}->{'index'} = $devconfig_index_by_path{$autoconfig_path_by_serial{$serial}}; } print "\nAvailable / configured drives for $hostname:\n\n"; print "drive serial\tindex\tdrive name\tdrive path\n"; foreach $serial (keys %driveinfo) { print "$serial\t", (defined($driveinfo{$serial}->{'index'})) ? "$driveinfo{$serial}->{'index'}\t" : "*NULL*\t", (defined($driveinfo{$serial}->{'name'})) ? "$driveinfo{$serial}->{'name'}\t" : "*NULL*\t\t", "$driveinfo{$serial}->{'path'}\n"; } foreach $path (keys %devconfig_name_by_path) { unless (defined($autoconfig_serial_by_path{$path})) { print "", (defined($vmglob_serial_by_name{$devconfig_name_by_path{$path}})) ? "$vmglob_serial_by_name{$devconfig_name_by_path{$path}}\t" : "*NULL*\t", "$devconfig_index_by_path{$path}\t", "$devconfig_name_by_path{$path}\t", "$path\t", "NOT VISIBLE!\n"; } } my $problems = 0; print "\n\nGlobDB consistency check for $hostname:\n\n"; foreach $serial (keys %driveinfo) { if (defined($driveinfo{$serial}->{'name'}) && (! defined($vmglob_name_by_serial{$serial}) || $vmglob_name_by_serial{$serial} ne $driveinfo{$serial}->{'name'})) { print "Name mismatch for drive serial $serial", "\n autoconfig:\t$driveinfo{$serial}->{'name'}", (defined($vmglob_name_by_serial{$serial})) ? "\n globdb:\t$vmglob_name_by_serial{$serial}" : "\n globdb:\t* MISSING *", "\n"; $problems++; } # if (defined($driveinfo{$serial}->{'name'}) && if (defined($vmglob_serial_by_name{$driveinfo{$serial}->{'name'}}) && $vmglob_serial_by_name{$driveinfo{$serial}->{'name'}} ne $serial) { print "Serial mismatch for drive name $driveinfo{$serial}->{'name'}", "\n autoconfig:\t$serial", "\n glodb:\t$vmglob_serial_by_name{$driveinfo{$serial}->{'name'}}", "\n"; $problems++; } unless (defined($vmglob_name_by_serial{$serial})) { print "Drive serial $serial is NOT in GlobDB for $hostname, ", "but is visible.\n"; $problems++; } } my (%hosts_by_drive_name, %hosts_by_drive_serial, $hname); foreach $serial (keys %vmglob_name_by_serial) { unless (defined($autoconfig_path_by_serial{$serial})) { print "Drive serial $serial is in GlobDB for $hostname, ", "but is NOT visible.\n"; $problems++; } print "Running [$vmglob_int_consistency $serial]...\n" if $debug; foreach $line (`$vmglob_int_consistency "$serial"`) { print $line if ($debug > 2); ($name, $hname) = (split(' ', $line))[1,3]; print "Got [$name][$hname] from vmglob.\n" if ($debug >1); if ($vmglob_name_by_serial{$serial} ne $name && $serial ne "-") { print "Name mismatch between hosts for drive serial $serial", "\n $hostname:\t$vmglob_name_by_serial{$serial}", "\n $hname:\t$name", "\n"; $problems++; } } } foreach $name (keys %vmglob_serial_by_name) { print "Running [$vmglob_int_consistency $name]...\n" if $debug; foreach $line (`$vmglob_int_consistency \' $name \'`) { print $line if ($debug > 2); ($serial, $hname) = (split(' ', $line))[2,3]; print "Got [$serial][$hname] from vmglob.\n" if ($debug >1); if ($vmglob_serial_by_name{$name} ne $serial) { print "Serial mismatch between hosts for drive name $name", "\n $hostname:\t$vmglob_serial_by_name{$name}", "\n $hname:\t$serial", "\n"; $problems++; } } } print "\n$problems problems.", ($problems == 0) ? " Looks fine!\n" : "\n";