diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index 384d474..277f7b7 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -113,7 +113,18 @@ class TempmonServerDaemon(Daemon): probe.status_changed = self.now probe.status_alert_sent = None - # no email if status is good + # send email when things go back to normal, after being bad + if status == self.enum.TEMPMON_PROBE_STATUS_GOOD_TEMP: + send_email(self.config, 'tempmon_good_temp', { + 'probe': probe, + 'status': self.enum.TEMPMON_PROBE_STATUS[status], + 'reading': reading, + 'taken': localtime(self.config, reading.taken, from_utc=True) if reading else None, + 'now': localtime(self.config), + }) + probe.status_alert_sent = self.now + + # no (more) email if status is good if status == self.enum.TEMPMON_PROBE_STATUS_GOOD_TEMP: return @@ -123,6 +134,11 @@ class TempmonServerDaemon(Daemon): if (self.now - probe.status_alert_sent) <= timeout: return + # delay even the first email, until configured threshold is reached + timeout = datetime.timedelta(minutes=probe.therm_status_timeout) + if (self.now - probe.status_changed) <= timeout: + return + msgtypes = { self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP : 'tempmon_low_temp', self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP : 'tempmon_high_temp', diff --git a/rattail_tempmon/templates/mail/tempmon_critical_temp.html.mako b/rattail_tempmon/templates/mail/tempmon_critical_temp.html.mako new file mode 100644 index 0000000..2dba9b6 --- /dev/null +++ b/rattail_tempmon/templates/mail/tempmon_critical_temp.html.mako @@ -0,0 +1,25 @@ +## -*- coding: utf-8 -*- + +
+
+ This is an alert from ${probe}!
+ The status of ${probe} is: ${status}.
+ The current temperature is: ${reading.degrees_f}.
+ The temperature should never be this high.
+ Investigate Immediately!
+
+ Notes:
+ Frozen food that is above 40 degrees needs to be thrown away
+ if it remains at that temperature for two hours or more.
+
+ Check out this USDA link for useful information +
+
+ This email will repeat every 15 minutes until the issue
+ has been resolved.
+
+ + diff --git a/rattail_tempmon/templates/mail/tempmon_error.html.mako b/rattail_tempmon/templates/mail/tempmon_error.html.mako new file mode 100644 index 0000000..fbf4ec4 --- /dev/null +++ b/rattail_tempmon/templates/mail/tempmon_error.html.mako @@ -0,0 +1,10 @@ +## -*- coding: utf-8 -*- + +
+At ${taken or now}, ${probe} reported that its status was: ${status}.
+ Something went wrong. Please investigate as soon as possible.
+
This email will repeat every 15 minutes until the issue is resolved. +
+ + diff --git a/rattail_tempmon/templates/mail/tempmon_good_temp.html.mako b/rattail_tempmon/templates/mail/tempmon_good_temp.html.mako new file mode 100644 index 0000000..236d37b --- /dev/null +++ b/rattail_tempmon/templates/mail/tempmon_good_temp.html.mako @@ -0,0 +1,9 @@ +## -*- coding: utf-8 -*- + + +This is a notice from ${probe}.
+ Things are back to normal now, status is: ${status}.
+ Current temperature is within expected range, at ${reading.degrees_f}
+
This is a warning from ${probe}.
+ The status of ${probe} is: ${status}.
+ This is because the temperature is ${reading.degrees_f}
+ and has been so for longer than expected.
+ This unit should be looked at as soon
+ as possible to ensure no food goes to waste.
+
+ Notes:
+ This alert will happen every 15 minutes until
+ the temperature reaches an acceptable level.
+
This is a warning from ${probe}.
+ The status of ${probe} is: ${status}.
+ This is because the temperature is ${reading.degrees_f}
+ and has been so for longer than expected.
+ This unit should be looked at as soon
+ as possible to ensure no food goes to waste.
+
+ Notes:
+ This alert will happen every 15 minutes until
+ the temperature reaches an acceptable level.
+