2017-11-18 22:12:40 -06:00
|
|
|
# -*- coding: utf-8; -*-
|
2016-12-10 14:14:40 -06:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2018-10-17 18:08:54 -05:00
|
|
|
# Copyright © 2010-2018 Lance Edgar
|
2016-12-10 14:14:40 -06:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
2017-07-06 23:38:50 -05:00
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
2016-12-10 14:14:40 -06:00
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2017-07-06 23:38:50 -05:00
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
2016-12-10 14:14:40 -06:00
|
|
|
#
|
2017-07-06 23:38:50 -05:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-10 14:14:40 -06:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Email config for tempmon-server
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
|
|
|
|
from rattail.db import model
|
|
|
|
from rattail.mail import Email
|
|
|
|
from rattail.time import localtime
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
from rattail_tempmon.db import model as tempmon
|
2016-12-10 14:14:40 -06:00
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
|
|
|
|
class TempmonBase(object):
|
2016-12-10 14:14:40 -06:00
|
|
|
"""
|
|
|
|
Generic base class for all tempmon-related emails; adds common sample data.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
now = localtime(self.config)
|
|
|
|
client = model.TempmonClient(config_key='testclient', hostname='testclient')
|
|
|
|
probe = model.TempmonProbe(config_key='testprobe', description="Test Probe")
|
|
|
|
client.probes.append(probe)
|
|
|
|
return {
|
2018-02-07 17:47:00 -06:00
|
|
|
'client': client,
|
2016-12-10 14:14:40 -06:00
|
|
|
'probe': probe,
|
|
|
|
'status': self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_ERROR],
|
|
|
|
'reading': model.TempmonReading(),
|
|
|
|
'taken': now,
|
|
|
|
'now': now,
|
2018-10-17 18:08:54 -05:00
|
|
|
'probe_url': '#',
|
2016-12-10 14:14:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-19 14:58:30 -05:00
|
|
|
class tempmon_critical_high_temp(TempmonBase, Email):
|
|
|
|
"""
|
|
|
|
Sent when a tempmon probe takes a "critical high" temperature reading.
|
|
|
|
"""
|
|
|
|
default_subject = "CRITICAL HIGH Temperature"
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_critical_high_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_CRITICAL_HIGH_TEMP]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
class tempmon_critical_low_temp(TempmonBase, Email):
|
|
|
|
"""
|
|
|
|
Sent when a tempmon probe takes a "critical low" temperature reading.
|
|
|
|
"""
|
|
|
|
default_subject = "CRITICAL LOW Temperature"
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_critical_low_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_CRITICAL_LOW_TEMP]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
class tempmon_critical_temp(TempmonBase, Email):
|
2016-12-10 14:14:40 -06:00
|
|
|
"""
|
|
|
|
Sent when a tempmon probe takes a reading which is "critical" in either the
|
|
|
|
high or low sense.
|
|
|
|
"""
|
|
|
|
default_subject = "Critical temperature detected"
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_critical_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_CRITICAL_TEMP]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
class tempmon_error(TempmonBase, Email):
|
2016-12-10 14:14:40 -06:00
|
|
|
"""
|
|
|
|
Sent when a tempmon probe is noticed to have some error, i.e. no current readings.
|
|
|
|
"""
|
|
|
|
default_subject = "Probe error detected"
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_error, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_ERROR]
|
|
|
|
data['taken'] = None
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2018-02-07 17:47:00 -06:00
|
|
|
class tempmon_client_offline(TempmonBase, Email):
|
|
|
|
"""
|
|
|
|
Sent when a tempmon client has been marked offline.
|
|
|
|
"""
|
|
|
|
default_subject = "Client Offline"
|
|
|
|
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
class tempmon_good_temp(TempmonBase, Email):
|
2016-12-12 09:46:20 -06:00
|
|
|
"""
|
|
|
|
Sent whenever a tempmon probe first takes a "good temp" reading, after
|
|
|
|
having previously had some bad reading(s).
|
|
|
|
"""
|
2018-10-19 14:58:30 -05:00
|
|
|
default_subject = "OK Temperature"
|
2016-12-12 09:46:20 -06:00
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_good_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_GOOD_TEMP]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
class tempmon_high_temp(TempmonBase, Email):
|
2016-12-10 14:14:40 -06:00
|
|
|
"""
|
|
|
|
Sent when a tempmon probe takes a reading which is above the "maximum good
|
|
|
|
temp" range, but still below the "critically high temp" threshold.
|
|
|
|
"""
|
2018-10-19 14:58:30 -05:00
|
|
|
default_subject = "HIGH Temperature"
|
2016-12-10 14:14:40 -06:00
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_high_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2017-11-18 22:12:40 -06:00
|
|
|
class tempmon_low_temp(TempmonBase, Email):
|
2016-12-10 14:14:40 -06:00
|
|
|
"""
|
|
|
|
Sent when a tempmon probe takes a reading which is below the "minimum good
|
|
|
|
temp" range, but still above the "critically low temp" threshold.
|
|
|
|
"""
|
2018-10-19 14:58:30 -05:00
|
|
|
default_subject = "LOW Temperature"
|
2016-12-10 14:14:40 -06:00
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
data = super(tempmon_low_temp, self).sample_data(request)
|
|
|
|
data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP]
|
|
|
|
return data
|
2017-11-18 22:12:40 -06:00
|
|
|
|
|
|
|
|
|
|
|
class tempmon_disabled_probes(Email):
|
|
|
|
"""
|
|
|
|
Notifies of any Tempmon client devices or probes which are disabled.
|
|
|
|
"""
|
|
|
|
default_subject = "Disabled probes"
|
|
|
|
|
|
|
|
def sample_data(self, request):
|
|
|
|
return {
|
|
|
|
'disabled_clients': [
|
|
|
|
tempmon.Client(config_key='foo', hostname='foo.example.com'),
|
|
|
|
],
|
|
|
|
'disabled_probes': [
|
2018-09-11 18:42:00 -05:00
|
|
|
tempmon.Probe(description="north wall of walk-in cooler",
|
|
|
|
client=tempmon.Client(config_key='bar')),
|
2017-11-18 22:12:40 -06:00
|
|
|
],
|
|
|
|
}
|