From 5df3379995def283575d9218926992f0d29dd6e8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 7 Feb 2018 17:47:00 -0600 Subject: [PATCH] Send email alert when tempmon server marks a client as offline courtesy of Cole Chaney --- rattail_tempmon/emails.py | 8 ++++++++ rattail_tempmon/server.py | 2 ++ .../templates/mail/tempmon_client_offline.html.mako | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 rattail_tempmon/templates/mail/tempmon_client_offline.html.mako diff --git a/rattail_tempmon/emails.py b/rattail_tempmon/emails.py index 6f76ec2..1351c9c 100644 --- a/rattail_tempmon/emails.py +++ b/rattail_tempmon/emails.py @@ -44,6 +44,7 @@ class TempmonBase(object): probe = model.TempmonProbe(config_key='testprobe', description="Test Probe") client.probes.append(probe) return { + 'client': client, 'probe': probe, 'status': self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_ERROR], 'reading': model.TempmonReading(), @@ -78,6 +79,13 @@ class tempmon_error(TempmonBase, Email): return data +class tempmon_client_offline(TempmonBase, Email): + """ + Sent when a tempmon client has been marked offline. + """ + default_subject = "Client Offline" + + class tempmon_good_temp(TempmonBase, Email): """ Sent whenever a tempmon probe first takes a "good temp" reading, after diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index fde4fd7..f6a3d25 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -83,6 +83,8 @@ class TempmonServerDaemon(Daemon): if not online and client.online: log.info("marking client as OFFLINE: {}".format(client)) client.online = False + send_email(self.config, 'tempmon_client_offline', {"client":client, "now":localtime(self.config,self.now,from_utc=True)}) + def check_readings_for_probe(self, session, probe, cutoff): readings = session.query(tempmon.Reading)\ diff --git a/rattail_tempmon/templates/mail/tempmon_client_offline.html.mako b/rattail_tempmon/templates/mail/tempmon_client_offline.html.mako new file mode 100644 index 0000000..9a7f829 --- /dev/null +++ b/rattail_tempmon/templates/mail/tempmon_client_offline.html.mako @@ -0,0 +1,8 @@ +## -*- coding: utf-8 -*- + + +

At ${now.strftime("%Y-%m-%d %I:%M %p")} the Tempmon server failed to locate readings for ${client}.
+ This client is now marked as offline. Investigate asap. +

+ +