added core config to jobs and tasks and made use of core variables raw in the tasks
This commit is contained in:
parent
25f83c3ae9
commit
0bfa4b3daa
5 changed files with 23 additions and 21 deletions
|
|
@ -14,11 +14,12 @@ def generateId():
|
|||
|
||||
|
||||
class Job:
|
||||
def __init__(self, service, host, members, processors):
|
||||
def __init__(self, service, host, members, processors, core):
|
||||
self.service = service
|
||||
self.host = host
|
||||
self.members = members
|
||||
self.processors = processors
|
||||
self.core = core
|
||||
self.jobInfos = []
|
||||
self.jobThreshold = 0
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ class Job:
|
|||
def set_job(self, job):
|
||||
self.job = job
|
||||
|
||||
def handle_threshold(self, serviceThreshold, executionSucessful):
|
||||
def handle_threshold(self, jobInfo, serviceThreshold, executionSucessful):
|
||||
if executionSucessful:
|
||||
if self.jobThreshold > 0:
|
||||
self.jobThreshold -= 1
|
||||
|
|
@ -40,12 +41,12 @@ class Job:
|
|||
|
||||
if self.jobThreshold >= serviceThreshold:
|
||||
self.log.d("Threshold reached!")
|
||||
self.handle_alarm(self.jobThreshold - serviceThreshold)
|
||||
self.handle_alarm(jobInfo, self.jobThreshold - serviceThreshold)
|
||||
|
||||
def handle_alarm(self, thresholdOffset):
|
||||
def handle_alarm(self, jobInfo, thresholdOffset):
|
||||
for member in self.service.get_hostgroup().get_members():
|
||||
for task in member.get_tasks():
|
||||
task.execute("Task executed for host: " + self.host)
|
||||
task.execute(jobInfo.get_message(), self.core)
|
||||
|
||||
def handle_call(self):
|
||||
self.log.d("handle call")
|
||||
|
|
@ -55,7 +56,7 @@ class Job:
|
|||
self.service._execute(jobInfo)
|
||||
jobInfo.set_execution_end()
|
||||
|
||||
self.handle_threshold(self.service.get_threshold(), jobInfo.was_execution_successful())
|
||||
self.handle_threshold(jobInfo, self.service.get_threshold(), jobInfo.was_execution_successful())
|
||||
|
||||
self.log.d("Code: " + str(jobInfo.get_errorcode()) + ", Message: " + str(jobInfo.get_message()))
|
||||
|
||||
|
|
|
|||
|
|
@ -27,21 +27,21 @@ class TcpconnectService(Service):
|
|||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.error, msg:
|
||||
jobInfo.set_errorcode(2)
|
||||
jobInfo.set_message("Could not create socket to host: " + jobInfo.get_host() + " on port: " +
|
||||
str(self.port) + " (" + str(msg) + ")")
|
||||
jobInfo.set_message("[tcpconnect] Could not create socket to host: " + jobInfo.get_host() +
|
||||
" on port: " + str(self.port) + " (" + str(msg) + ")")
|
||||
|
||||
try:
|
||||
sock.connect((jobInfo.get_host(), self.port))
|
||||
except socket.error, msg:
|
||||
jobInfo.set_errorcode(1)
|
||||
jobInfo.set_message("Could not establish connection to host: " + jobInfo.get_host() + " on port: " +
|
||||
str(self.port) + " (" + str(msg) + ")")
|
||||
jobInfo.set_message("[tcpconnect] Could not establish connection to host: " + jobInfo.get_host() +
|
||||
" on port: " + str(self.port) + " (" + str(msg) + ")")
|
||||
|
||||
if jobInfo.get_errorcode() == -1:
|
||||
jobInfo.set_execution_successful(True)
|
||||
jobInfo.set_errorcode(0)
|
||||
jobInfo.set_message("Connection successful established to host: " + jobInfo.get_host() + " on port: " +
|
||||
str(self.port))
|
||||
jobInfo.set_message("[tcpconnect] Connection successful established to host: " + jobInfo.get_host() +
|
||||
" on port: " + str(self.port))
|
||||
|
||||
sock.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ class JabberTask(Task):
|
|||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
def execute(self, msg):
|
||||
client = xmpp.Client('systemchaos.org')
|
||||
client.connect(server=('systemchaos.org', 5222))
|
||||
client.auth('linspector', 'PASSWORD', 'alert')
|
||||
def execute(self, msg, core):
|
||||
#TODO: totally unstable just to use values from core. make checks before...!
|
||||
client = xmpp.Client(core["tasks"]["jabber"]["host"])
|
||||
client.connect(server=(core["tasks"]["jabber"]["host"], core["tasks"]["jabber"]["port"]))
|
||||
client.auth(core["tasks"]["jabber"]["username"], core["tasks"]["jabber"]["password"], 'alert')
|
||||
client.sendInitPresence()
|
||||
message = xmpp.Message(self.recipient, msg)
|
||||
message.setAttr('type', 'chat')
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ class MailTask(Task):
|
|||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
def execute(self, msg):
|
||||
def execute(self, msg, core):
|
||||
message = MIMEText(msg)
|
||||
message['Subject'] = 'Warning from Linspector'
|
||||
message['Subject'] = msg
|
||||
now = datetime.datetime.now()
|
||||
message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S")
|
||||
message['From'] = "warning@linspector.org"
|
||||
message['From'] = core["tasks"]["mail"]["from"]
|
||||
message['To'] = self.recipient
|
||||
s = smtplib.SMTP('localhost')
|
||||
s = smtplib.SMTP(core["tasks"]["mail"]["host"], core["tasks"]["mail"]["port"])
|
||||
s.sendmail("warning@linspector.org", self.recipient, message.as_string())
|
||||
s.quit()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue