Add problem report for disabled clients/probes

This commit is contained in:
Lance Edgar 2017-11-18 22:12:40 -06:00
parent 840c146969
commit fd7cd5cadd
5 changed files with 122 additions and 7 deletions

View file

@ -145,3 +145,16 @@ class TempmonServer(commands.Subcommand):
daemon.start(args.daemonize)
elif args.subcommand == 'stop':
daemon.stop()
class TempmonProblems(commands.Subcommand):
"""
Email report(s) of various Tempmon data problems
"""
name = 'tempmon-problems'
description = __doc__.strip()
def run(self, args):
from rattail_tempmon import problems
problems.disabled_probes(self.config, progress=self.progress)

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
@ -30,8 +30,10 @@ from rattail.db import model
from rattail.mail import Email
from rattail.time import localtime
from rattail_tempmon.db import model as tempmon
class tempmon(object):
class TempmonBase(object):
"""
Generic base class for all tempmon-related emails; adds common sample data.
"""
@ -50,7 +52,7 @@ class tempmon(object):
}
class tempmon_critical_temp(tempmon, Email):
class tempmon_critical_temp(TempmonBase, Email):
"""
Sent when a tempmon probe takes a reading which is "critical" in either the
high or low sense.
@ -63,7 +65,7 @@ class tempmon_critical_temp(tempmon, Email):
return data
class tempmon_error(tempmon, Email):
class tempmon_error(TempmonBase, Email):
"""
Sent when a tempmon probe is noticed to have some error, i.e. no current readings.
"""
@ -76,7 +78,7 @@ class tempmon_error(tempmon, Email):
return data
class tempmon_good_temp(tempmon, Email):
class tempmon_good_temp(TempmonBase, Email):
"""
Sent whenever a tempmon probe first takes a "good temp" reading, after
having previously had some bad reading(s).
@ -89,7 +91,7 @@ class tempmon_good_temp(tempmon, Email):
return data
class tempmon_high_temp(tempmon, Email):
class tempmon_high_temp(TempmonBase, Email):
"""
Sent when a tempmon probe takes a reading which is above the "maximum good
temp" range, but still below the "critically high temp" threshold.
@ -102,7 +104,7 @@ class tempmon_high_temp(tempmon, Email):
return data
class tempmon_low_temp(tempmon, Email):
class tempmon_low_temp(TempmonBase, Email):
"""
Sent when a tempmon probe takes a reading which is below the "minimum good
temp" range, but still above the "critically low temp" threshold.
@ -113,3 +115,20 @@ class tempmon_low_temp(tempmon, Email):
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
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': [
tempmon.Probe(description="north wall of walk-in cooler"),
],
}

View file

@ -0,0 +1,51 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# 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.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Tempmon data problems
"""
from __future__ import unicode_literals, absolute_import
from rattail.mail import send_email
from rattail_tempmon.db import Session as TempmonSession, model as tempmon
def disabled_probes(config, progress=None):
"""
Notifies if any Tempmon client devices or probes are disabled.
"""
tempmon_session = TempmonSession()
clients = tempmon_session.query(tempmon.Client)\
.filter(tempmon.Client.enabled == False)\
.all()
probes = tempmon_session.query(tempmon.Probe)\
.join(tempmon.Client)\
.filter(tempmon.Client.enabled == True)\
.filter(tempmon.Probe.enabled == False)\
.all()
if clients or probes:
send_email(config, 'tempmon_disabled_probes', {
'disabled_clients': clients,
'disabled_probes': probes,
})
tempmon_session.close()

View file

@ -0,0 +1,31 @@
## -*- coding: utf-8; -*-
<html>
<body>
<h1>Disabled Tempmon Probes</h1>
<p>
We checked if there were any offline temperature probes at your location.&nbsp;
Someone wanted these deactivated at some point, but you should make sure it is
okay that they still are.&nbsp; Here are the results:
</p>
% if disabled_probes:
<h3>Disabled Probes</h3>
<ul>
% for probe in disabled_probes:
<li>${probe}</li>
% endfor
</ul>
% endif
% if disabled_clients:
<h3>Disabled Clients</h3>
<ul>
% for client in disabled_clients:
<li>${client}</li>
% endfor
</ul>
% endif
<p>Please contact the Tech Department with any questions.</p>
</body>
</html>

View file

@ -101,6 +101,7 @@ setup(
'export-hotcooler = rattail_tempmon.commands:ExportHotCooler',
'purge-tempmon = rattail_tempmon.commands:PurgeTempmon',
'tempmon-client = rattail_tempmon.commands:TempmonClient',
'tempmon-problems = rattail_tempmon.commands:TempmonProblems',
'tempmon-server = rattail_tempmon.commands:TempmonServer',
],
'rattail.config.extensions': [