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 xCAT::NetworkUtils; 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 $self->{load_type}:scalar, $::MONITOR or $::REPLAY, used for distinguishing monitor and replay. 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; $self->{load_type} = 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} = undef; } 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 = join(" ", @candidate_svr_hostname_inlog); probe_utils->send_msg("stdout", "d", "The candidate MN hostname(s) 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{