Sync from remote server: 2025-10-12 18:56:41
This commit is contained in:
249
Tilt/Report_ASE.m
Executable file
249
Tilt/Report_ASE.m
Executable file
@@ -0,0 +1,249 @@
|
||||
function Report_ASE(IDcentralina,unitID,chainID,alarms,Chain_Scheme,num_nodi,...
|
||||
Users_Report,Mail,time,activeEN,siteID,conn,FileName)
|
||||
% Software per la generazione automatica di report sull'attività di
|
||||
% monitoraggio ASE
|
||||
|
||||
% try
|
||||
|
||||
diary on
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
text = 'report_ASE function started';
|
||||
fprintf(fileID,fmt,text);
|
||||
fclose(fileID);
|
||||
|
||||
RPT_ON = 0; % parametro che regola la creazione o meno del report
|
||||
NomeFile = strcat('Report',siteID,'.txt');
|
||||
meseadesso = str2double(datestr(today,'mm'));
|
||||
if isfile(NomeFile) == 1 % Esiste
|
||||
|
||||
% Scarico la frequenza del report
|
||||
comando = ['select freq_report from sites where id like ''' siteID ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
Freq = cell2mat(curs.Data);
|
||||
numgiorni = Freq;
|
||||
|
||||
Filetesto = importdata(NomeFile);
|
||||
[rTXT,~] = size(Filetesto);
|
||||
if rTXT > 1
|
||||
datainvio = Filetesto(1,1); % mese di invio OPPURE data di ultimo invio
|
||||
attivaReport = Filetesto(2,1);
|
||||
else % file txt vuoto
|
||||
if numgiorni == 30
|
||||
datainvio = str2double(datestr(today,'mm'))+1; % mese successivo
|
||||
else
|
||||
datainvio = now;
|
||||
end
|
||||
attivaReport = 1; % report disattivato
|
||||
end
|
||||
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
text = ['Report frequency:' num2str(numgiorni) ' days'];
|
||||
fprintf(fileID,fmt,text);
|
||||
fclose(fileID);
|
||||
|
||||
if numgiorni == 30
|
||||
adesso = str2double(datestr(today,'mm'));
|
||||
if datainvio == adesso
|
||||
RPT_ON = 1;
|
||||
end
|
||||
else
|
||||
adesso = now;
|
||||
if adesso >= datainvio + numgiorni
|
||||
RPT_ON = 1;
|
||||
end
|
||||
end
|
||||
|
||||
if RPT_ON == 1 && attivaReport == 0
|
||||
try
|
||||
attivaReport = 1;
|
||||
outdat = fopen(NomeFile,'wt+');
|
||||
fopen(NomeFile,'wt');
|
||||
fmt = '%d \r';
|
||||
fileID = fopen(NomeFile,'a');
|
||||
fprintf(fileID,fmt,meseadesso);
|
||||
fprintf(fileID,fmt,attivaReport);
|
||||
fclose(fileID);
|
||||
|
||||
% salvo variabili da caricare in Report
|
||||
nomevar = ['variabili_RPT' siteID '.mat'];
|
||||
save(nomevar, 'unitID', 'chainID', 'alarms', 'Chain_Scheme', 'num_nodi', 'Users_Report', 'Mail', ...
|
||||
'time', 'meseadesso', 'adesso', 'datainvio', 'numgiorni', 'activeEN', 'FileName');
|
||||
|
||||
rilancio = ['/usr/local/matlab_func/run_Report_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '...
|
||||
siteID ''];
|
||||
|
||||
status = system(rilancio);
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
fprintf(fileID,fmt,status);
|
||||
catch err
|
||||
FileErr = ['ErrorFile-Report-' siteID '-' datestr(today) '-' datestr(now,'hhMMss')];
|
||||
fid = fopen(FileErr,'a+');
|
||||
fprintf(fid, '%s', err.getReport('extended','hyperlinks','off'));
|
||||
fclose(fid);
|
||||
|
||||
%% Email
|
||||
setpref('Internet','E_mail','alert@aseltd.eu');
|
||||
setpref('Internet','SMTP_Server','smtps.aruba.it');
|
||||
setpref('Internet','SMTP_Username','alert@aseltd.eu');
|
||||
setpref('Internet','SMTP_Password','Ase#2013!20@bat');
|
||||
props=java.lang.System.getProperties;
|
||||
pp=props.setProperty('mail.smtp.auth','true'); %#ok
|
||||
pp=props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory'); %#ok
|
||||
pp=props.setProperty('mail.smtp.socketFactory.port','465'); %#ok
|
||||
|
||||
% Uso il siteID per identificare il nome del sito
|
||||
comando = ['select name from sites where id like ''' siteID ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
NomeSito = num2str(cell2mat(curs.Data));
|
||||
|
||||
subject_ITA = ('CRASH funzione Report');
|
||||
testo = cellstr('Ciao Andrea e Alessandro,');
|
||||
testobis = cellstr('');
|
||||
testo2 = cellstr(['Il mostro biblico della funzione Report ha al proprio interno qualche minchiata '...
|
||||
'per cui il SW crasha nel realizzare il report di ' NomeSito '. Vi prego di correggermi '...
|
||||
'o continuer' char(243) ' a crashare e ad assillarvi con questa mail. BUAHAHAH! Troverete l''errore in allegato.']);
|
||||
message_ITA = [testo; testobis; testo2];
|
||||
message = cellstr('Tanti Blip e Blop a voi, ');
|
||||
message2 = cellstr('Software Tilt');
|
||||
message_ITA = [message_ITA; message; message2];
|
||||
|
||||
recipients_ASE{1,1} = 'alessandro.valletta@aseltd.eu';
|
||||
recipients_ASE{2,1} = 'andrea.carri@aseltd.eu';
|
||||
|
||||
allegato = FileErr;
|
||||
|
||||
sendmail(recipients_ASE, subject_ITA, message_ITA, allegato)
|
||||
|
||||
end
|
||||
end
|
||||
else
|
||||
datainvio = meseadesso+1;
|
||||
if datainvio > 12
|
||||
datainvio = datainvio-12;
|
||||
end
|
||||
end
|
||||
%% --- Modifica file di testo --- %%%
|
||||
if numgiorni == 30
|
||||
if datainvio == 12
|
||||
nuovofile = 1;
|
||||
elseif datainvio == 13
|
||||
nuovofile = 13;
|
||||
else
|
||||
nuovofile = adesso+1;
|
||||
end
|
||||
else
|
||||
nuovofile = datainvio + numgiorni;
|
||||
end
|
||||
attivaReport = 0;
|
||||
outdat = fopen(NomeFile,'wt+');
|
||||
fopen(NomeFile,'wt');
|
||||
fmt = '%d \r';
|
||||
fileID = fopen(NomeFile,'a');
|
||||
fprintf(fileID,fmt,nuovofile);
|
||||
fprintf(fileID,fmt,attivaReport);
|
||||
fclose(fileID);
|
||||
|
||||
% catch err
|
||||
% FileErr = ['ErrorFile-' IDcentralina '-' datestr(today) '-' datestr(now,'hhMMss') '.txt'];
|
||||
% fid = fopen(FileErr,'a+');
|
||||
% fprintf(fid, '%s', err.getReport('extended','hyperlinks','off'));
|
||||
% fclose(fid);
|
||||
%
|
||||
% % Scarico la frequenza del report
|
||||
% comando = ['select freq_report from sites where id like ''' siteID ''' '];
|
||||
% curs = exec(conn,comando);
|
||||
% curs = fetch(curs);
|
||||
% Freq = cell2mat(curs.Data);
|
||||
% numgiorni = Freq;
|
||||
% meseadesso = str2double(datestr(today,'mm'));
|
||||
%
|
||||
% NomeFile = strcat('Report',siteID,'.txt');
|
||||
%
|
||||
% if isfile(NomeFile) == 1 % Esiste
|
||||
% Filetesto = importdata(NomeFile);
|
||||
% [rTXT,~] = size(Filetesto);
|
||||
% if rTXT >1
|
||||
% datainvio = Filetesto(1,1); % mese di invio OPPURE data di ultimo invio
|
||||
% else % file txt vuoto
|
||||
% if numgiorni == 30
|
||||
% datainvio = meseadesso;
|
||||
% else
|
||||
% datainvio = now;
|
||||
% end
|
||||
% end
|
||||
% else
|
||||
% datainvio = meseadesso+1;
|
||||
% if datainvio > 12
|
||||
% datainvio = datainvio-12;
|
||||
% end
|
||||
% end
|
||||
%
|
||||
% attivaReport = 0;
|
||||
% outdat = fopen(NomeFile,'wt+');
|
||||
% fopen(NomeFile,'wt');
|
||||
% fmt = '%d \r';
|
||||
% fileID = fopen(NomeFile,'a');
|
||||
% if numgiorni == 30
|
||||
% if datainvio == 12
|
||||
% nuovofile = 12;
|
||||
% elseif datainvio == 13
|
||||
% nuovofile = 13;
|
||||
% else
|
||||
% nuovofile = meseadesso;
|
||||
% end
|
||||
% else
|
||||
% nuovofile = datainvio;
|
||||
% end
|
||||
% fprintf(fileID,fmt,nuovofile);
|
||||
% fprintf(fileID,fmt,attivaReport);
|
||||
% fclose(fileID);
|
||||
%
|
||||
% %% Email
|
||||
% setpref('Internet','E_mail','alert@aseltd.eu');
|
||||
% setpref('Internet','SMTP_Server','smtps.aruba.it');
|
||||
% setpref('Internet','SMTP_Username','alert@aseltd.eu');
|
||||
% setpref('Internet','SMTP_Password','Ase#2013!20@bat');
|
||||
% props=java.lang.System.getProperties;
|
||||
% pp=props.setProperty('mail.smtp.auth','true'); %#ok
|
||||
% pp=props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory'); %#ok
|
||||
% pp=props.setProperty('mail.smtp.socketFactory.port','465'); %#ok
|
||||
%
|
||||
% % Uso il siteID per identificare il nome del sito
|
||||
% comando = ['select name from sites where id like ''' siteID ''' '];
|
||||
% curs = exec(conn,comando);
|
||||
% curs = fetch(curs);
|
||||
% NomeSito = num2str(cell2mat(curs.Data));
|
||||
%
|
||||
% subject_ITA = (['CRASH del Report Automatico - ' NomeSito '']);
|
||||
% testo = cellstr('Ciao Andrea e Alessandro,');
|
||||
% testobis = cellstr('');
|
||||
% testo2 = cellstr(['Nella funzione del report avete scritto qualche minchiata per cui crasha. Vi prego di correggermi '...
|
||||
% 'o continuer' char(243) ' a crashare e ad assillarvi con questa mail. Troverete l''errore in allegato.']);
|
||||
% message_ITA = [testo; testobis; testo2];
|
||||
% message = cellstr('Tanti Bip e Bop a te, ');
|
||||
% message2 = cellstr('Software Tilt');
|
||||
% message_ITA = [message_ITA; message; message2];
|
||||
%
|
||||
% recipients_ASE{1,1} = 'alessandro.valletta@aseltd.eu';
|
||||
% recipients_ASE{2,1} = 'andrea.carri@aseltd.eu';
|
||||
%
|
||||
% allegato = FileErr;
|
||||
%
|
||||
% sendmail(recipients_ASE, subject_ITA, message_ITA, allegato)
|
||||
|
||||
% end
|
||||
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
text = 'report_ASE function executed correctly';
|
||||
fprintf(fileID,fmt,text);
|
||||
fclose(fileID);
|
||||
|
||||
diary off
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user