File: //opt/OV/newconfig/instrumentation/PostDeployHpcsConfigPolicy.pl
#!/usr/bin/perl
#
###################################################################################
# @(#) PostDeployHpcsConfigPolicy.pl =*=
###################################################################################
#
# The perl script runs after the successful deployment of policy.
# Replaces hpcs.conf configuration file followed by restarting hpsensor
#
###################################################################################
use strict;
use warnings;
use File::Basename;
#
# Constants
#
my $ov_bin_dir = "/opt/OV/bin/";
my $ov_data_dir = "/var/opt/OV/";
my $perf_bin_dir = "/opt/perf/bin/";
my $error_num;
#
# Global Variables
#
my $policy_dir = "$ov_data_dir" . "conf/Performance_Collection_Component/hpsensor/";
my $output;
my $ret_status;
my $fullfilename;
my @platform;
my $logfile;
#
# Set the bin dir location
# Set the data dir location
#
if ($^O eq "aix") {
$ov_bin_dir="/usr/lpp/OV/bin/";
$perf_bin_dir = "/usr/lpp/perf/bin/";
}
# Removing the ov_bin_dir from opcmsg, as it seems that opcmsg is in PATH
# Stale code start
elsif ($^O eq "MSWin32") {
#
# Using opcagt command to determine the PATH
# as Registry.pm is not packaged in perl by OVO.
# This is to be modified to read the registry
# once OVO packages it
#
open($output, "opcagt -type -verbose |") ||
send_opcmsg("DIE","\[OAPCC-PDA-01\] Unable to determine the Install and Data dir of Performance Collection Component. The Post Deployment Policy actions are not performed.");
while(<$output>) {
# chop \n character
chop;
my @fields = split(/=/,$_);
# chop last " character
chop $fields[1];
# chop the first " character
$fields[1] =~ s/^.//;
if ($fields[0] eq "OVO_INSTALLDIR") {
$ov_bin_dir = "$fields[1]" . "bin\\";
$perf_bin_dir = $ov_bin_dir;
}
if ($fields[0] eq "OVO_DATADIR") {
$ov_data_dir = "$fields[1]";
}
}
$policy_dir = "$ov_data_dir" . "conf\\Performance_Collection_Component\\hpsensor\\";
close($output);
}
# Stale code End
#
# Set fullfilename
#
$fullfilename = "$policy_dir" . "hpcs.conf";
#
# Define the logfile and open it for writing.
#
open($logfile,">$ov_data_dir" . "policydep_hpcsConf.log");
#
# Print out all the variable values
#
print $logfile "===================== Hpsensor configuration Post Deployment Actions Start =================\n";
if ($^O eq "MSWin32") {
print $logfile "NOTE: The post deploy actions started at : " . `date /T` . `time /T` . "\n";
}
else {
print $logfile "NOTE: The post deploy actions started at : " . `date` . "\n";
}
print $logfile "NOTE: Operations Manager Bin Dir :$ov_bin_dir\n";
print $logfile "NOTE: Operations Manager Data Dir :$ov_data_dir\n";
print $logfile "NOTE: Configfile Policy Dir :$policy_dir\n";
print $logfile "NOTE: Filename Passed :$fullfilename\n";
#
# 1. Replace hpcs.conf file.
# 2. Checking if selfmon status (OPC_SELFMON_ENABLE : true/false)
# 3. Restart the hpsensor
#
perform_copy();
perform_selfmon_test();
perform_restart();
#
# Check if Selfmon is enabled re-enable selfmon
#
sub perform_selfmon_test {
my $selfmon_status;
if ($^O eq "MSWin32" ) {
$selfmon_status = `"ovconfget agent.health OPC_SELFMON_ENABLE"`;
}
else {
my $cmd = $ov_bin_dir . "ovconfget agent.health OPC_SELFMON_ENABLE";
$selfmon_status = `$cmd`;
}
print $logfile "INFO: Selfmon Status : $selfmon_status\n";
if($selfmon_status eq "true\n" ) {
if ($^O eq "MSWin32" ) {
my $cmd = "\"$ov_bin_dir..\\nonOV\\perl\\a\\bin\\perl\" \"". $perf_bin_dir . "selfmon_configure.pl\" -enable -avoidhpcsrun";
print $logfile "INFO: cmd : $cmd\n";
system($cmd);
}
else {
my $cmd = $ov_bin_dir."../nonOV/perl/a/bin/perl ". $perf_bin_dir . "selfmon_configure.pl -enable -avoidhpcsrun";
print $logfile "INFO: cmd : $cmd\n";
system($cmd);
}
}
else {
print $logfile "INFO: Selfmon is not enabled\n";
}
}
#
# Perform copy of hpcs.conf file to data dir
#
sub perform_copy {
use File::Copy;
my $dst_file;
print $logfile "NOTE: Entering function perform_copy.\n";
if ($^O eq "MSWin32" ) {
$dst_file = "$ov_data_dir" . "hpcs\\hpcs.conf" ;
print $logfile "NOTE: Copying $fullfilename to $dst_file. Windows\n";
copy("$fullfilename", "$dst_file");
}
else {
$dst_file = "$ov_data_dir" . "hpcs/hpcs.conf";
print $logfile "NOTE: Copying $fullfilename to $dst_file. Other platforms\n";
copy("$fullfilename", "$dst_file");
}
print $logfile "NOTE: Leaving function perform_copy.\n";
}
#
# To start the Hpsensor Services.
# On error, send opcmsg but do not quit.
#
sub perform_restart {
print $logfile "NOTE: Entering function perform_restart.\n";
if ($^O eq "MSWin32") {
system("ovc -restart hpsensor");
}
else {
system($ov_bin_dir."\\ovc -restart hpsensor");
}
print $logfile "NOTE: Leaving function perform_restart.\n";
}
#
# Send opcmsg to server
#
# Argument 1
# DIE - exit after sending the message
# NOTE - Do not exit
# WARNING - Do not exit
# ERROR - Do not exit
#
# Argument 2
# Message to be sent
#
sub send_opcmsg {
use Sys::Hostname;
# Constants
my $application = "OA Performance Collection Component";
my $object = "PostDeployActions";
my $msg_grp = "Performance";
my $hostname = hostname();
# Variables
my $severity;
my @run_command;
my $runcommand;
print { $logfile ? $logfile : \*STDOUT } "NOTE: Entering function send_opcmsg.\n";
if ($_[0] eq "DIE") {
$severity = "critical";
$error_num++;
}
elsif ($_[0] eq "ERROR") {
$severity = "major";
$error_num++;
}
elsif ($_[0] eq "WARNING") {
$severity = "warning";
}
elsif ($_[0] eq "NOTE") {
$severity = "normal";
}
else {
$severity = "normal";
}
print { $logfile ? $logfile : \*STDOUT } "NOTE: Sending opcmsg to management server.\n";
if ( $^O eq "MSWin32" ) {
my $run_command;
$run_command = " \"opcmsg\" severity=\"$severity\" application=\"$application\" object=\"$object\" msg_text=\"$_[1]\" msg_grp=\"$msg_grp\" node=\"$hostname\" ";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Running $run_command\n";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Message sent is - $_[1]\n";
system($run_command);
}
elsif ($^O eq "solaris") {
$runcommand = " \"$ov_bin_dir/opcmsg\" severity=\"$severity\" application=\"$application\" object=\"$object\" msg_text=\"$_[1]\" msg_grp=\"$msg_grp\" node=\"$hostname\" ";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Running $runcommand\n";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Message sent is - $_[1]\n";
system($runcommand);
}
else {
my @run_command;
@run_command = ("$ov_bin_dir/opcmsg", "severity=$severity", "application=$application", "object=$object", "msg_text=$_[1]", "msg_grp=$msg_grp", "node=$hostname");
print { $logfile ? $logfile : \*STDOUT } "NOTE: Running @run_command\n";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Message sent is - $_[1]\n";
system(@run_command);
}
if ($_[0] eq "DIE") {
print { $logfile ? $logfile : \*STDOUT } "NOTE: The Post Deploy Actions encountered a CRITICAL error, quitting.\n";
print { $logfile ? $logfile : \*STDOUT } "NOTE: Leaving function send_opcmsg.\n";
print { $logfile ? $logfile : \*STDOUT } "===================== Perf Post Deployment Actions End =================\n";
if ( $logfile ) {
close($logfile);
}
exit 1;
}
print { $logfile ? $logfile : \*STDOUT } "NOTE: Leaving function send_opcmsg.\n";
}