use strict; use Net::Ping; no strict 'refs'; ######################################################################### ################# Constants (Global) ################################### ######################################################################### my $outputlog = "tkisclustercheck.log"; my $tracelog = "tkisclustertrace.log"; my $autolog = "tkisclusterauto.log"; my $REM_SH = "ssh"; my $LSMOD = "/sbin/lsmod"; my @out; my $SYSCTL = '/etc/sysctl.conf'; my $KERNEL_VALUE = 524288; my $SSHD = "/usr/sbin/sshd"; my $SHELL = "tcsh"; my @nodes = map {$ENV{$_->[0]}}sort {$a->[1] <=> $b->[1]}map { [ $_,m/(\d+)$/]}grep {/^MULTI_NODE\d+$/}keys %ENV; my @private = map {$ENV{$_->[0]}}sort {$a->[1] <=> $b->[1]}map { [ $_,m/(\d+)$/]}grep {/^PRIVATE_NODE\d+$/}keys %ENV; my @vips = map {$ENV{$_->[0]}}sort {$a->[1] <=> $b->[1]}map { [ $_,m/(\d+)$/]}grep {/^VIP_NODE\d+$/}keys %ENV; @nodes = map {(split/\./)[0]}@nodes; ######################################################################### ########## Create output and trace log and duplicate the Handle ######### ######################################################################### open (CLUSTER, ">$outputlog") or die "Unable to open the file $outputlog : $!\n"; open (AUTO, ">$autolog") or die "Unable to open the file $autolog : $!\n"; open (TRACE,">$tracelog") or die "Unable to open the file $tracelog : $!\n"; local *STDOUT = *TRACE; open( STDERR, ">>&STDOUT"); my $HANDLE = "CLUSTER"; ######################################################################### ############### Lookup Checks for all the Node values ################### ######################################################################### &exec_cmd( "code" => ["lookup"] ); ######################################################################### ##################### Kernel Parameters ################################# ######################################################################### &exec_cmd( "header"=> "Checking Kernel Parameters", "cmd" => "cat $SYSCTL", "code" => ["kernel"], "nodes" => \@nodes, "keep_track" => 1 ); ######################################################################### ################# Check ssh run status ##### ########################### ######################################################################### &exec_cmd( "header" => "Checking the sshd availability", "cmd" => "ps -efw | egrep $SSHD | grep -v grep", printm => 1, "nodes" => \@nodes, "code" => ["sshd"], keep_track => 1 ); ######################################################################### ##################### Check the Shell ################################## ######################################################################### &exec_cmd( "header" => "Checking the shell type", cmd => "env | egrep SHELL", printm => 1, "nodes"=> \@nodes, keep_track => 1, code => ["shell"] ); &exec_cmd( header => "Checking Public/Private address entries", "code" => ["ifconfig"], nodes => \@nodes, keep_track => 1, cmd => "$IFCONFIG" ); close (TRACE); close (CLUSTER); close (AUTO); ######################################################################### ##################### Core Handler(subroutine Driver) ################### ######################################################################### sub exec_cmd { my %hash = @_; $hash{nodes}->[0] = 1 unless (defined $hash{nodes});#For standalone subs print $HANDLE "\n"; my @keep_track; print $HANDLE "\n$hash{header}\n" if (defined $hash{header}); #Prints Header foreach my $n (@{$hash{nodes}}) { if (defined $hash{header}) { print TRACE "\n$hash{header} in node $n\n"; } if (defined $hash{cmd}){ @out = `$REM_SH $n $hash{cmd}`; #Command Execution } if (defined $hash{code}){ ##Pass Node Info to callback subroutine ## if (defined $hash{keep_track}) { push @keep_track, $hash{code}->[0]->($n); } else { ## Pass args from code block ### my $cnt = scalar @{$hash{code}}; $hash{code}->[0]->(@{$hash{code}}[1..$cnt-1] ); } } if ($hash{printm} == 1){ print TRACE @out; #Details of the command o/p } } if (defined $hash{keep_track}) { #General Tracker for combo pass/fail status my $pass = (grep {not $_}@keep_track)?"FAILED":"PASSED"; print $HANDLE "\nTEST $pass\n"; } @keep_track = (); #Resetting tracking value return; } ######################################################################### #################### Utility subroutines ################################ ######################################################################### sub lookup { print $_ "Checking nslookup values for all the nodes\n" for ("$HANDLE", "TRACE"); eval { # Escape from dying print TRACE map {"Nslookup value for $_ is ".&nslookup($_)."\n"} (@nodes,@private,@vips); my @dns = grep {not defined &nslookup($_) } (@nodes,@private,@vips); if (@dns) { my $dns = join ':',@dns; print $HANDLE "The following nodes doesn't have nslookup configured properly: $dns\n"; print $HANDLE "TEST FAILED\n"; } else { print $HANDLE "\nTEST PASSED\n"; } }; print TRACE "The Failure is due to $@\n" if ($@); } sub kernel { my $n = shift; return 0 unless (@out); my @kernel = grep {/net.core.[rw]mem_(max|default)/i && !/^#/} @out; my $fail = join $/, sort @kernel; print TRACE $/,$fail,$/; my $kernel = (grep { !/^$KERNEL_VALUE$/}map{m/(\d+)/}@kernel)?0:1; print TRACE "Node $n is having:\n$fail\n" unless ($kernel); return $kernel; } sub sshd { my $n = shift; my $pass = (grep {/$SSHD/i}@out)?1:0; print TRACE "Node $n is not having sshd running in it\n" unless ($pass); return $pass; } sub shell { my $n = shift; my $pass = (grep {/$SHELL/i}@out)?1:0; print TRACE "Node $n is not having the $SHELL in it\n" unless ($pass); return $pass; } sub ifconfig { my $n = shift; return 0 unless (@out); my $value; { local $"; $value = "@out" }; my %ifconfig; my @ifc = split/\n\n/,$value; foreach my $i (@ifc) { chomp $i; my ($eth) = $i =~/^(\S+)/i; my ($addr) = $i =~/inet addr:\s*(\S+)/i; my ($mask) = $i =~/Mask:\s*(\S+)/i; $ifconfig{$addr} = [$eth,$mask]; } my ($pos) = grep {lc($nodes[$_]) eq lc($n)}(0..$#nodes); my ($public,$private) = ($nodes[$pos],$private[$pos]); my ($pub_ip, $pub_sub_eth, $priv_ip,$pubmask,$priv_sub_eth,$privmask); eval { $pub_ip = &nslookup($public); ($pub_sub_eth,$pubmask)=@{$ifconfig{$pub_ip}}; ($priv_ip) = &nslookup($private); ($priv_sub_eth,$privmask)=@{$ifconfig{$priv_ip}}; }; print TRACE "The subethernet value for Primary node is: $pub_sub_eth\n"; print TRACE "The Mask Value for Primary node is: $pubmask\n"; print TRACE "The subethernet value for Private node is: $priv_sub_eth\n"; print TRACE "The Mask Value for Private node is: $privmask\n"; my $pass = (grep {not exists $ifconfig{$_}} ($pub_ip,$priv_ip))?0:1; print TRACE "Node $n doesnot have Public/Private address in ifconfig\n" unless ($pass); return $pass; }