30.09.2022, 09:02
I have little problem with my code.
I want to archive result, where email what LM send is formatted.
There is list of alarms. If alarm is okay, after variable name I want to show green bold "OK". If there is alarm, I want to show red bold "ALARM".
Basically I have working solution but sometimes system gonna paint whole text to green.
This script is event based script (alarms count - if any alarms found, this script variable will be over 1)
I have tried delays, formatting text before sending etc but haven't find any fix...
When checking with dev tools I see that span is not ended.
But why, that is the question...
Tried to send email to three different email platform no differences (to gmail, to own domain email).
Any suggestions?
With short emails I haven't seen any errors so far (up to 5 variable names).
I want to archive result, where email what LM send is formatted.
There is list of alarms. If alarm is okay, after variable name I want to show green bold "OK". If there is alarm, I want to show red bold "ALARM".
Basically I have working solution but sometimes system gonna paint whole text to green.
This script is event based script (alarms count - if any alarms found, this script variable will be over 1)
Code:
value = event.getvalue()
require('user.sendmail')
require('user.emails')
content_alarm = 'Tere! <br><br> <b>SV1</b> automaatikasüsteemis on tuvastatud järgmised häired: <br><br>'
content_ok = 'Tere! <br><br> <b>SV1</b> automaatikasüsteemi häired on taastunud ning süsteem on töökorras.<br><br>Kokkuvõte häiretest: <br><br>'
footer = '<br><br><br><br><i>Email on genereeritud automaatikasüsteemi poolt. Palume mitte sellele emailile vastata!<br><br>Parimate soovidega,<br>Building Automation System OÜ</i>'
summary_to_send = ''
function alarm_summary(tag)
table_len = 0
summary = ''
alarms = grp.tag(tag)
for _ in pairs(alarms) do
table_len = table_len + 1
end
--os.sleep(0.5)
for i=1,table_len, 1 do
if alarms[i].value ==true then
--summary = summary .. alarms[i].name .. " - <span style='color:red;font-weight:bold'>".."ALARM!".."</span><br>"
summary = string.format("%s%s%s",summary, alarms[i].name, " - <span style='color:red;font-weight:bold'>ALARM!</span><br>")
--os.sleep(0.5)
else
--summary = summary .. alarms[i].name .. " - <span style='color:green;font-weight:bold'>".."OK".."</span><br>"
summary = string.format("%s%s%s",summary , alarms[i].name , " - <span style='color:green;font-weight:bold'>OK</span><br>")
--os.sleep(0.5)
end
end
--os.sleep(0.5)
return summary
end
summary_to_send = alarm_summary('SV1-ALARMS')
--os.sleep(0.5)
if value >0 then
res, err = mail(emails, 'Hooneautomaatika',string.format("%s%s%s",content_alarm, summary_to_send, footer ))
if err ~=nil then
grp.checkupdate('38/4/6',1)
else
grp.checkupdate('38/4/6',0)
end
else
res, err =mail(emails, 'Hooneautomaatika',string.format("%s%s%s",content_ok , summary_to_send , footer))
if err ~=nil then
grp.checkupdate('38/4/6',1)
else
grp.checkupdate('38/4/6',0)
end
end
I have tried delays, formatting text before sending etc but haven't find any fix...
When checking with dev tools I see that span is not ended.
But why, that is the question...
Tried to send email to three different email platform no differences (to gmail, to own domain email).
Any suggestions?
With short emails I haven't seen any errors so far (up to 5 variable names).