From 8be97eb781305c838a75c82ceac22d32c2449ca9 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 19 Sep 2013 19:34:21 +0200 Subject: [PATCH] renamed email task to mail because of some name collision in smtplib --- examples/hanez.json | 5 +++-- examples/linspector.json | 6 +++--- examples/minimal.json | 4 ++-- lib/core/job.py | 4 ++++ lib/tasks/mail.py | 15 ++++----------- lib/tasks/task.py | 3 +++ 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/hanez.json b/examples/hanez.json index 936c6c3..04ea252 100644 --- a/examples/hanez.json +++ b/examples/hanez.json @@ -3,7 +3,8 @@ "hanez":{ "name": "Johannes Findeisen", "tasks": [ - { "class":"email", "type": "email", "args": { "rcpt": "you@hanez.org" }} + { "class":"mail", "type": "mail", "args": { "rcpt": "you@hanez.org" }}, + { "class":"mail", "type": "mail", "args": { "rcpt": "johannes.findeisen@com.puting.de" }} ] } }, @@ -19,7 +20,7 @@ "class": "tcpconnect", "args": { "port": 80 }, "periods": ["always"], - "threshold": 5 + "threshold": 1 } ] } diff --git a/examples/linspector.json b/examples/linspector.json index aae9209..a195480 100644 --- a/examples/linspector.json +++ b/examples/linspector.json @@ -3,7 +3,7 @@ "root":{ "name": "Admin", "comment": "The Linspector Admin", - "tasks":[{ "class": "email", "type": "warning", "args":{ "rcpt": "admin@systems.hanez.org" }}, + "tasks":[{ "class": "mail", "type": "warning", "args":{ "rcpt": "admin@systems.hanez.org" }}, { "class": "sms", "type": "critical", "args":{ "rcpt": "+49112" }}, { "class": "xmpp", "type": "critical", "args":{ "rcpt": "admin@jabber.hanez.org" }}] }, @@ -11,13 +11,13 @@ "name": "Johannes Findeisen", "comment": "Just a nerd doing admin stuff.", "parent": "darth", - "tasks":[{ "class": "email", "type": "warning", "args":{ "rcpt": "you@hanez.org" }}, + "tasks":[{ "class": "mail", "type": "warning", "args":{ "rcpt": "you@hanez.org" }}, { "class": "sms", "type": "critical", "args":{ "rcpt": "+49110" }}] }, "darth":{ "name": "Darth Vader", "comment": "The father", - "tasks":{ "class": "email", "type": "warning", "args":{ "rcpt": "darth.vader@hanez.org" }} + "tasks":{ "class": "mail", "type": "warning", "args":{ "rcpt": "darth.vader@hanez.org" }} } }, "periods":{ diff --git a/examples/minimal.json b/examples/minimal.json index 5454d0c..0453708 100644 --- a/examples/minimal.json +++ b/examples/minimal.json @@ -4,8 +4,8 @@ "name": "Homer Simpson", "comment": "Security Inspector", "tasks": [ - {"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}, - {"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}} + {"class":"mail", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}, + {"class":"mail", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}} ] } }, diff --git a/lib/core/job.py b/lib/core/job.py index a50654f..ec1286f 100644 --- a/lib/core/job.py +++ b/lib/core/job.py @@ -43,6 +43,10 @@ class Job: self.handle_alarm(self.jobThreshold - serviceThreshold) def handle_alarm(self, thresholdOffset): + for member in self.service.get_hostgroup().get_members(): + for task in member.get_tasks(): + print(task) + task.execute("Task executed!") pass def handle_call(self): diff --git a/lib/tasks/mail.py b/lib/tasks/mail.py index eaa28e2..086ba01 100644 --- a/lib/tasks/mail.py +++ b/lib/tasks/mail.py @@ -4,12 +4,12 @@ The email task. http://docs.python.org/2/library/email-examples.html """ -#import smtplib -#from email.mime.text import MIMEText +import smtplib +from email.mime.text import MIMEText from lib.tasks.task import Task -class EmailTask(Task): +class MailTask(Task): def __init__(self, **kwargs): if not "type" in kwargs: raise Exception("'type' not in typeDict " + str(kwargs)) @@ -19,7 +19,6 @@ class EmailTask(Task): self.recipient = kwargs["args"]["rcpt"] def execute(self, msg): - ''' message = MIMEText(msg) message['Subject'] = 'Warning from Linspector' message['From'] = "warning@linspector.org" @@ -27,13 +26,7 @@ class EmailTask(Task): s = smtplib.SMTP('localhost') s.sendmail("warning@linspector.org", self.recipient, message.as_string()) s.quit() - ''' - - print("Task executed") - print(msg) - print(self.recipient) - pass def create(taskDict): - return EmailTask(**taskDict) \ No newline at end of file + return MailTask(**taskDict) \ No newline at end of file diff --git a/lib/tasks/task.py b/lib/tasks/task.py index b4c7db8..e8b113f 100644 --- a/lib/tasks/task.py +++ b/lib/tasks/task.py @@ -18,4 +18,7 @@ class Task: return self._taskType def some_other_irrelevant_methods(self): + pass + + def execute(self, msg): pass \ No newline at end of file