DRY up some server alert logic a bit
This commit is contained in:
parent
4f42ad164a
commit
de1543018a
|
@ -107,6 +107,14 @@ class TempmonServerDaemon(Daemon):
|
|||
self.update_status(probe, self.enum.TEMPMON_PROBE_STATUS_ERROR)
|
||||
|
||||
def update_status(self, probe, status, reading=None):
|
||||
data = {
|
||||
'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),
|
||||
}
|
||||
|
||||
prev_status = probe.status
|
||||
if probe.status != status:
|
||||
probe.status = status
|
||||
|
@ -115,13 +123,7 @@ class TempmonServerDaemon(Daemon):
|
|||
|
||||
# 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),
|
||||
})
|
||||
send_email(self.config, 'tempmon_good_temp', data)
|
||||
probe.status_alert_sent = self.now
|
||||
|
||||
# no (more) email if status is good
|
||||
|
@ -146,14 +148,6 @@ class TempmonServerDaemon(Daemon):
|
|||
self.enum.TEMPMON_PROBE_STATUS_ERROR : 'tempmon_error',
|
||||
}
|
||||
|
||||
data = {
|
||||
'probe': probe,
|
||||
'status': self.enum.TEMPMON_PROBE_STATUS[status],
|
||||
'reading': reading,
|
||||
'taken': localtime(self.config, make_utc(reading.taken, tzinfo=True)) if reading else None,
|
||||
'now': localtime(self.config),
|
||||
}
|
||||
|
||||
send_email(self.config, msgtypes[status], data)
|
||||
|
||||
# maybe send more emails if config said so
|
||||
|
|
Loading…
Reference in a new issue