modificato left join per vedere anche tools orfani e senza nodi

This commit is contained in:
2018-05-17 22:48:29 +02:00
parent a7261e0b9b
commit 2d966e2ada
2 changed files with 82 additions and 5 deletions

View File

@@ -41,7 +41,7 @@ $email_msg = <<"END_MSG";
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">
<tr>
<td align="center" bgcolor="#fff" style="padding: 10px 0 10px 0;">
<img src="http://www.aseltd.eu/img/logo_ASE_small.png" alt="ASE" style="display: block;" />
<img src="http://aseadmin.aseltd.eu/img/logo_ASE_small.png" alt="ASE" style="display: block;" />
</td>
</tr>
<tr>

View File

@@ -8,6 +8,7 @@ use File::Basename qw( fileparse );
use List::Util qw( max );
use Data::Dumper qw(Dumper);
use Cwd;
use Mail::Sender;
$|++; # Autoflush
@@ -41,6 +42,8 @@ my ($unit_id, $unit, $unittype);
my ($fileDate, $fileTime);
my $matlab_rt = "/usr/local/MATLAB/MATLAB_Runtime/v93";
my $matlab_func_dir = "/usr/local/matlab_func/";
my $email_addr = 'andrea.carri@aseltd.eu,alessandro.battilani@gmail.com';
my ($email_msg, $email_obj);
sub getTimeStamp
{ # parm [ts] => timestamp for filename; log => timestamp for log
@@ -108,14 +111,21 @@ sub matlabCalc {
chdir($matlab_func_dir)
or die "cannot change: $!\n";
my @args = ( $matlab_cmd, $matlab_rt, $unit, $tool);
system(@args) == 0
or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" );
if (system(@args) != 0) {
makeEmailMsg();
emailSend();
print getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n";
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";
exit(1);
}
} else {
$matlab_cmd = 'matlab_' . uc $matlab_cmd . '.cmd';
my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`;
if (index($out_matlab[-1], "Failure") != -1) {
print getTimeStamp("log")
. " - pid $$ >> $tool MatLab calc failed.\n";
makeEmailMsg();
emailSend();
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";
exit(1);
}
@@ -177,11 +187,11 @@ sub trxelab {
select * from (
select 'ToolNameID', 'EventDate', 'EventTime', 'NodeNum', 'NodeType', 'NodeDepth',
'XShift', 'YShift', 'ZShift' , 'X', 'Y', 'Z', 'HShift', 'HShiftDir', 'HShift_local',
'speed', 'speed_local', 'acceleration', 'acceleration_local', 'T_node', 'water_level', 'pressure', 'load_value'
'speed', 'speed_local', 'acceleration', 'acceleration_local', 'T_node', 'water_level', 'pressure', 'load_value', 'AlfaX', 'AlfaY', 'CalcErr'
union all
select ToolNameID, EventDate, EventTime, NodeNum, NodeType, NodeDepth,
XShift, YShift, ZShift , X, Y, Z, HShift, HShiftDir, HShift_local,
speed, speed_local, acceleration, acceleration_local, T_node, water_level, pressure, load_value
speed, speed_local, acceleration, acceleration_local, T_node, water_level, pressure, load_value, AlfaX, AlfaY, calcerr
from ElabDataView
where ToolNameID = '$tool' and updated_at > '$matlab_timestamp'
order by ToolNameID DESC, EventDate, EventTime, convert(`NodeNum`, decimal) DESC
@@ -338,6 +348,72 @@ sub getMatlabCmd {
return;
}
sub makeEmailMsg {
$email_msg = <<"END_MSG";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Alert from ASE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">
<tr>
<td align="center" bgcolor="#fff" style="padding: 10px 0 10px 0;">
<img src="http://aseadmin.aseltd.eu/img/logo_ASE_small.png" alt="ASE" style="display: block;" />
</td>
</tr>
<tr>
<td bgcolor="#ffffff" style="padding: 10px 10px 10px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="padding: 10px 10px 10px 10px;">
Alert from ASE: <BR>
Matlab function $matlab_cmd failed on unit => $unit - tool => $tool
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
END_MSG
}
sub emailSend {
$email_obj = 'Matlab error on unit ' . $unit . ' - tool ' . $tool;
my $sender = new Mail::Sender {
auth => 'PLAIN',
authid => 'ase.mums.alert@gmail.com',
authpwd => 'ASE@mums!',
smtp => 'smtp.gmail.com',
port => 587,
from => 'ASE Alert System',
to => $email_addr,
subject => $email_obj,
msg => $email_msg,
ctype => "text/html",
encoding => "7bit"
};
my $mail_res = $sender->MailMsg({msg => $sender->{msg},});
if (ref($mail_res) ne "Mail::Sender") {
print getTimeStamp("log") . " - pid $$ >> $mail_res: $sender->{error_msg} \n";
} else {
print getTimeStamp("log") . " - pid $$ >> $email_obj\n";
print getTimeStamp("log") . " - pid $$ >> Mail sent to: $email_addr.\n";
}
}
my $starttime = getTimeStamp("log");
print "$starttime - pid $$ >> Start execution.\n";
@@ -366,6 +442,7 @@ if ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)_\d*$/i ) {
($unittype, $unit ) = split( /\s/, uc <FILE> );
$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];