Add base class for tempmon email config, for common sample data

This commit is contained in:
Lance Edgar 2016-12-01 11:53:48 -06:00
parent ebbf7abffb
commit 6afbd49ec9

View file

@ -83,7 +83,26 @@ class filemon_action_error(Email):
} }
class tempmon_critical_temp(Email): class tempmon(object):
"""
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 {
'probe': probe,
'status': self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_ERROR],
'reading': model.TempmonReading(),
'taken': now,
'now': now,
}
class tempmon_critical_temp(tempmon, Email):
""" """
Sent when a tempmon probe takes a reading which is "critical" in either the Sent when a tempmon probe takes a reading which is "critical" in either the
high or low sense. high or low sense.
@ -91,36 +110,25 @@ class tempmon_critical_temp(Email):
default_subject = "Critical temperature detected" default_subject = "Critical temperature detected"
def sample_data(self, request): def sample_data(self, request):
enum = self.config.get_enum() data = super(tempmon_critical_temp, self).sample_data(request)
now = localtime(self.config) data['status'] = enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_CRITICAL_TEMP]
return { return data
'probe': model.TempmonProbe(config_key='test', description="Test Probe"),
'status': enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_CRITICAL_TEMP],
'reading': model.TempmonReading(),
'taken': now,
'now': now,
}
class tempmon_error(Email): class tempmon_error(tempmon, Email):
""" """
Sent when a tempmon probe is noticed to have some error, i.e. no current readings. Sent when a tempmon probe is noticed to have some error, i.e. no current readings.
""" """
default_subject = "Probe error detected" default_subject = "Probe error detected"
def sample_data(self, request): def sample_data(self, request):
enum = self.config.get_enum() data = super(tempmon_error, self).sample_data(request)
now = localtime(self.config) data['status'] = enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_ERROR]
return { data['taken'] = None
'probe': model.TempmonProbe(config_key='test', description="Test Probe"), return data
'status': enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_ERROR],
'reading': None,
'taken': None,
'now': now,
}
class tempmon_high_temp(Email): class tempmon_high_temp(tempmon, Email):
""" """
Sent when a tempmon probe takes a reading which is above the "maximum good Sent when a tempmon probe takes a reading which is above the "maximum good
temp" range, but still below the "critically high temp" threshold. temp" range, but still below the "critically high temp" threshold.
@ -128,31 +136,19 @@ class tempmon_high_temp(Email):
default_subject = "High temperature detected" default_subject = "High temperature detected"
def sample_data(self, request): def sample_data(self, request):
enum = self.config.get_enum() data = super(tempmon_high_temp, self).sample_data(request)
now = localtime(self.config) data['status'] = enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_HIGH_TEMP]
return { return data
'probe': model.TempmonProbe(config_key='test', description="Test Probe"),
'status': enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_HIGH_TEMP],
'reading': model.TempmonReading(),
'taken': now,
'now': now,
}
class tempmon_low_temp(Email): class tempmon_low_temp(tempmon, Email):
""" """
Sent when a tempmon probe takes a reading which is below the "minimum good Sent when a tempmon probe takes a reading which is below the "minimum good
temp" range, but still above the "critically low temp" threshold. temp" range, but still above the "critically low temp" threshold.
""" """
default_subject = "Low temperature detected" default_subject = "Low temperature detected"
def sample_data(self, request): def sample_data(self, request):
enum = self.config.get_enum() data = super(tempmon_low_temp, self).sample_data(request)
now = localtime(self.config) data['status'] = enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_LOW_TEMP]
return { return data
'probe': model.TempmonProbe(config_key='test', description="Test Probe"),
'status': enum.TEMPMON_PROBE_STATUS[enum.TEMPMON_PROBE_STATUS_LOW_TEMP],
'reading': model.TempmonReading(),
'taken': now,
'now': now,
}