#!C:\Perl\bin\perl.exe use strict; use warnings; # # This script is created to put the servers # in unplanned outage as part of the tasks that # are received to stop the monitoring on the servers # due to some maintenance activity on the servers. # my $path = 'E:/Temp/INYROHS/'; require $path.'omwNodeDetails.pm'; # expect values 'on|off' my $maintMode = lc $ARGV[0] || ''; chomp($maintMode); unless ($maintMode =~ /^(on|off)$/){ die "Invalid mode $maintMode\n"; } # date/time my ($SEC,$MIN,$HOUR, $DAY, $MON, $YEAR)= (localtime) [0..6]; my $date = sprintf "%04d_%02d_%02d",$YEAR+1900,$MON+1,$DAY; my $time = sprintf "%02d:%02d:%02d",$HOUR,$MIN,$SEC; # log file my $logfile = $path . "maintenanceMode_$date.log"; open (LOG,'>>',$logfile) or die "Can't open LOG '$logfile': $!\n"; printLog ("\n=================== Date is $date Time is $time Starting the maintenance mode process to turn $maintMode outages."); # server file my $serverlist = $path.'serverlist.txt'; open( SRV,'<',$serverlist) or die "Can't open SVR '$serverlist': $!"; my @nodes = (); while (){ # skip blank lines s/\s+$//; s/^\s+//; next if /^$/; # validate records if (/.+/){ # change to suit push @nodes,$_; } else { printLog("ERROR Invalid record '$_'"); } } # check serverlist had entries if (@nodes == 0){ printLog("ERROR No nodes found in $serverlist"); exit; } # process each node for my $NODE (@nodes){ my ($hostname) = split /\./, $NODE; my $fqdn = getNodeAttributes($hostname,'PrimaryNodeName'); # catch errors #unless ($fqdn =~/pattern/){ #printLog ("ERROR : Invalid fqdn '$fqdn' from '$hostname'"); #next; #} # command common to on/off my $cmd = "ovownodeutil.cmd -outage_node -unplanned -disable_heartbeat -delete_msgs -node_name $fqdn -$maintMode "; printLog("Node $hostname >>> $maintMode"); # on command or off commands if ( $maintMode eq 'on' ){ printLog($cmd); #`$cmd`; } elsif( $maintMode eq 'off' ){ printLog("Bringing the server $NODE out of outage."); my $cmdresopcmona="ovdeploy -cmd \"ovc -restart opcmona\" -host $fqdn"; my $cmdresopcle ="ovdeploy -cmd \"ovc -restart opcle\" -host $fqdn"; printLog($cmd); #`$cmd`; printLog($cmdresopcmona); #`$cmdresopcmona`; printLog($cmdresopcle); #`$cmdresopcle`; } printLog("done with command\n"); } # clear serverlist printLog ("Truncating $serverlist"); open( SRV,'>',$serverlist) or die "Can't open SRV '$serverlist': $!"; close SRV; # end close LOG; # screen and log sub printLog { my ($logLine) = @_; my $now = sprintf "%02d:%02d:%02d",(localtime)[2,1,0]; print "$logLine\n"; print LOG "$now $logLine\n"; }