1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
| #!/usr/local/nagios/ActivePerl-5.10/bin/perl
#This script call others scripts to treat and export .log file
#into csv files, to trace an order
#Files we want to treat and export :
# - P12_recv_20100713_joined.log
# - P10_send_20100713_joined.log
# - slev5fix_recv_20100713_joined.log
# - EMIS7_FIX_20100713.log
# - RECEP7_FIX_20100713.log
# - slev5fixfixfix_send_20100713_joined.log
# - P10_recv_20100713_joined.log
# - P12_send_20100713_joined.log
#Date : July 2010
#@author : Olivier ### (mail supprimé)
###########################################################################
#use lib "/usr/local/nagios/libexec/gt.hkg/perlModules" ;
use Config::IniFiles;
use strict;
use warnings;
#get the time yyyymmdd
sub getTime {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
$year += 1900;
$mon +=1;
my $mon_= $mon;
my $mday_ = $mday;
if ($mon < 10) {
$mon_ = join "","0", "$mon";
}
if ($mday < 10) {
$mday_ = join "","0", "$mday";
}
my $time_= join "","$year","$mon_","$mday_";
return $time_;
}
my @listOfcsvFiles = glob('*.csv');
#print "listOfCsvFiles : @listOfcsvFiles\n";
#get from the precedent list of .csv file the one
#we specified as a parameter
# PLE (ajout de la lecture du fichier dans la référence de tableau fournie)
sub getFile {
my ($fileName, $matrix_ref) = @_;
if (my ($file) = grep /$fileName/, @listOfcsvFiles) {
open my $FILE, "+<", $file or die "Couldn't open file , $file $! \n";
while(<$FILE>) {
push @$matrix_ref, [ split /,/ ];
}
}
else {
die "Couldn't open find any file containing [$fileName]\n";
}
}
# PLE Pas utilisé (ne disposant pas de slev5fix.ini, je saute cette partie
if (0) {
###########################################
######## HASH CREATION ############
###########################################
my $path = $ENV{PWD};
my $iniFile = join "","$path","/","slev5fix.ini";
my $cfg = new Config::IniFiles -file => "$iniFile" or die "Config::IniFile method new failed\n";
my %arrayOfSession= ();
for ( my $i= 1; $i <=37; $i++) {
my $sessionName = join "","ROUTING_SESSION","$i";
my $sessionId = $cfg -> val($sessionName,"sessionid");
my $cle = $sessionId;
my $FixProtocolId = $cfg -> val("$sessionName","FIXConnection");
#print "sessionId : $sessionId FixProtocolId : $FixProtocolId\n ";
#%arrayOfSession = ("$sessionId" => "$FixProtocolId" );
$arrayOfSession{$cle} = $FixProtocolId;
}
#foreach my $k (keys(%arrayOfSession))
#{
# print "Clef=$k Valeur=$arrayOfSession{$k}\n";
#}
}
###########################################
######## FILEHANDLE #################
###########################################
my $theTime = &getTime;
my $outName = join "", "entrelacement", "_", "$theTime", ".csv";
open(OUTPUT,">$outName") or die "Couldn't open file , $outName $! \n";
# PLE Utilisation de l'opérateur qw() et de la fonction join
print OUTPUT join ",", qw(FileName OrderTime Node noUti command GLID clientAppliId exchangeOrderId localSLEOrderId localSLECommandId sessionId ExecType); # PLE
#print OUTPUT "FileName",",","OrderTime", ",","Node",",","noUti",",","command",",","GLID",",","clientAppliId",",","exchangeOrderId",",","localSLEOrderId",",","localSLECommandId",",","sessionId",",","ExecType";
print OUTPUT "\n";
my $counter = 0;
# PLE : la fonction getFile lit le fichier et range les données dans les tableaux
my (@P12_recv_lines, @P10_send_lines, @slev5fix_recv_lines, @emis1_lines, @recep1_lines, @emis2_lines, @recep2_lines,
@emis3_lines, @recep3_lines, @emis5_lines, @recep5_lines, @emis7_lines, @recep7_lines,
@slev5fix_send_lines, @P10_recv_lines, @P12_send_lines);
#my (@emis4_lines, @recep4_lines, @emis6_lines, @recep6_lines, @emis8_lines, @recep8_lines);
######### P12 recv
getFile("output_P12_recv", \@P12_recv_lines);
######### P10 SEND
getFile("output_P10_send", \@P10_send_lines);
######### slev5fix_recv
getFile("output_slev5fix_recv", \@slev5fix_recv_lines);
######### EMIS1
#PLE getFile("output_EMIS1", \@emis1_lines);
######### RECEP1
#PLE getFile("output_RECEP1", \@recep1_lines);
######### EMIS2
#PLE getFile("output_EMIS2", \@emis2_lines);
######### RECEP2
#PLE getFile("output_RECEP2", \@recep2_lines);
######### EMIS3
#PLE getFile("output_EMIS3", \@emis3_lines);
######### RECEP3
#PLE getFile("output_RECEP3", \@recep3_lines);
########## EMIS4
#getFile("output_EMIS4", \@emis4_lines);
########## RECEP4
#getFile("output_RECEP4", \@recep4_lines);
######### EMIS5
#PLE getFile("output_EMIS5", \@emis5_lines);
######### RECEP5
#PLE getFile("output_RECEP5", \@recep5_lines);
########## EMIS6
#getFile("output_EMIS6", \@emis6_lines);
########## RECEP6
#getFile("output_RECEP6", \@recep6_lines);
######### EMIS7
getFile("output_EMIS7", \@emis7_lines);
######### RECEP7
getFile("output_RECEP7", \@recep7_lines);
########## EMIS8
#getFile("output_EMIS8", \@emis8_lines);
########## RECEP8
#getFile("output_RECEP8", \@recep8_lines);
######### slev5fix_send
getFile("output_slev5fix_send", \@slev5fix_send_lines);
######### P10 RECV
getFile("output_P10_recv", \@P10_recv_lines);
######### P12 SEND
getFile("output_P12_send", \@P12_send_lines);
###########################################
######## SUBRUTINE ##################
###########################################
# PLE creation d'une fonction générique de création d'index prenant en paramètre une liste de colonne servant de clés,
# PLE et une matrice. Le résultat est un hashage dans lequel la clé est l'assemblage des colonnes clés, et la valeur
# PLE une référence de la ligne de la matrice correspondante
sub createIndex {
my ($matrix_ref, $key_cols_ref) = @_;
my $header = shift @$matrix_ref;
my %index = map {
(join ",", map { /^\d+$/ ? int($_) : $_ } @$_[@$key_cols_ref]) => $_; # le map converti les valeurs numériques texte en vraies valeurs numériques (sans 0 non significatif ; sauf le 0, cas rare)
} @$matrix_ref;
unshift @$matrix_ref, $header;
return %index;
}
my $no_more_needed = <<'IGNORE1';
sub getMatrice{
my @linesToTransform = @_;
shift(@linesToTransform);
my (%matrix, @tmp);
my $i;
foreach $i (@linesToTransform) {
@tmp= split(',',$i);
my $cle = join ",", @tmp[3..6];
$matrix{$cle} = [@tmp];
}
return %matrix;
}
sub getMatriceFIXEMIS{
my @linesToTransform = @_;
shift(@linesToTransform);
my (%matrix, @tmp);
my $i;
foreach $i (@linesToTransform) {
@tmp= split(',',$i);
my $cleFIXEMIS = join ",", $tmp[6];
$matrix{$cleFIXEMIS} = [@tmp];
}
return %matrix;
}
sub getMatriceExchangeOrderId{
my @linesToTransform = @_;
shift(@linesToTransform);
my (%matrix, @tmp);
my $i;
foreach $i (@linesToTransform) {
@tmp= split(',',$i);
my $cleEOI = join ",", $tmp[7];
$matrix{$cleEOI} = [@tmp];
}
return %matrix;
}
sub getMatriceSLECommandId{
my @linesToTransform = @_;
shift(@linesToTransform);
my (%matrix, @tmp);
my $i;
foreach $i (@linesToTransform) {
@tmp= split(',',$i);
my $cleSLECID = join ",", $tmp[9];
$matrix{$cleSLECID} = [@tmp];
}
return %matrix;
}
IGNORE1
########### GETMATRICE (3..6)
# PLE Create indexes for keys in columns 3 to 6
my %matrixOfP12recv = createIndex(\@P12_recv_lines, [3..6]); # &getMatrice(@P12_recv_lines);
my %matrixOfP10send = createIndex(\@P10_send_lines, [3..6]); # &getMatrice(@P10_send_lines);
my %matrixOfslev5fixrecv = createIndex(\@slev5fix_recv_lines, [3..6]); # &getMatrice(@slev5fix_recv_lines);
my %matrixOfP10recv = createIndex(\@P10_recv_lines, [3..6]); # &getMatrice(@P10_recv_lines);
my %matrixOfP12send = createIndex(\@P12_send_lines, [3..6]); # &getMatrice(@P12_send_lines);
########### GETMATRICEFIXEMIS (6)
# PLE Create indexes for keys in column 6
my %matrixOfslev5fixrecvMap = createIndex(\@slev5fix_recv_lines, [6]); # &getMatriceFIXEMIS(@slev5fix_recv_lines);
my %matrixOfEmis1Map = createIndex(\@emis1_lines, [6]); # &getMatriceFIXEMIS(@emis1_lines);
my %matrixOfEmis3Map = createIndex(\@emis3_lines, [6]); # &getMatriceFIXEMIS(@emis3_lines);
my %matrixOfEmis7Map = createIndex(\@emis7_lines, [6]); # &getMatriceFIXEMIS(@emis7_lines);
########## GETMATRICE EOI (7)
# PLE Create indexes for keys in column 7
my %matrixOfemis1 = createIndex(\@emis1_lines, [7]); # &getMatriceExchangeOrderId(@emis1_lines);
my %matrixOfrecep1 = createIndex(\@recep1_lines, [7]); # &getMatriceExchangeOrderId(@recep1_lines);
my %matrixOfemis2 = createIndex(\@emis2_lines, [7]); # &getMatriceExchangeOrderId(@emis2_lines);
my %matrixOfrecep2 = createIndex(\@recep2_lines, [7]); # &getMatriceExchangeOrderId(@recep2_lines);
my %matrixOfemis3 = createIndex(\@emis3_lines, [7]); # &getMatriceExchangeOrderId(@emis3_lines);
my %matrixOfrecep3 = createIndex(\@recep3_lines, [7]); # &getMatriceExchangeOrderId(@recep3_lines);
#my %matrixOfemis4 = createIndex(\@emis4_lines, [7]); # &getMatriceExchangeOrderId(@emis4_lines);
#my %matrixOfrecep4 = createIndex(\@recep4_lines, [7]); # &getMatriceExchangeOrderId(@recep4_lines);
my %matrixOfemis5 = createIndex(\@emis5_lines, [7]); # &getMatriceExchangeOrderId(@emis5_lines);
my %matrixOfrecep5 = createIndex(\@recep5_lines, [7]); # &getMatriceExchangeOrderId(@recep5_lines);
#my %matrixOfemis6 = createIndex(\@emis6_lines, [7]); # &getMatriceExchangeOrderId(@emis6_lines);
#my %matrixOfrecep6 = createIndex(\@recep6_lines, [7]); # &getMatriceExchangeOrderId(@recep6_lines);
my %matrixOfemis7 = createIndex(\@emis7_lines, [7]); # &getMatriceExchangeOrderId(@emis7_lines);
my %matrixOfrecep7 = createIndex(\@recep7_lines, [7]); # &getMatriceExchangeOrderId(@recep7_lines);
#my %matrixOfemis8 = createIndex(\@emis8_lines, [7]); # &getMatriceExchangeOrderId(@emis8_lines);
#my %matrixOfrecep8 = createIndex(\@recep8_lines, [7]); # &getMatriceExchangeOrderId(@recep8_lines);
######### GETMATRICE SLECID (9)
# PLE Create indexes for keys in column 9
my %matrixOfslev5fix_sendSLECID = createIndex(\@slev5fix_recv_lines, [9]); # &getMatriceSLECommandId(@slev5fix_recv_lines);
my %matrixOfP10_recvSLECID = createIndex(\@P10_recv_lines, [9]); # &getMatriceSLECommandId(@P10_recv_lines);
###########################################
######## MAPPING ####################
###########################################
# List of keys to link matrixOfP10send, matrixOfslev5fixrecv, matrixOfP10recv, matrixOfP12send and matrixOfP12recv
my %cles;
my @cles = grep { exists $matrixOfP10send{$_} && exists $matrixOfslev5fixrecv{$_}
&& exists $matrixOfP10recv{$_} && exists $matrixOfP12send{$_}} keys %matrixOfP12recv;
#print "@cles\n";
my $no_more_used = <<'UNUSED';
## List of keys to link matrixOfslev5fixsend and matrixOfP10recv and matrixOfRecepX
#my %clesEOI;
#my @clesEOI = grep { exists $matrixOfslev5fixsendEOI{$_} && (exists $matrixOfRecep1EOI{$_} ||
# exists $matrixOfRecep3EOI{$_} || exists $matrixOfRecep7EOI{$_}) } keys %matrixOfP10recvEOI;
# List of keys to link matrixOfslev5fixsend and matrixOfP10recv and matrixOfRecepX
my %clesEOI;
my @clesEOI = (grep { exists $matrixOfemis1{$_} } keys %matrixOfrecep1)
&& (grep { exists $matrixOfemis3{$_} } keys %matrixOfrecep3)
&& (grep { exists $matrixOfemis7{$_} } keys %matrixOfrecep7);
# PLE Je ne vois pas comment @clesEOI peut contenir quelque chose d'exploitable : c'est une valeur booleenne rangée dans un tableau !
#print @clesEOI;
# List of keys to link matrixOfEmisX and matrixOfslev5fixrecv
my %clesFIXEMIS;
my @clesFIXEMIS = grep { exists $matrixOfEmis1Map{$_} || exists $matrixOfEmis3Map{$_}
|| exists $matrixOfEmis7Map{$_} } keys %matrixOfslev5fixrecvMap ;
# List of keys to link matrixOfslev5fix_sendSLECID and matrixOfslev5fix_sendSLECID
my %clesSLEID;
my @clesSLECID = grep { exists $matrixOfslev5fix_sendSLECID{$_} } keys %matrixOfslev5fix_sendSLECID ;
UNUSED
sub getCleClientAppliId { #field 6
my ($keytoget) = @_;
my @test =split(",", $keytoget);
#print "key to get : $test[3]\n";
return $test[3];
}
# PLE Creation d'une fonction retournant un texte à écrire à partir d'une ligne de tableau matrix
sub row2str {
my ($row) = @_;
return join ",", @$row;
}
#print @clesEOI;
my $indent=1;
# On boucle sur cette liste (contenant dans les clés du hash %cles)
foreach my $cle (@cles) {
print OUTPUT "Order Number : $indent";
print OUTPUT "\n";
my $EOItoGet = $matrixOfP12send{$cle}->[7];
my $SLECIDtoGet = $matrixOfP10recv{$cle}->[9];
if ($EOItoGet =~/^[ATE\s]/) { # PLE Simplification du test en 1 regexp
$EOItoGet = 0;
}
# PLE $splitkey ne dépend que de $cle :
# PLE ne pas le calculer dans une boucle où $cle ne varie pas (déplacer en dehors de la boucle)
my $splitkey = getCleClientAppliId($cle);
print OUTPUT row2str($matrixOfP12recv{$cle}) if exists $matrixOfP12recv{$cle};
print OUTPUT row2str($matrixOfP10send{$cle}) if exists $matrixOfP10send{$cle};
print OUTPUT row2str($matrixOfslev5fixrecv{$cle}) if exists $matrixOfslev5fixrecv{$cle};
print OUTPUT row2str($matrixOfEmis1Map{$splitkey}) if exists $matrixOfEmis1Map{$splitkey};
print OUTPUT row2str($matrixOfEmis3Map{$splitkey}) if exists $matrixOfEmis3Map{$splitkey};
print OUTPUT row2str($matrixOfEmis7Map{$splitkey}) if exists $matrixOfEmis7Map{$splitkey};
print OUTPUT row2str($matrixOfrecep1{$EOItoGet}) if exists $matrixOfrecep1{$EOItoGet};
print OUTPUT row2str($matrixOfrecep3{$EOItoGet}) if exists $matrixOfrecep3{$EOItoGet};
print OUTPUT row2str($matrixOfrecep7{$EOItoGet}) if exists $matrixOfrecep7{$EOItoGet};
print OUTPUT row2str($matrixOfslev5fix_sendSLECID{$SLECIDtoGet}) if exists $matrixOfslev5fix_sendSLECID{$SLECIDtoGet};
print OUTPUT row2str($matrixOfP10recv{$cle}) if exists $matrixOfP10recv{$cle};
print OUTPUT row2str($matrixOfP12send{$cle}) if exists $matrixOfP12send{$cle};
print OUTPUT "\n";
my $oldLoop = <<'OLDLOOP';
foreach my $cleFIXEMIS (@clesFIXEMIS) {
next unless ($cleFIXEMIS eq $splitkey) ;
foreach my $cleEOI (@clesEOI) {
next unless ($cleEOI == $EOItoGet );
foreach my $cleSLECID (@clesSLECID) {
next unless ($cleSLECID eq $SLECIDtoGet);
print OUTPUT (join ",", @{$matrixOfP12recv{$cle}}) if exists $matrixOfP12recv{$cle};
print OUTPUT (join ",", @{$matrixOfP10send{$cle}}) if exists $matrixOfP10send{$cle};
print OUTPUT (join ",", @{$matrixOfslev5fixrecv{$cle}}) if exists $matrixOfslev5fixrecv{$cle};
if ($matrixOfEmis1Map{$cleFIXEMIS}) {
print OUTPUT (join ",", @{$matrixOfEmis1Map{$cleFIXEMIS}});
} elsif ($matrixOfEmis3Map{$cleFIXEMIS}) {
print OUTPUT (join ",", @{$matrixOfEmis3Map{$cleFIXEMIS}});
} elsif ($matrixOfEmis7Map{$cleFIXEMIS}) {
print OUTPUT (join ",", @{$matrixOfEmis7Map{$cleFIXEMIS}});
}
if ($matrixOfrecep1{$cleEOI}) {
print OUTPUT (join ",", @{$matrixOfrecep1{$cleEOI}});
} elsif ($matrixOfrecep3{$cleEOI}) {
print OUTPUT (join ",", @{$matrixOfrecep3{$cleEOI}});
} elsif ($matrixOfrecep7{$cleEOI}) {
print OUTPUT (join ",", @{$matrixOfrecep7{$cleEOI}});
}
print OUTPUT (join ",", @{$matrixOfslev5fix_sendSLECID{$cleSLECID}}) if exists $matrixOfslev5fix_sendSLECID{$cleSLECID};
print OUTPUT (join ",", @{$matrixOfP10recv{$cle}}) if exists $matrixOfP10recv{$cle};
print OUTPUT (join ",", @{$matrixOfP12send{$cle}}) if exists $matrixOfP12send{$cle};
print OUTPUT "\n";
}
}
}
OLDLOOP
$indent++;
}
__END__
#PLE unused function
sub getCommandValue {
my ($valueToAnalyze) = @_;
if ($valueToAnalyze =~ /48/) {
return 48;
} elsif ($valueToAnalyze =~ /49/) {
return 49;
} elsif ($valueToAnalyze =~ /50/) {
return 50;
}
} |
Partager