Hi All,
I have writen a library for a particular function.I could not written
the hash reference fron the subroutine "process_files".Can any one
please help in this regard?
Also i have pasted the file below
package Filter_Rule;
use StorADE::Tele_Decoder;
use database_common_function;
use DBI;
use Audit;
use TutorialConfig;
#use tools;
if(!open(LOG,">>/var/opt/SUNWTeleAlarm/LOG/Filter_Rule.log")){
print "Unable to open Log files ::
/var/opt/SUNWTeleAlarm/LOG/Filter_Rule.log ";
}
## Database Connection
$dbh = DBI->connect(
'DBI:mysql:telealarm:localhost;mysql_socket=/tmp/telealarm.sock',
'telealarm',
'telealarm',
) || die "Database connection not made: $DBI::errstr";
if($DBI::errstr){
$audit->warning("mysql error",data=>$dbh);
print LOG "MySQL database connection error \n";
print "Database connection error \n";
}else{
print LOG "Successfully connected database [MySQL] \n";
# print "Sucessfully connect Database of telealarm \n";
}
my $audit = new Audit;
my %hash_event_list1;
sub main_validation
{
our $filter = shift;
our $rule = shift;
%hash_event_list1 =();
## get Test Event Directory details from conf file
my $RSconf = new TutorialConfig;
$RSconf->read('/opt/SUNWTeleAlarm/conf/Telealarm.conf');
my $test_event_dir = $RSconf->get('TeleAlarm.Test_event_directory');
print LOG "Test Event Directory :: $test_event_dir \n";
print "Filter :: $filter \n";
print "Rule :: $rule \n";
print LOG "Filter :: $filter \n";
print LOG "Rule :: $rule \n";
$filter = parser($filter);
$rule = parser($rule);
print LOG "Parser Rule :: $rule \n";
print LOG "Parser filter :: $filter \n";
if($filter && $rule){
#my $test_event_dir = "/var/opt/SUNWTeleAlarm/Test_event_directory";
my $match_flt1 = process_files($test_event_dir);
print LOG eval $match_flt1;
print LOG "Return value from :: $match_flt1 \n";
print LOG %match_flt1;
foreach my $item (keys %$match_flt1){
print LOG "Hash :: $match_flt1{$item} \n";
}
return $match_flt;
}
# return($filter,$rule);
}
sub parser
{
my $arg = shift();
if($arg =~ /_/){
# print $' ;
return $';
}else{
return 0;
}
}
sub process_files {
my($FILE) = @_;
print LOG "file & PAth :: $FILE \n";
$extension = "email";
if (-d $FILE) {
opendir(O, $FILE);
my @L = readdir(O); closedir(O);
foreach my $f (sort @L) {
next if ($f !~ /\.$extension$/);
# print "\nMESSAGE '$f'\n\n";
my $f2 = $f;
$f2 = substr($f2,2) if (substr($f2,0,2) eq "./");
my $test = process_file("$FILE/$f2");
#return @rs_flt;
# print LOG "test print \n";
# foreach my $k1 (keys %$test){
# print LOG "hash keys :: $test->{$k1} \n";
# }
}
return $test;
# return "true";
} elsif (-f $FILE) {
#print "MESSAGE $FILE\n";
#print "Inside process_files ::\MESSAGE \$FILE :: $FILE \n";
#my @rs_flt = process_file($FILE);
&process_file($FILE);
#return @rs_flt;
#return @rs_flt;
} else {
my $ERR = "Invalid file $FILE \n";
return $ERR;
}
# return $test;
}
sub process_file{
my @event_text;
my($file) = @_;
print LOG "File list :: $file \n";
%hash_event_list1 = ();
$hash_event_list1{'file_name'} = $file;
my @event_rs = StorADE::Tele_Decoder::open_event_file($file);
if([EMAIL PROTECTED]){
print "No content found, Empty file for :$file \n";
}else{
## Search subject location from email event
my ($match,$address) = StorADE::Tele_Decoder::subject_event(@event_rs);
print "Match :: $match Address :: $address \n";
my ($match_count,$address_count);
undef $match_count;
undef $address_count;
$match_count = length($match);
$address_count = length($address);
if($match_count == 0 && $address_count == 0){
print "Error : Subject missin in the email event \n";
}else{
## find the locationis and evenr serial in the email subject
my ($location_id,$event_serial) =
verify_locationid_email_event($address);
## Remove the space from locationid and event serial
$location_id =~ s/^\s+|\s+$//g;
$event_serial =~ s/^\s+|\s+$//g;
print "Locationid :: $location_id \n";
print "Event Serial :: $event_serial \n";
$hash_event_list1{'location_id'} = $location_id;
$hash_event_list1{'event_serial'} = $event_serial;
## Locationid and event seiral verify in deviceinfo table
my $result =
check_locationid_deviceinfo($location_id,$event_serial);
if($result eq "true"){
### DB in deviceinfo table verification for product,serial and
managedOps
my($product,$serial,$managedOps) =
search_product($hash_event_list1{'location_id'},$hash_event_list1{'event_serial'});
print LOG "\$product :: $product \n";
print LOG "\$serial :: $serial \n";
print LOG "\$managedOps :: $managedOps \n";
# hash values
$hash_event_list1{'deviceinfo'} = "Yes";
$hash_event_list1{'product'} = $product;
$hash_event_list1{'serial'} = $serial;
$hash_event_list1{'managedOps'} = $managedOps;
# search event text
@event_text = StorADE::Tele_Decoder::event_text(@event_rs);
# print LOG "Event Text :: @event_text \n";
if([EMAIL PROTECTED]){
print LOG "Bad email event,event text missing \n";
}else{
## hash values
$hash_event_list1{'event_text'} = @event_text;
my @match = filter_process(@event_text);
print LOG "Matched filter reult :: @match \n";
if(@match[0] == 0){
print LOG " No filter matched \n";
}else{
print LOG "Filter matched \n";
## Rules verification
## hash values for filter
$hash_event_list1{'filter'}= @match[0];
# my @dbrule_match =
database_common_function::select_local_rule(@match);
my %dbrule_results = rule_process($rule);
## hash value entery for
run_position,filters_matched,actionable,severity,fault_group,continuation_period
print LOG " Local results table filters matched :
$dbrule_results{filters_matched} \n";
my @split_rules_filter = split(/\+/,
$dbrule_results{filters_matched});
my $flag = 0;
foreach my $item (@split_rules_filter){
if($hash_event_list1{'filter'} == $item){
print LOG " Matched filter in split rule
table. :; $item \n";
$flag = 1;
$hash_event_list1{'filters_matched'} = $item;
}
print LOG "Split rules :: $item \n";
}
if($flag == 1){
$hash_event_list1{'rule_number'} = $rule;
$hash_event_list1{'run_position'} =
$dbrule_results{run_position};
# $hash_event_list1{'filters_matched'} =
$dbrule_results{filters_matched};
$hash_event_list1{'actionable'} = $dbrule_results{actionable};
$hash_event_list1{'severity'} = $dbrule_results{severity};
$hash_event_list1{'fault_group'} = $dbrule_results{fault_group};
$hash_event_list1{'continuation_period'} =
$dbrule_results{continuation_period};
}
return \%hash_event_list1;
}
}
}else{
print LOG " LocationID and Event serial missed into
deviceinfo table \n";
}
}
}
# return @match;
#exit;
}
sub search_product
{
my $Loc_id = shift;
my $event_ser = shift;
chomp($Loc_id);
chomp($event_ser);
my $sql_dev = qq{ SELECT product,serial,managedOps FROM
deviceinfo where ((locationID = "$Loc_id") and (eventSerial
="$event_ser"))};
my $sth_dev = $dbh->prepare( $sql_dev );
sleep 1;
$sth_dev->execute();
if($DBI::errstr){
$audit->warning("mysql error",data=>$dbh);
}
my ($v1,$v2,$v3);
$sth_dev->bind_columns( undef, \$v1, \$v2, \$v3);
while($sth_dev->fetch()){
delete $hash_event_list1{'product'};
$hash_event_list1{'product'} = $v1;
$hash_event_list1{'serial'} = $v2;
$hash_event_list1{'managedOps'} = $v3;
print LOG "Device Info Table => product :: $v1 \n serial ::
$v2 \n managedOps :: $v3 \n";
}
return($v1,$v2,$v3);
}
sub check_locationid_deviceinfo
{
my $location_id = shift;
my $event_serial = shift;
if(($location_id) && ($event_serial)){
my $sql = qq{ select locationID,eventSerial from deviceinfo where
(locationID="$location_id") && (eventSerial="$event_serial")};
my $sth1 = $dbh->prepare( $sql );
$sth1->execute();
if($DBI::errstr){
# $audit->warning("mysql error",data=>$dbh);
print LOG "DB ERROR : $DBI::errstr \n";
print "DB ERROR : $DBI::errstr \n";
}
my ($lid,$lid1);
$sth1->bind_columns( undef, \$lid,\$lid1);
while( my $ref=$sth1->fetch() ) {
$lid = $lid;
$lid1 = $lid1;
}
# print LOG "Db Location id :: $lid \n DB Serial ::
$lid1 \n";
if((!$location_id eq $lid) && (!$event_serial eq $lid1))
{
print LOG "locationid and event serial not matched
in deviceinfo \n";
return false;
}else{
print LOG "DB Location id :: $lid \n DB Serial ::
$lid1 \n";
print "DB Location id :: $lid \n DB Serial :: $lid1
\n";
return true;
}
}else{
print LOG "LocationID and event serial missing for
deviceinfo Verification \n";
}
}
sub verify_locationid_email_event
{
my $address = shift;
my ($location_id,$event_serial) =
StorADE::Tele_Decoder::Split_locationid($address);
return($location_id,$event_serial);
}
sub filter_process
{
print LOG "Filter Process :: $filter \n";
print LOG "Rule Process :: $rule \n";
my @event_text = @_;
# print LOG "Event Text test :: @event_text \n";
@dbreturn = database_common_function::select_local_filter($filter);
print LOG "Test return values \n";
print LOG "Return filter :: @dbreturn \n";
%filter = @dbreturn;
my @match_flt = ();
for my $key1 (sort keys %filter){
my $ser = $filter{$key1};
print LOG "Pass search filter :: $ser \n key :: $key1
\n";#exit;
my $rs =
database_common_function::search_filter($ser,@event_text);
if($rs == 1)
{
push(@match_flt,$key1)
}
#print "Matched Filters :: @match_flt \n";
}
print LOG "Matched Filters :: @match_flt \n";
if(@match_flt){
return @match_flt;
}else{
return 0;
}
}
sub rule_process
{
## select value from local_rules tables based on the rule number
my $rule_no = shift;
# print "Rule number : $rule_no \n";
my %rule_rs = database_common_function::select_local_rule($rule_no);
print LOG "Run Position :: $rule_rs{run_position} \n ";
print LOG "Filter Matched :: $rule_rs{filters_matched} \n";
print LOG "Actionable :: $rule_rs{actionable} \n";
print LOG "Severity :: $rule_rs{severity} \n";
print LOG "Fault Group :: $rule_rs{fault_group} \n";
print LOG " continuation_period ::$rule_rs{continuation_period} \n";
return %rule_rs;
#return %dbreturn;
}
1;
Regards,
Praveena
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/