⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fc_collector.pm

📁 Perl开发的数据采集工具 基于UNIX
💻 PM
📖 第 1 页 / 共 2 页
字号:
package FC_Collector;#################################################################################  @(#) Perl Module: FC_Collector##  Copyright(C) 2002-2004 BOCO Inter-Telecom DC Team, All Rights Reserved##  Author(s): JiaXiaoLong#  #  Creation Date: 2002/12/12##  Description:1.This package is the base of file collection.It reads the config#		file, connects bss or msc and sends commands to collect data. #	       2.The second functions of this module are: common prepare method#		 and common postprocess method. ################################################################################use Env qw(NPM_HOME);use XML::Simple;use Data::Dumper;use threads;use threads::shared;use StdCollect;use StdConnect;@ISA=("StdCollect","StdConnect");use Exporter;@ISA=('Exporter');@EXPORT=qw(WriteHash2Col_cfg);use lib "$NPM_HOME/common/modules";use DBIs;################################################################  Function:new##  Input:##  Output:##  Return value:##  Description:create filecollector###############################################################sub new{	my ($pkg,$Assistant_Var,$ErrMessage_hdl,$db_para) = @_;	my $filecollector=bless{				'Assistant_Var'=> $Assistant_Var,				'ErrMessage_hdl'=> $ErrMessage_hdl,				'db_para' => $db_para,				'connect_handle'=>'NULL',				'connect_func'=>'NULL',				'command_func'=>'NULL'			},$pkg;	return $filecollector;} #----------------------------------------------------------------------## common file collection part. #----------------------------------------------------------------------#################################################################  Function:creat_method_function##  Input:##  Output:##  Return value:connect and command functions##  Description: read method_module.xml ###############################################################sub creat_method_function{	my $colcfg="$NPM_HOME/common/mbin/filecollector/config/method_func.xml";	DBIs::Trace("Read method_func file: $colcfg\n");	if(!(-r	 $colcfg)){			$err_msg="Can't read file $colcfg .\n File:".__FILE__."\t Line:".__LINE__."\n";			DBIs::Trace("$err_msg");			return (-1,$err_msg,'','');	}	$act_func_map=eval{XMLin("$colcfg")};	if($@){		$err_msg="$@ File:".__FILE__."\t Line:".__LINE__."\n";		return (-1,$err_msg,'','');	}						return (1,'success\n',$act_func_map->{'Connect_Method'},$act_func_map->{'Command_Method'});}################################################################  Function:connect_ne##  Input:1.connect information which has structure:#		{#			connect_type,#			other necessary information.#		}#	 2.connect handle#  Output:##  Return value:$return_code,$return_message,$connect_hdl.#		$return_code=1,success, others fail.##  Description:this function is designed to control all kinds of#		connection.###############################################################sub connect_ne{	my ($pkg,$connect_inf,$connect_hdl)=@_;	my ($result_code,$result_msg);		my $connect_type=lc($connect_inf->{'Connect_type'});	my $connect_func=$pkg->{'connect_func'}{$connect_type}{'Function'};#	print "$connect_type\n";#	print "$connect_func\n";	#----------------------------------	# handle NULL connection: rcp,rsh	#----------------------------------	if($connect_type=~/NULL/i){		return (1,"success \n",$connect_hdl);	}	if(!(defined $connect_func)){		return(-1," the type of $connect_type is not used \n",$connect_hdl);		}	else {		#print Dumper $connect_hdl;		DBIs::Trace("Connect Func:$connect_func\n");                ($result_code,$result_msg,$connect_hdl)=$pkg->$connect_func($connect_inf,$connect_hdl);                if($result_code==1){                        return (1,"$connect_type success\n",$connect_hdl);                }                else{                        return (-1,$result_msg);                }        }}################################################################  Function:execute_connect##  Input: the ref hash of connection information.##  Output:##  Return value:1 connect succes, -1 connect fail##  Description:connect omc/oss/terminal and bss/msc,etc.###############################################################sub execute_connect{	my ($pkg,$cnt_inf)=@_;	my $max_retry=$cnt_inf->{'retry'}{'maxtimes'};	if (!$max_retry){$max_retry=0;}	#-------------------------------------------------	# $ne1_cntinf is omc/oss connection information	# and 	# $ne2_cntinf is bss/msc connection information	#-------------------------------------------------	$cnt_inf= $pkg->Format_HashStruc($cnt_inf);	my $ne1_cntinf= $cnt_inf->{'ne'};	my $ne2_cntinf= $cnt_inf->{'ne'}{'child_ne'};	delete $ne1_cntinf->{'child_ne'};	my ($return_code,$return_msg,$err_msg,$connect_hdl);	my $retry_times=0;	while(($retry_times<=$max_retry)){		$retry_times++;		#----------------------------		# connect omc/oss		#----------------------------		($return_code,$return_msg,$connect_hdl)=$pkg->connect_ne($ne1_cntinf,0);		#---------------------------------------------------------		# connect omc/oss error, retry here.		#---------------------------------------------------------		if ($return_code==-1){			$err_msg=$return_msg."\n\tFile:".__FILE__."\n\tLine:".__LINE__."\n";			next;		} 		#---------------------------------------------------------		# connect bss/msc. if connection is error here , we		# close the connect handle comming from connecting omc/oss		#---------------------------------------------------------		($return_code,$return_msg,$connect_hdl)=$pkg->connect_ne($ne2_cntinf,$connect_hdl);		#---------------------------------------------------------		# connect msc/bss error, retry here.		#---------------------------------------------------------		if ($return_code==-1){			$err_msg=$return_msg."\n\tFile:".__FILE__."\n\tLine:".__LINE__."\n";			next;		}				#---------------------------------------------------------		# success. Note, for rcp&rsh,connection doesn't need.		# $pkg->{'connect_handle'}= NULL is in this case.		#---------------------------------------------------------		if($connect_hdl){			$pkg->{'connect_handle'}=$connect_hdl;		}				return (1,"Connect successfully\n");	}		#--------------------------------	# fail,need trace here.	#--------------------------------		return (-1,$err_msg);}################################################################  Function:execute_cmdlist##  Input: command information##  Output: data file collected##  Return value:1 success -1 fail.##  Description:execute all command listed in collection config file.###############################################################sub execute_cmdlist{	my ($pkg,$cmd_inf,$err_inf)=@_;	my $r_cmd_list=$cmd_inf;	#----------------------------------------------	# if there is only one item in command list	# we have to change the hash stucture here.	#----------------------------------------------	if(exists $r_cmd_list->{'name'}){		delete $r_cmd_list->{'name'};		%cmd_list=("1"=>$r_cmd_list);	}	else{		if(exists $r_cmd_list->{'id'}){			%cmd_list=("1"=>$r_cmd_list);		}		else{			%cmd_list=%$r_cmd_list;		}	}	#----------------------	# add $share_hdl 	#----------------------	my $share_hdl;#modify by jzw 20041101	my @err_file,$err_count=0;print "\n###### NORMAL GET FILE START ######\n";	foreach $cmd_index (sort{$a<=>$b} keys %cmd_list){#print "\n######cmd_index is :$cmd_index######\n";		my $r_current_cmdinf=$cmd_list{$cmd_index};		$r_current_cmdinf->{'Ftp_state'} = 0;		my $error_tag = $r_current_cmdinf->{'Error_tag'};		my $flow_tag = $r_current_cmdinf->{'Flow_tag'};				DBIs::Trace("Current Step: $cmd_index");		my ($return_code,$return_msg,$share_handle)=$pkg->execute_current_cmd($r_current_cmdinf,$err_inf,$error_tag,$share_hdl);		$share_hdl=$share_handle;		DBIs::Trace("Step $cmd_index: $return_code");		#---------------------------------------------------		# serious error, we must interrupt current work flow 		# and return back. need trace here.		#---------------------------------------------------	        my $err_msg=$return_msg." File:".__FILE__."\t Line:".__LINE__."\n";                if (($return_code==1)){                    next;       	        }                 if (($return_code==-2)){#modify by jzw 20041101 for error repeat get;			$err_count = $err_count + 1;#print "\n###### remotefile is:$r_current_cmdinf->{'remotefile'} ###########\n";			@err_file[$err_count] = $cmd_list{$cmd_index};#modify by wengzy  for error skip#                    next;                          #$return_code=check_return_code($return_code,$err_inf,$return_msg);		   #print "return_code=$return_code \n";                }       		if (($return_code==-1)){			#modify by wengzy  for error skip			    next;       			if ($flow_tag =~ /next/i) {				DBIs::Trace("\n\nWorkFlow is next ...\n");				next;			}			else {				#return (-1,$err_msg)			}                }                print "\n###### NORMAL GET FILE END ######\n";#print "\n###### ERR FILE IS######\n";#print Dumper(@err_file);			my $i;		if(@err_file>0){print "\n###### GET ERRFILE AGAIN START######\n";	        	DBIs::Trace("Err File Get Repeat Start:");			for ($i=1;$i<=@err_file;$i++){#print "\n###### AGAIN r_current_cmdinf is:$err_file[$i] ######\n";				my $r_current_cmdinf=$err_file[$i];				$r_current_cmdinf->{'Ftp_state'} = 1;#print "\n######r_current_cmdinf is ######################\n";#print Dumper($r_current_cmdinf);	                	my $error_tag = $r_current_cmdinf->{'Error_tag'};	                	my $flow_tag = $r_current_cmdinf->{'Flow_tag'};		                	DBIs::Trace("Current Step: $cmd_index");	                	my ($return_code,$return_msg,$share_handle)=$pkg->execute_current_cmd($r_current_cmdinf,$err_inf,$error_tag,$share_hdl);				$share_hdl=$share_handle;	                	DBIs::Trace("Step $cmd_index: $return_code");				my $err_msg=$return_msg." File:".__FILE__."\t Line:".__LINE__."\n";	                	if (($return_code==1)){	                    	next;	                	}	                	if (($return_code==-2)){	                    	next;	                	}	                	if (($return_code==-1)){	                            	next;	                        	if ($flow_tag =~ /next/i) {	                                	DBIs::Trace("\n\nWorkFlow is next ...\n");	                                	next;	                        	}	                        	else {	                                	#return (-1,$err_msg)	                        	}	                	}			}			DBIs::Trace("Err File Get Repeat End");print "\n###### GET ERRFILE AGAIN END ######\n";		}                        			}        #--------------------------        # need trace here.	#--------------------------	return (1,"Finish execute command list.\n");    	}################################################################  Function:execute_current_cmd##  Input: current command which will be execute here.##  Output:##  Return value:1,success -1 error.##  Description:this function is called by sub execute_cmdlist.###############################################################sub execute_current_cmd{	my ($pkg,$r_current_cmdinf,$r_current_errinf,$error_tag,$share_hdl)=@_;	my $cmd_type=lc($r_current_cmdinf->{'cmd_type'});	my $cmd_func=$pkg->{'command_func'}{$cmd_type}{'Function'};	print "$cmd_type\n";	print "$cmd_func\n";	my ($return_code,$return_msg,$return_hdl);	if(!(defined $cmd_func)){#		print "the type of $cmd_type is not used\n";		return(-1," $cmd_type is not used \n");		}	else {#		print "Cmd is correct, Func: $cmd_func\n";		eval{#print "\n##########r_current_cmdinf ##################\n";#print Dumper($r_current_cmdinf);		    ($return_code,$return_msg,$return_hdl)=$pkg->$cmd_func($r_current_cmdinf,$r_current_errinf,$error_tag,$share_hdl);		};		#---------------------------------------------		# fail 		# need trace here.		#---------------------------------------------		if($@){			return (-1,"$@"." File:".__FILE__."\n"." Line:".__LINE__."\n");		}		return ($return_code,$return_msg,$return_hdl);	}}################################################################  Function:read_colcfg##  Input:collection config file($colcfg)##  Output:##  Return value:1.return_code:1 success, -1 fail#		2.return_msg: success or error message.#		3.connection information#		4.command information#  Description: get connection and command information from collection#		config file.##

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -