File: //var/opt/OV/bin/instrumentation/SpiMetricHash.pm
###############################
#
# Version : 11.11.025
#
###############################
package SpiMetricHash;
#############################################################################################################################################
#This perl module would be used to reduce the SourceEx calls with in the Policies for different Metrics which are not included in Source Tab
#SetMetricHash()
#This function gets the required data to be pushed into the hash and generates the hash, and there after storing the same hash string into a
#Session variable for future access. To get the proper metric data one needs to provide the CodaPath, as this would be taken to run SourceEx
#once with in this function.
#
#get_this_instance()
#This function is used to retrieve the value based upon the Key passed to it. This basically gets the Value for the Key being passed to it,
#and returns the same. In case if the Value is not defined or say "na" or empty, then the value returned is "unknown"
##############################################################################################################################################
require Exporter;
use vars qw($VERSION @ISA @EXPORT);
use POSIX;
use Config;
use OvTrace;
use warnings;
use Data::Dumper;
# set the version for version checking
$VERSION = 0.01;
@ISA = qw(Exporter);
sub new_hash_store
{
my $class = shift;
my ( $policy, $console, $rule, $session, $mhash, $debug ) = @_;
my $self = {};
$self->{OVOPOLICY} = $policy;
$self->{OVOCONSOLEMESSAGE} = $console;
$self->{OVORULE} = $rule;
$self->{OVOSESSION} = $session;
$self->{HASHSTR} = $mhash;
$self->{DEBUG} = $debug;
$self->{TRACEOBJ}=OvTrace->new($policy,$console,$rule,$session);
$self->{METRIC_HASH} = {};
bless($self, $class);
return $self;
}
sub SetMetricHash
{
my $self = shift;
my $CodaPath = shift;
my $traceObj = $self->{TRACEOBJ};
my $Key; #To store the Key in the hash
my $Value; #To store the Value in the hash
my $Counter = 0; #count acts as incremental counter to break from the while condition
my $Instance_count = 0; #To store the instance count from SourceEx call
my $AllSrc; #Reference to the object returned bu SourceEx
my $Dumper_obj; #Used to create the Data::Dumper object
my $Hash_str;
my $sess_varname_ref;
my $Debug = $self->{DEBUG};
#Below code is used to get the values and store into the Hash
$AllSrc = $self->{OVOPOLICY}->SourceEx($CodaPath);
$Instance_count = $AllSrc->InstanceCount();
if ( $self->{DEBUG} )
{
$traceObj->WriteTraceLog($Debug, "Total Instance Count is $Instance_count");
}
$self->{OVOSESSION}->Value("Instance_count",$Instance_count);
while ( $Counter < $Instance_count )
{
#Storing the values into the hash
$Key = $AllSrc->NameOf($Counter);
$Value = $AllSrc->ValueOf($Counter);
if ( lc($Value) eq "na" or $Value eq "-" )
{
$Value = "Unknown";
}
$self->{METRIC_HASH}{$Key} = $Value;
if ( $self->{DEBUG} )
{
$traceObj->WriteTraceLog($Debug, "Value stored Key is $Key and Value is $Value \n");
}
$Counter = $Counter+1;
}
#Below code is used to store the above Generated Hash into the Session
$sess_varname_ref = '*'.$self->{HASHSTR};
$Dumper_obj = Data::Dumper->new ([$self->{METRIC_HASH}],[$sess_varname_ref]);
$Hash_str = sprintf("%s", $Dumper_obj->Dump());
if ( $self->{DEBUG} )
{
$traceObj->WriteTraceLog($Debug, "The Hash content is $Hash_str \n");
}
$self->{OVOSESSION}->Value($self->{HASHSTR}, $Hash_str);
}
1;