diff options
author | Tom Ritter <tom@ritter.vg> | 2016-01-25 21:24:41 -0500 |
---|---|---|
committer | Tom Ritter <tom@ritter.vg> | 2016-01-25 21:24:41 -0500 |
commit | 9b25f65ca655a567873c66c2b015884a3e013276 (patch) | |
tree | 242b994394ebbbcfdcc72eba6241f4ea03cf921c /jobs/JobBase.py |
Initial commit of checker
Diffstat (limited to 'jobs/JobBase.py')
-rwxr-xr-x | jobs/JobBase.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/jobs/JobBase.py b/jobs/JobBase.py new file mode 100755 index 0000000..330b6a9 --- /dev/null +++ b/jobs/JobBase.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import random +import logging + +import smtplib + +class JobFrequency: + MINUTE = "minute" + HOUR = "hour" + +class JobBase: + def __init__(self): + self.config = None + def getName(self): + return str(self.__class__) + def shouldExecute(self, cronmode): + frequency = self.executeEvery() + if cronmode == frequency: + return True + return False + def setConfig(self, config): + self.config = config + + def sendEmail(self, subject, body, to=""): + return sendEmail(self.config, subject, body, to) + + def executeEvery(self): + pass + def execute(self): + pass + +def sendEmail(config, subject, body, to=""): + FROM = config.get('email', 'user') + PASS = config.get('email', 'pass') + if not to: + to = config.get('alertcontact', 'default') + + # Prepare actual message + # Avoid gmail threading + subject = subject + " " + str(random.random()) + message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" \ + % (FROM, ", ".join(to), subject, body) + try: + server = smtplib.SMTP(config.get('email', 'smtpserver'), config.get('email', 'smtpport')) + server.ehlo() + server.starttls() + server.login(FROM, PASS) + server.sendmail(FROM, to, message) + server.close() + return True + except: + return False
\ No newline at end of file |