diff --git a/.gitignore b/.gitignore index 34b9c14..69558dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ prova.pl prova_mail.pl UnitCSVReceiver -prova.log \ No newline at end of file +prova.log +.vstags diff --git a/AlertNotReceived.pl b/AlertNotReceived.pl index 65a8d40..6d7672d 100644 --- a/AlertNotReceived.pl +++ b/AlertNotReceived.pl @@ -121,17 +121,18 @@ if ($sth->rows < 0) { print getLoggingTime() . " - No rows from TOOLS & UNITS.\n"; } else { while (my $results = $sth->fetchrow_hashref) { - $ToolName{$results->{'ToolNameID'}}{'idCompany'} = $results->{'idCompany'}; - $ToolName{$results->{'ToolNameID'}}{'CompanyNameShort'} = $results->{'CompanyNameShort'}; - $ToolName{$results->{'ToolNameID'}}{'SiteName'} = $results->{'SiteName'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'idCompany'} = $results->{'idCompany'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'CompanyNameShort'} = $results->{'CompanyNameShort'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'SiteName'} = $results->{'SiteName'}; $ToolName{$results->{'idCompany'}}{'CompanyEmail'} = $results->{'CompanyEmail'}; $ToolName{$results->{'idCompany'}}{'SendAlarm'} = $results->{'SendAlarm'}; - $ToolName{$results->{'ToolNameID'}}{'UnitNameId'} = $results->{'UnitNameId'}; - $ToolName{$results->{'ToolNameID'}}{'ToolState'} = $results->{'ToolState'}; - $ToolName{$results->{'ToolNameID'}}{'LettureNodi'} = "--"; - $ToolName{$results->{'ToolNameID'}}{'LettureCatene'} = "--"; - $ToolName{$results->{'ToolNameID'}}{'NumeroNodi'} = "--"; - $ToolName{$results->{'ToolNameID'}}{'ErroriTotaliLetture'} = "--"; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'UnitNameId'} = $results->{'UnitNameId'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'ToolNameID'} = $results->{'ToolNameID'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'ToolState'} = $results->{'ToolState'}; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'LettureNodi'} = "--"; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'LettureCatene'} = "--"; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'NumeroNodi'} = "--"; + $ToolName{$results->{UnitNameId} . $results->{'ToolNameID'}}{'ErroriTotaliLetture'} = "--"; if ($results->{'ToolState'} eq "Active" ){ $act_tool++; } @@ -145,7 +146,7 @@ $dbh->disconnect; $dbh = DBI->connect("DBI:mysql:$database;host=$server", $username, $password) or die getLoggingTime() . " - Could not connect to database: $DBI::errstr"; -my $stw = $dbh->prepare("select ToolNameID, EventDate, count(EventTime) 'LettureNodi', truncate(Count(EventTime)/max(NodeNum),1) 'LettureCatene', max(NodeNum) 'NumeroNodi' from RAWDATACOR where EventDate = subdate(curdate(),1) group by ToolNameID") +my $stw = $dbh->prepare("select UnitName, ToolNameID, EventDate, count(EventTime) 'LettureNodi', truncate(Count(EventTime)/max(NodeNum),1) 'LettureCatene', max(NodeNum) 'NumeroNodi' from RAWDATACOR where EventDate = subdate(curdate(),1) group by UnitName, ToolNameID") or die getLoggingTime() . " - $DBI::errstr"; $stw->execute(); @@ -154,9 +155,9 @@ if ($stw->rows == 0) { $email_obj = "ATTENZIONE: nessuna lettura pervenuta!!!" } else { while (my $results = $stw->fetchrow_hashref) { - $ToolName{$results->{'ToolNameID'}}{'LettureNodi'} = $results->{'LettureNodi'}; - $ToolName{$results->{'ToolNameID'}}{'LettureCatene'} = $results->{'LettureCatene'}; - $ToolName{$results->{'ToolNameID'}}{'NumeroNodi'} = $results->{'NumeroNodi'}; + $ToolName{$results->{'UnitName'} . $results->{'ToolNameID'}}{'LettureNodi'} = $results->{'LettureNodi'}; + $ToolName{$results->{'UnitName'} . $results->{'ToolNameID'}}{'LettureCatene'} = $results->{'LettureCatene'}; + $ToolName{$results->{'UnitName'} . $results->{'ToolNameID'}}{'NumeroNodi'} = $results->{'NumeroNodi'}; $ref_date = $results->{'EventDate'}; if (substr($results->{'ToolNameID'},0,2) eq "GD" ){ $gd_tool++; @@ -172,12 +173,12 @@ if ($stw->rows == 0) { $stw->finish; -my $ste = $dbh->prepare("select ToolNameID, count(val0) 'ErroriTotaliLetture' from RAWDATACOR where EventDate = ? and val0 = 'Err1' group by ToolNameID") +my $ste = $dbh->prepare("select UnitName, ToolNameID, count(val0) 'ErroriTotaliLetture' from RAWDATACOR where EventDate = ? and val0 = 'Err1' group by ToolNameID") or die getLoggingTime() . " - $DBI::errstr"; $ste->bind_param(1, $ref_date); $ste->execute(); while (my $results = $ste->fetchrow_hashref) { - $ToolName{$results->{'ToolNameID'}}{'ErroriTotaliLetture'} = $results->{'ErroriTotaliLetture'}; + $ToolName{$results->{'UnitName'} . $results->{'ToolNameID'}}{'ErroriTotaliLetture'} = $results->{'ErroriTotaliLetture'}; } $ste->finish; @@ -193,7 +194,7 @@ foreach my $tool (sort grep { /DT|PT/ } keys %ToolName){ } my $tool_part = "" . $ToolName{$tool}{'CompanyNameShort'} . "". $ToolName{$tool}{'SiteName'} . ""; - $tool_part .= "" . $ToolName{$tool}{'UnitNameId'} . "" . $tool . ""; + $tool_part .= "" . $ToolName{$tool}{'UnitNameId'} . "" . $ToolName{$tool}{ToolNameID} . ""; $tool_part .= "" . $ToolName{$tool}{'LettureNodi'} . "" . $ToolName{$tool}{'NumeroNodi'} . ""; $tool_part .= "" . $ToolName{$tool}{'LettureCatene'} . ""; $tool_part .= "" . $ToolName{$tool}{'ErroriTotaliLetture'} . "" . $ToolName{$tool}{'ToolState'} . "\n"; diff --git a/LoadCSVData.pl b/LoadCSVData.pl index c19c710..e7444bf 100644 --- a/LoadCSVData.pl +++ b/LoadCSVData.pl @@ -41,9 +41,10 @@ my ($fileDate, $fileTime); my $matlab_rt = "/usr/local/MATLAB/MATLAB_Runtime/v93"; my $matlab_func_dir = "/usr/local/matlab_func/"; my $matlab_error = ''; -my $matlab_timeout = '1200'; -my $email_addr = 'andrea.carri@aseltd.eu,roberto.savi@aseltd.eu,alessandro.battilani@gmail.com'; +my $matlab_timeout = '1800'; +my $email_addr = 'andrea.carri@aseltd.eu,roberto.savi@aseltd.eu,edoardo.cavalca@aseltd.eu,alessandro.battilani@gmail.com,alessandro.valletta@aseltd.eu'; my ($email_msg, $email_obj); +my $G201_fcheck = 0; sub getTimeStamp{ # parm [ts] => timestamp for filename; log => timestamp for log @@ -411,20 +412,17 @@ if ( $db_name ne 'asega' ) { } my ( $filecsvname, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ ); - if ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)_\d*$/i ) { ($fileDate, $fileTime) = split( /\s/, ); ($unittype, $unit ) = split( /\s/, uc ); $unit =~ s/;+$//; -} elsif ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)_\d*$/i ) { - - # da mettere il controllo ^^^^^^^^^^^^^^^ se ha mese ed anno all'inivio - my @strings = $filecsvname =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/; - $fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2]; - $fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5]; - $unittype = $strings[6]; - $unit = $strings[7]; - $tool = $strings[8]; +} elsif ( $filecsvname =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) { + my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; + $unittype = $strings[0]; + $unit = $strings[1]; + $tool = $strings[2]; + $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5];; + $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'MUX'; } @@ -454,6 +452,11 @@ while ( my $line = ) { $NodeData =~ s/;+$//; #$NodeData =~ s/\r\n\z//; + if ($unittype eq 'G201' and $G201_fcheck eq 0) { + print getTimeStamp("log"). " - pid $$ >> Found $tooltype tool name: $tool\n"; + getNodesType(); + $G201_fcheck = 1; + } if ( $tooltype eq "MUX" ) { diff --git a/UnitCsvReceiverSmart.pl b/UnitCsvReceiverSmart.pl index 8377b29..32d5b9a 100644 --- a/UnitCsvReceiverSmart.pl +++ b/UnitCsvReceiverSmart.pl @@ -30,12 +30,12 @@ sub getUnitName { # parm => file received ($trfile) my ( $fileDate, $fileTime ); my ( $unittype, $unit ); my ( $filenamecsv, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ ); - if ( $filenamecsv =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)$/i ) { # GD201 - my @strings = $filenamecsv =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/; - $fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2];; - $fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5]; - $unittype = $strings[6]; - $unit = $strings[7]; + if ( $filenamecsv =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { # GD201 + my @strings = $filenamecsv =~ /(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; + $unittype = $strings[0]; + $unit = $strings[1]; + $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5];; + $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; } else { open FILE, $filename or warn getTimeStamp("log") . " >> Error: opening input file $filename\n"; @@ -69,15 +69,13 @@ while ( my $line = $tail->GetLine() ) { or warn getTimeStamp("log") . " >> $truser not in passwd file.\n"; my ( $filename, $path, $suffix ) = fileparse( $trfile, qr/\.[^.]*/ ); - if ( $path eq "/" ) { - $path = "/home/" . $truser . "/"; - $trfile = "/home/" . $truser . $trfile; - } + $path = "/home/" . $truser . "/"; + $trfile = "/home/" . $truser . $trfile; if ( ( ( uc $suffix ) eq ( uc $ext ) ) and ( $filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d*|GD\d*)$/i - or $filename =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)$/i) ) + or $filename =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i) ) { my $unit = getUnitName($trfile); print getTimeStamp("log") . " >> Unit $unit - Filename $trfile\n"; @@ -109,7 +107,7 @@ while ( my $line = $tail->GetLine() ) { my @fname = ($dest); chown $uid, $gid, @fname; if ( ($filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)$/i - or $filename =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)$/i) + or $filename =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i) and ( $unit ne 'ID9999' ) and ( $truser ne 'corra' ) ) {