From 93e42d9908f2c82b056dfcc68976d005be444875 Mon Sep 17 00:00:00 2001 From: hu-weihua Date: Tue, 20 Sep 2016 02:39:47 -0400 Subject: [PATCH 1/3] Restructure osdeplay code logic --- xCAT-probe/lib/perl/LogParse.pm | 684 +++++++ xCAT-probe/lib/perl/probe_global_constant.pm | 47 + xCAT-probe/lib/perl/probe_utils.pm | 33 +- xCAT-probe/subcmds/osdeploy | 1674 +++++++++--------- 4 files changed, 1562 insertions(+), 876 deletions(-) create mode 100644 xCAT-probe/lib/perl/LogParse.pm create mode 100644 xCAT-probe/lib/perl/probe_global_constant.pm diff --git a/xCAT-probe/lib/perl/LogParse.pm b/xCAT-probe/lib/perl/LogParse.pm new file mode 100644 index 000000000..77141fc45 --- /dev/null +++ b/xCAT-probe/lib/perl/LogParse.pm @@ -0,0 +1,684 @@ +package LogParse; + +# IBM(c) 2016 EPL license http://www.eclipse.org/legal/epl-v10.html + +BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } +use lib "$::XCATROOT/probe/lib/perl"; +use probe_global_constant; +use probe_utils; + +use strict; +use Data::Dumper; +use File::Path; +use File::Copy; +use Time::Local; +use File::Basename; + +#------------------------------------------ + +=head3 + Description: + The constructor of class 'LogParse' + Arguments: + Public attributes: + $self->{verbose}:scalar, Offer verbose information, used for handling feature logic + private attributes: + $self->{log_open_info}: reference of a hash, used to save the log file operating information. + $self->{current_ref_year}: scalar, the year information of current time. such as 2016. Used for log time parsing + $self->{current_ref_time}: scalar, the epoch format of current time, such as 1472437250. Used for log time parsing + + $self->{debug}: Scalar, offer debug information, used for hanlde code logic, used by developer to debug function running + $self->{debuglogpath}: Scalar, the path of debug log files + $self->{debuglogfd}: File descriptor of debug log files + + The structure of "log_open_info" hash is: + $self->{log_open_info}->{}{openfd} : The file descriptor of sepecific openning log file + $self->{log_open_info}->{}{rotate_file_list} : Array, all rotate file about related log file + $self->{log_open_info}->{}{openning_file_index} : scalar, the index of openning file in rotate_file_list + $self->{log_open_info}->{}{next_read_point} : scalar, the read point of one log file, used by 'seek' function + $self->{log_open_info}->{}{filetype} : scalar, the type of current log file, $::LOGTYPE_RSYSLOG or $::LOGTYPE_HTTP + $self->{log_open_info}->{}{next_start_time} : scalar, the next read time + + Returns: + The instance of class +=cut + +#------------------------------------------ +sub new { + my @args = @_; + my $self = {}; + my $class = shift; + $self->{verbose} = shift; + + my %log_open_info; + $self->{log_open_info} = \%log_open_info; + + my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime(time()); + $self->{current_ref_year} = $year; + $self->{current_ref_time} = time(); + + $self->{debug} = 0; + if ($self->{debug}) { + my $logfiledir = "/tmp/xcatprobedebug/"; + mkpath("$logfiledir") unless (-d "$logfiledir"); + $self->{debuglogpath} = $logfiledir; + $self->{debuglogfd}; + } + + bless($self, ref($class) || $class); + return $self; +} + +#------------------------------------------ + +=head3 + Description: + Public functuon. Calculate the possible host name of current server in rsyslog files. + Arguments: + NULL + Returns: + A array which contains the possible host names of current server + Such as ("xxxxxx", "xxxxx.domain",....) +=cut + +#------------------------------------------ +sub obtain_candidate_mn_hostname_in_log { + my $self = shift; + + my $svr_hostname_short = `hostname -s`; + chomp($svr_hostname_short); + my $svr_hostname_domain = `hostname -d`; + chomp($svr_hostname_domain); + + my @candidate_svr_hostname_inlog; + push(@candidate_svr_hostname_inlog, $svr_hostname_short); + push(@candidate_svr_hostname_inlog, "$svr_hostname_short.$svr_hostname_domain"); + if ($self->{debug}) { + my $tmpstr = ""; + $tmpstr .= "$_ " foreach (@candidate_svr_hostname_inlog); + probe_utils->send_msg("stdout", "d", "The candidate MN hostname in log are $tmpstr"); + } + return @candidate_svr_hostname_inlog; +} + + + +#------------------------------------------ + +=head3 + Description: + Public function. Specify the log files scope which will be scaned. + Arguments: + NULL + Returns: + A hash which save all candidate log file information + $candidate_log{