This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Tag value chek function
#1
Hello,

I need a function that checks objects by tag once a day and if the value of any of the objects is below 50 to send an email with the name of the object and its value. Also if the object has not updated its value for more than 2 hours also send an email.
Reply
#2
Use this:
Code:
objs = grp.tag('mytag')
mindelta = 2 * 60 * 60 -- 2 hours

now = os.time()
errors = {}

for _, obj in ipairs(objs) do
  delta = now - obj.updatetime

  if delta >= mindelta or obj.value < 50 then
    errors[ #errors + 1 ] = string.format('Name: %s, Value: %d, Updated: %s',
      obj.name, obj.value, os.date('%c', obj.updatetime))
  end
end

if #errors > 0 then
  text = table.concat(errors, '\n')
  log(text)
end
Reply
#3
Thank you very much! As always it works. I can't just force every event to be on a new line in the email with /n not working.
Reply
#4
Try using <br> instead of \n. mail() function sets html content-type so \n won't work.
Reply


Forum Jump: