yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | #!/usr/bin/perl
|
| 2 | #
|
| 3 | # Copyright Statement:
|
| 4 | # --------------------
|
| 5 | # This software is protected by Copyright and the information contained
|
| 6 | # herein is confidential. The software may not be copied and the information
|
| 7 | # contained herein may not be used or disclosed except with the written
|
| 8 | # permission of MediaTek Inc. (C) 2005
|
| 9 | #
|
| 10 | # BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
|
| 11 | # THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
|
| 12 | # RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
|
| 13 | # AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
|
| 14 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
|
| 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
|
| 16 | # NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
|
| 17 | # SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
|
| 18 | # SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
|
| 19 | # THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
|
| 20 | # NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
|
| 21 | # SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
|
| 22 | #
|
| 23 | # BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
|
| 24 | # LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
|
| 25 | # AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
|
| 26 | # OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
|
| 27 | # MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
|
| 28 | #
|
| 29 | # THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
|
| 30 | # WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
|
| 31 | # LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
|
| 32 | # RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
|
| 33 | # THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
|
| 34 | #
|
| 35 | #
|
| 36 | #*****************************************************************************
|
| 37 | package tools::mbis;
|
| 38 | BEGIN{ push @INC, "tools/perl"};
|
| 39 | use MIME::Lite;
|
| 40 | use File::Copy;
|
| 41 | use Cwd;
|
| 42 | use File::Basename;
|
| 43 |
|
| 44 | # for export subroutines
|
| 45 | use Exporter;
|
| 46 | @ISA = qw(Exporter);
|
| 47 | use vars qw(@EXPORT);
|
| 48 | @EXPORT = qw(&mbisLogCommand &mbisLogInfo &mbisLogTimeStamp &mergeLogFile &mbisPostProcess &writeTimeLogFromTempfile);
|
| 49 |
|
| 50 | #*****************************************************************************
|
| 51 | # Global Variable Declaration and Initialization
|
| 52 | #*****************************************************************************
|
| 53 | my $file_server_folder;
|
| 54 | my $mbis_config_ini;
|
| 55 |
|
| 56 | if($^O eq "MSWin32") {
|
| 57 | if (!-d "protocol/lte_sec"){
|
| 58 | $file_server_folder = "\\\\glbfs14\\sw_releases\\mbis\\moly\\un_processed\\";
|
| 59 | $mbis_config_ini = "\\\\glbfs14\\sw_releases\\mbis\\scripts\\MBIS_conf.ini";
|
| 60 | }else{ # in LTE domain
|
| 61 | $file_server_folder = "\\\\mtklwafs01\\mbis\\moly\\un_processed\\";
|
| 62 | $mbis_config_ini = "\\\\mtklwafs01\\mbis\\scripts\\MBIS_conf.ini";
|
| 63 | }
|
| 64 | }
|
| 65 | if($^O eq "linux") {
|
| 66 | $file_server_folder = "/moly/un_processed"; #/glbfs14/sw_releases/mbis/ is root
|
| 67 | $mbis_config_ini = "/mtkeda/wcpsm/mbis/config/mbis_conf.ini";
|
| 68 | }
|
| 69 |
|
| 70 | #*****************************************************************************
|
| 71 | # Function: mbisLogCommand
|
| 72 | # Argument:
|
| 73 | # (1) $mbis_enable: mbis enable flag
|
| 74 | # (2) @argv: original command (.bat) name + the arguments
|
| 75 | #
|
| 76 | # Return: NONE
|
| 77 | # Description: log the original command and arguments into mbis info MBIS_BUILD_INFO_LOG.
|
| 78 | #*****************************************************************************
|
| 79 | sub mbisLogCommand{
|
| 80 | my ($mbis_enable, @argv) = @_;
|
| 81 |
|
| 82 | if ($mbis_enable){
|
| 83 | logToInfoFile ("COMMAND,make @argv");
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 | #*****************************************************************************
|
| 90 | # Function: mbisLogInfo
|
| 91 | # Argument:
|
| 92 | # (1) $mbis_enable: mbis enable flag
|
| 93 | # (2) $info: the info string
|
| 94 | #
|
| 95 | # Return: NONE
|
| 96 | # Description: log the info message into MBIS_BUILD_INFO_LOG.
|
| 97 | #*****************************************************************************
|
| 98 | sub mbisLogInfo{
|
| 99 | my ($mbis_enable, $info) = @_;
|
| 100 | if ($mbis_enable){
|
| 101 | logToInfoFile ($info);
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 | #*****************************************************************************
|
| 108 | # Function: mbisLogTimeStamp
|
| 109 | # Argument:
|
| 110 | # (1) $mbis_enable: mbis enable flag
|
| 111 | # (2) $info: the info string
|
| 112 | #
|
| 113 | # Return: NONE
|
| 114 | # Description: log the info message and timestamp into MBIS_BUILD_TIME_TMP.
|
| 115 | #*****************************************************************************
|
| 116 | sub mbisLogTimeStamp{
|
| 117 | my ($mbis_enable, $info) = @_;
|
| 118 | if ($mbis_enable){
|
| 119 | logToTimeStampTempFile ($info);
|
| 120 | }
|
| 121 | }
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 | #*****************************************************************************
|
| 126 | # Function: mergeFileIntoTempfile
|
| 127 | # Argument:
|
| 128 | # (1) $mbis_enable: mbis enable flag
|
| 129 | # (2) $folder: the *.mbis folder
|
| 130 | #
|
| 131 | # Return: NONE
|
| 132 | # Description: merge the content of all the *.mbis files $dir into MBIS_BUILD_TIME_TMP.
|
| 133 | #*****************************************************************************
|
| 134 | sub mergeLogFile{
|
| 135 | my ($mbis_enable, $folder) = @_;
|
| 136 | if ($mbis_enable){
|
| 137 | opendir (DIR, $folder) or die "no folder : $folder";
|
| 138 | my @files = grep {/.+\.mbis/} readdir DIR;
|
| 139 | close DIR;
|
| 140 | foreach my $file (@files){
|
| 141 | logFileIntoTimeStampTempFile("$folder/$file");
|
| 142 | }
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 | #*****************************************************************************
|
| 149 | # Function: mbisPostProcess
|
| 150 | # Argument:
|
| 151 | # (1) $mbis_enable: mbis enable flag
|
| 152 | # Return: NONE
|
| 153 | # Description: rewrite MBIS_BUILD_INFO_LOG and MBIS_BUILD_TIME_LOG and add
|
| 154 | # mbis process time info.
|
| 155 | #*****************************************************************************
|
| 156 | sub mbisPostProcess{
|
| 157 | my ($mbis_enable) = @_;
|
| 158 | if ($mbis_enable)
|
| 159 | {
|
| 160 | my $build_time_string = "";
|
| 161 | my $successful_build = 0;
|
| 162 | my $userID = "";
|
| 163 | my @info_list = ();
|
| 164 | my $bm_build = 0;
|
| 165 | my $transfer_file_name = "";
|
| 166 | my $machine = "";
|
| 167 | my $build_start_time = "";
|
| 168 | my $mbis_process_start_time;
|
| 169 | my $mbis_process_end_time;
|
| 170 | my $mbis_duration_time;
|
| 171 | my $total_process_start_time;
|
| 172 | my $total_process_end_time;
|
| 173 | my $total_duration_time;
|
| 174 | my $line;
|
| 175 | my $PID = "";
|
| 176 | my $sec;
|
| 177 | my $min;
|
| 178 | my $hour;
|
| 179 | my $mday;
|
| 180 | my $mon;
|
| 181 | my $year;
|
| 182 | my $path;
|
| 183 |
|
| 184 | $mbis_process_start_time = time;
|
| 185 | logToTimeStampTempFile("T_S,MBIS,M");
|
| 186 |
|
| 187 | # process the time log file
|
| 188 | &writeTimeLogFromTempfile($mbis_enable);
|
| 189 |
|
| 190 | # process the info log file
|
| 191 | open(FILEHANDLE, $ENV{MBIS_BUILD_INFO_LOG}) or die "can't open $ENV{MBIS_BUILD_INFO_LOG}!\n";
|
| 192 |
|
| 193 | foreach $line (<FILEHANDLE>){
|
| 194 | # for time end/start stamp
|
| 195 | $line =~ s/\s+$//;
|
| 196 | @info_list=split /,/, $line;
|
| 197 | if ($info_list[0] eq "SUCCESSFUL_BUILD")
|
| 198 | {
|
| 199 | $successful_build = $info_list[1];
|
| 200 | }
|
| 201 | elsif ($info_list[0] eq "USER")
|
| 202 | {
|
| 203 | $userID = $info_list[1];
|
| 204 | }
|
| 205 | elsif ($info_list[0] eq "BM_BUILD")
|
| 206 | {
|
| 207 | $bm_build = $info_list[1];
|
| 208 | }
|
| 209 | elsif ($info_list[0] eq "BUILD_MACHINE")
|
| 210 | {
|
| 211 | $machine = lc($info_list[1]);
|
| 212 | }
|
| 213 | elsif ($info_list[0] eq "BUILD_START_DATATIME")
|
| 214 | {
|
| 215 | $build_start_time = lc($info_list[1]);
|
| 216 | }
|
| 217 | elsif ($info_list[0] eq "PID")
|
| 218 | {
|
| 219 | $PID = sprintf("%8.8d",($info_list[1]));
|
| 220 | }
|
| 221 | }
|
| 222 | close(FILEHANDLE);
|
| 223 |
|
| 224 | $mbis_process_end_time = time;
|
| 225 | logToTimeStampTempFile("T_E,MBIS,M");
|
| 226 | logToTimeStampTempFile("T_E,TOTAL,A");
|
| 227 |
|
| 228 | # write the reformatted time log directly since parse the temp time log file already.
|
| 229 | $mbis_duration_time = $mbis_process_end_time - $mbis_process_start_time;
|
| 230 | logToTimeStampFile("MBIS,M,$mbis_process_start_time,$mbis_process_end_time,$mbis_duration_time");
|
| 231 |
|
| 232 | # get the start stampe for TOTAL to calculate the TOTAL time
|
| 233 | open(FILEHANDLE, $ENV{MBIS_BUILD_TIME_TMP}) or die "can't open $ENV{MBIS_BUILD_TIME_TMP}!\n";
|
| 234 | foreach $line (<FILEHANDLE>){
|
| 235 | if($line =~ /^T_S,TOTAL,A,(.+)/){
|
| 236 | $total_process_start_time = trim($1);
|
| 237 | last;
|
| 238 | }
|
| 239 | }
|
| 240 | close(FILEHANDLE);
|
| 241 |
|
| 242 | # write the reformatted time log directly again.
|
| 243 | $total_process_end_time = time;
|
| 244 | $total_duration_time = $total_process_end_time - $total_process_start_time;
|
| 245 | logToTimeStampFile("TOTAL,A,$total_process_start_time,$total_process_end_time,$total_duration_time");
|
| 246 |
|
| 247 | # Record build end_data_time
|
| 248 | # get epoch timestamp
|
| 249 | $build_time_sec = time;
|
| 250 | # convert to GMT+8 time
|
| 251 | ($sec, $min, $hour, $mday, $mon, $year) = gmtime($build_time_sec+28800);
|
| 252 | $build_time_string = sprintf("%4.4d.%2.2d.%2.2d.%2.2d.%2.2d.%2.2d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
|
| 253 | logToInfoFile("BUILD_END_DATATIME,$build_time_string");
|
| 254 |
|
| 255 | #if(($successful_build == 1) && ($bm_build == 1)){
|
| 256 | $transfer_file_name = $build_start_time . "_" . $machine . "_" . $PID;
|
| 257 |
|
| 258 | $dir_path = dirname($ENV{MBIS_BUILD_INFO_LOG});
|
| 259 | move($ENV{MBIS_BUILD_INFO_LOG}, "$dir_path/$transfer_file_name"."_mbis_info.log");
|
| 260 | move($ENV{MBIS_BUILD_TIME_LOG}, "$dir_path/$transfer_file_name"."_mbis_time.log");
|
| 261 | move($ENV{MBIS_BUILD_TIME_TMP}, "$dir_path/$transfer_file_name"."_mbis_time.tmp");
|
| 262 | $path = $ENV{MBIS_BUILD_INFO_LOG};
|
| 263 | $path =~ m/(.*)[\\\/](.+)/;
|
| 264 | #}
|
| 265 | } #if ($mbis_enable)
|
| 266 | }
|
| 267 |
|
| 268 | #*****************************************************************************
|
| 269 | # Function: writeTimeLogFromTempfile
|
| 270 | # Argument: NONE
|
| 271 | # Return: NONE
|
| 272 | # Description: calculate the time duration in MBIS_BUILD_TIME_TMP and rewrite
|
| 273 | # into MBIS_BUILD_TIME_LOG file.
|
| 274 | #*****************************************************************************
|
| 275 | sub writeTimeLogFromTempfile{
|
| 276 | my ($mbis_enable) = @_;
|
| 277 | if ($mbis_enable){
|
| 278 | my @time_data;
|
| 279 | my $timestamp_type;
|
| 280 | my $item_name;
|
| 281 | my $item_type;
|
| 282 | my $item_timestamp;
|
| 283 | my %mbis_start_timetable;
|
| 284 | my %mbis_end_timetable;
|
| 285 | my @item_seq;
|
| 286 | my $last_item_name;
|
| 287 | my @mbis_end_timetable_key;
|
| 288 | my $item;
|
| 289 | my $item_start_time;
|
| 290 | my $item_end_time;
|
| 291 | my $item_duration_time;
|
| 292 | my $log_str;
|
| 293 | my $line;
|
| 294 |
|
| 295 | open(FILEHANDLE, $ENV{MBIS_BUILD_TIME_TMP}) or die "can't open $ENV{MBIS_BUILD_TIME_TMP}!\n";
|
| 296 | foreach $line (<FILEHANDLE>){
|
| 297 | $line =~ s/\s+$//;
|
| 298 |
|
| 299 | # do NOT process TOTAL and MBIS start timestamp because the end timestamp is not logged yet.
|
| 300 | if($line =~ /(^T_S,TOTAL,A)|(^T_S,MBIS,M)/){
|
| 301 | next;
|
| 302 | }
|
| 303 |
|
| 304 | if($line =~ /^(T_S|T_E),/){
|
| 305 | @time_data = split (/,/ , $line);
|
| 306 |
|
| 307 | #T_S[0],emigen[1],T[2],1288539647[3]
|
| 308 | $timestamp_type = trim($time_data[0]);
|
| 309 | $item_name = trim($time_data[1]);
|
| 310 | $item_type = trim($time_data[2]);
|
| 311 | $item_timestamp = trim($time_data[3]);
|
| 312 |
|
| 313 | if ($timestamp_type eq "T_S"){
|
| 314 | $mbis_start_timetable{$item_name} = "$item_type,$item_timestamp";
|
| 315 |
|
| 316 | # remember the item sequence
|
| 317 | push(@item_seq, $item_name);
|
| 318 |
|
| 319 | # special handling for $item_type = "O", keep the $item_name for next item comparsion
|
| 320 | if ($item_type eq "O"){
|
| 321 | $last_item_name = $item_name;
|
| 322 | }
|
| 323 | }
|
| 324 | else{ #$timestamp_type eq "T_E"
|
| 325 | $mbis_end_timetable{$item_name} = "$item_type,$item_timestamp";
|
| 326 |
|
| 327 | # special handling for $item_type = "O", obj timestamp must side by side with T_S and T_E
|
| 328 | if ($item_type eq "O"){
|
| 329 | if ($last_item_name ne $item_name){
|
| 330 | logWarning("[WARNING] Unexpect timestamp for object : $item_name");
|
| 331 | }
|
| 332 | $last_item_name = "";
|
| 333 | }
|
| 334 | }
|
| 335 | }
|
| 336 | elsif ($line =~ /^Time Stamp/){
|
| 337 | #ignore title
|
| 338 | }
|
| 339 | else{
|
| 340 | logWarning("[WARNING] Unexpect mbis log line : $line");
|
| 341 | }
|
| 342 | }
|
| 343 | close(FILEHANDLE);
|
| 344 |
|
| 345 | foreach $item_name(@item_seq){
|
| 346 | # $item = "$item_type,$item_name"
|
| 347 | $item_start_time = getItemTimeStamp($mbis_start_timetable{$item_name});
|
| 348 | $item_end_time = getItemTimeStamp($mbis_end_timetable{$item_name});
|
| 349 | if (defined($item_end_time)){
|
| 350 | $item_duration_time = $item_end_time - $item_start_time;
|
| 351 | $item_type = getItemType($mbis_start_timetable{$item_name});
|
| 352 |
|
| 353 | # check if the item_type is match
|
| 354 | # still log the timestamp according to the start timestamp type
|
| 355 | if (getItemType($mbis_end_timetable{$item_name}) ne $item_type){
|
| 356 | logWarning("[WARNING] Type mismatch for item : $item_name");
|
| 357 | }
|
| 358 |
|
| 359 | # append to the log string
|
| 360 | #print "$item_name,$item_type,$item_start_time,$item_end_time,$item_duration_time\n";
|
| 361 | $log_str .= "$item_name,$item_type,$item_start_time,$item_end_time,$item_duration_time\n";
|
| 362 |
|
| 363 | # clean the value of $mbis_end_timetable{$item_name} for checking single T_E
|
| 364 | $mbis_end_timetable{$item_name} = undef;
|
| 365 | }
|
| 366 | else{
|
| 367 | # check if just T_S but no T_E
|
| 368 | logWarning("[WARNING] Single T_S of $item_name");
|
| 369 | }
|
| 370 | }
|
| 371 |
|
| 372 | # check if just T_E but no T_S
|
| 373 | @mbis_end_timetable_key = keys %mbis_end_timetable;
|
| 374 | foreach $item_name(@mbis_end_timetable_key){
|
| 375 | if (defined($mbis_end_timetable{$item_name})){
|
| 376 | logWarning("[WARNING] Single T_E of $item_name");
|
| 377 | }
|
| 378 | }
|
| 379 |
|
| 380 | # write the log string to the log file
|
| 381 | if (defined($log_str)){
|
| 382 | open(FILEHANDLE, ">$ENV{MBIS_BUILD_TIME_LOG}") or die "cannot open file for writing: $!";
|
| 383 | print FILEHANDLE "Item Name,Type,Start Time,End Time,Duration Time\n";
|
| 384 | print FILEHANDLE "$log_str";
|
| 385 | close(FILEHANDLE);
|
| 386 | }
|
| 387 | }#if ($mbis_enable)
|
| 388 | }
|
| 389 |
|
| 390 |
|
| 391 | #*****************************************************************************
|
| 392 | # Internal Subroutine Definition
|
| 393 | #*****************************************************************************
|
| 394 | sub logToInfoFile{
|
| 395 | open FILEHANDLE, ">>$ENV{MBIS_BUILD_INFO_LOG}";
|
| 396 | print FILEHANDLE "$_[0]\n";
|
| 397 | close FILEHANDLE;
|
| 398 | }
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 | sub logToTimeStampFile{
|
| 403 | open FILEHANDLE, ">>$ENV{MBIS_BUILD_TIME_LOG}";
|
| 404 | print FILEHANDLE "$_[0]\n";
|
| 405 | close FILEHANDLE;
|
| 406 | }
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 | sub logToTimeStampTempFile{
|
| 411 | my $datetime = time;
|
| 412 | open FILEHANDLE, ">>$ENV{MBIS_BUILD_TIME_TMP}";
|
| 413 | print FILEHANDLE "$_[0],$datetime\n";
|
| 414 | close FILEHANDLE;
|
| 415 | }
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 | sub logFileIntoTimeStampTempFile{
|
| 420 | my $file_path = $_[0];
|
| 421 | my $line;
|
| 422 | open FILEHANDLE, ">>$ENV{MBIS_BUILD_TIME_TMP}";
|
| 423 | open INPUT, $file_path or die "cannot open source file: $!";
|
| 424 | foreach $line (<INPUT>){
|
| 425 | print FILEHANDLE $line;
|
| 426 | }
|
| 427 | close INPUT;
|
| 428 | close FILEHANDLE;
|
| 429 | }
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 | sub logWarning{
|
| 434 | return 0;
|
| 435 | # open FILEHANDLE, ">>mbis_warning.log";
|
| 436 | # print FILEHANDLE "$_[0]\n";
|
| 437 | # close FILEHANDLE;
|
| 438 | }
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 | sub trim{
|
| 443 | if (defined($_[0])){
|
| 444 | my $item = $_[0];
|
| 445 | $item =~ s/(^\s+)|(\s+$)//g;
|
| 446 | return $item;
|
| 447 | }
|
| 448 | else{
|
| 449 | return undef;
|
| 450 | }
|
| 451 |
|
| 452 | }
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 | sub getItemTimeStamp{
|
| 457 | if (defined($_[0])){
|
| 458 | my $item = $_[0];
|
| 459 | $item =~ /(?:\w+),(\w+)/;
|
| 460 | return $1;
|
| 461 | }
|
| 462 | else{
|
| 463 | return undef;
|
| 464 | }
|
| 465 | }
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 | sub getItemType{
|
| 470 | if (defined($_[0])){
|
| 471 | my $item = $_[0];
|
| 472 | $item =~ /(\w+),\w+/;
|
| 473 | return $1;
|
| 474 | }
|
| 475 | else{
|
| 476 | return undef;
|
| 477 | }
|
| 478 | }
|
| 479 |
|
| 480 | sub notify_owner{
|
| 481 | #skip notify owner
|
| 482 | return 0;
|
| 483 |
|
| 484 | if (!-e "$mbis_config_ini") {
|
| 485 | warn "Skip mbis log files. Build process is DONE.\n";
|
| 486 | exit 0;
|
| 487 | }
|
| 488 | my %mbis_conf = iniToHash($mbis_config_ini);
|
| 489 | my $smtp = $mbis_conf{'NOTIFY_INFO'}->{'SMTP'};
|
| 490 | my $admin_email = $mbis_conf{'NOTIFY_INFO'}->{'MBIS_ADMIN_MAIL'};
|
| 491 | my $notify_owner_email = $mbis_conf{'NOTIFY_INFO'}->{'MBIS_NOTIFY_MAIL'};
|
| 492 | my $message_body="";
|
| 493 |
|
| 494 | print "Notify MBIS Service Owner...";
|
| 495 | chomp(my $cwd = cwd());
|
| 496 | my ($infolog,$timelog,$infotmp,$upload_log) = @_;
|
| 497 |
|
| 498 | if(-e "$upload_log")
|
| 499 | {
|
| 500 | open (LOG_FILE, "<$upload_log") or warn "cannot open $upload_log!\n";
|
| 501 | $backup = $/;
|
| 502 | undef $/;
|
| 503 | $message_body = <LOG_FILE>;
|
| 504 | $/ = $backup;
|
| 505 | close LOG_FILE;
|
| 506 | }
|
| 507 |
|
| 508 | $msg = MIME::Lite->new(
|
| 509 | From => $admin_email,
|
| 510 | To => $notify_owner_email,
|
| 511 | Subject => '[MBIS Notify] MBIS log files upload Failed',
|
| 512 | Type => 'multipart/mixed'
|
| 513 | );
|
| 514 |
|
| 515 | $msg->attach(Type => 'auto',Path => $cwd."/".$infolog,);
|
| 516 | $msg->attach(Type => 'auto',Path => $cwd."/".$timelog,);
|
| 517 | $msg->attach(Type => 'auto',Path => $cwd."/".$infotmp,);
|
| 518 |
|
| 519 | $msg->attach (
|
| 520 | Type => 'TEXT',
|
| 521 | Data => $message_body
|
| 522 | ) or warn "Error adding the text message part: $!\n";
|
| 523 |
|
| 524 | $msg->send('smtp', $smtp, Timeout => 60);
|
| 525 | print "Done\n";
|
| 526 | }
|
| 527 |
|
| 528 | sub iniToHash {
|
| 529 | open(MYINI, $_[0]);
|
| 530 | my %hash;
|
| 531 | my $hashref;
|
| 532 |
|
| 533 | while(<MYINI>)
|
| 534 | {
|
| 535 | next if ((/^\s*$/) || (/^\s*#/));
|
| 536 | if (/^\s*\[(.+)\]/)
|
| 537 | {
|
| 538 | $hashref = $hash{$1} ||= {};
|
| 539 | }
|
| 540 | elsif (/^\s*(\S+)\s*=\s*(.+)\s*$/)
|
| 541 | {
|
| 542 | $hashref->{$1} = $2;
|
| 543 | }
|
| 544 | elsif (/^\s*(\S+)\s*\+=\s*(.+)\s*$/)
|
| 545 | {
|
| 546 | $hashref->{$1} = $hashref->{$1} . " $2";
|
| 547 | }
|
| 548 | }
|
| 549 |
|
| 550 | close MYINI;
|
| 551 | return %hash;
|
| 552 | }
|
| 553 |
|
| 554 | 1;
|