renamed email task to mail because of some name collision in smtplib
This commit is contained in:
parent
15a6470cbb
commit
bccb205f6d
6 changed files with 19 additions and 18 deletions
|
|
@ -3,7 +3,8 @@
|
||||||
"hanez":{
|
"hanez":{
|
||||||
"name": "Johannes Findeisen",
|
"name": "Johannes Findeisen",
|
||||||
"tasks": [
|
"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",
|
"class": "tcpconnect",
|
||||||
"args": { "port": 80 },
|
"args": { "port": 80 },
|
||||||
"periods": ["always"],
|
"periods": ["always"],
|
||||||
"threshold": 5
|
"threshold": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"root":{
|
"root":{
|
||||||
"name": "Admin",
|
"name": "Admin",
|
||||||
"comment": "The Linspector 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": "sms", "type": "critical", "args":{ "rcpt": "+49112" }},
|
||||||
{ "class": "xmpp", "type": "critical", "args":{ "rcpt": "admin@jabber.hanez.org" }}]
|
{ "class": "xmpp", "type": "critical", "args":{ "rcpt": "admin@jabber.hanez.org" }}]
|
||||||
},
|
},
|
||||||
|
|
@ -11,13 +11,13 @@
|
||||||
"name": "Johannes Findeisen",
|
"name": "Johannes Findeisen",
|
||||||
"comment": "Just a nerd doing admin stuff.",
|
"comment": "Just a nerd doing admin stuff.",
|
||||||
"parent": "darth",
|
"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" }}]
|
{ "class": "sms", "type": "critical", "args":{ "rcpt": "+49110" }}]
|
||||||
},
|
},
|
||||||
"darth":{
|
"darth":{
|
||||||
"name": "Darth Vader",
|
"name": "Darth Vader",
|
||||||
"comment": "The father",
|
"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":{
|
"periods":{
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
"name": "Homer Simpson",
|
"name": "Homer Simpson",
|
||||||
"comment": "Security Inspector",
|
"comment": "Security Inspector",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}},
|
{"class":"mail", "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"}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ class Job:
|
||||||
self.handle_alarm(self.jobThreshold - serviceThreshold)
|
self.handle_alarm(self.jobThreshold - serviceThreshold)
|
||||||
|
|
||||||
def handle_alarm(self, thresholdOffset):
|
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
|
pass
|
||||||
|
|
||||||
def handle_call(self):
|
def handle_call(self):
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ The email task.
|
||||||
http://docs.python.org/2/library/email-examples.html
|
http://docs.python.org/2/library/email-examples.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#import smtplib
|
import smtplib
|
||||||
#from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from lib.tasks.task import Task
|
from lib.tasks.task import Task
|
||||||
|
|
||||||
|
|
||||||
class EmailTask(Task):
|
class MailTask(Task):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if not "type" in kwargs:
|
if not "type" in kwargs:
|
||||||
raise Exception("'type' not in typeDict " + str(kwargs))
|
raise Exception("'type' not in typeDict " + str(kwargs))
|
||||||
|
|
@ -19,7 +19,6 @@ class EmailTask(Task):
|
||||||
self.recipient = kwargs["args"]["rcpt"]
|
self.recipient = kwargs["args"]["rcpt"]
|
||||||
|
|
||||||
def execute(self, msg):
|
def execute(self, msg):
|
||||||
'''
|
|
||||||
message = MIMEText(msg)
|
message = MIMEText(msg)
|
||||||
message['Subject'] = 'Warning from Linspector'
|
message['Subject'] = 'Warning from Linspector'
|
||||||
message['From'] = "warning@linspector.org"
|
message['From'] = "warning@linspector.org"
|
||||||
|
|
@ -27,13 +26,7 @@ class EmailTask(Task):
|
||||||
s = smtplib.SMTP('localhost')
|
s = smtplib.SMTP('localhost')
|
||||||
s.sendmail("warning@linspector.org", self.recipient, message.as_string())
|
s.sendmail("warning@linspector.org", self.recipient, message.as_string())
|
||||||
s.quit()
|
s.quit()
|
||||||
'''
|
|
||||||
|
|
||||||
print("Task executed")
|
|
||||||
print(msg)
|
|
||||||
print(self.recipient)
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def create(taskDict):
|
def create(taskDict):
|
||||||
return EmailTask(**taskDict)
|
return MailTask(**taskDict)
|
||||||
|
|
@ -19,3 +19,6 @@ class Task:
|
||||||
|
|
||||||
def some_other_irrelevant_methods(self):
|
def some_other_irrelevant_methods(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def execute(self, msg):
|
||||||
|
pass
|
||||||
Loading…
Add table
Add a link
Reference in a new issue