renamed xmpp task to jabber to avoid conflicts; added simple xmpp/jabber support to tasks
This commit is contained in:
parent
bccb205f6d
commit
1e8ad1f110
5 changed files with 41 additions and 27 deletions
|
|
@ -46,7 +46,7 @@ class Job:
|
|||
for member in self.service.get_hostgroup().get_members():
|
||||
for task in member.get_tasks():
|
||||
print(task)
|
||||
task.execute("Task executed!")
|
||||
task.execute("Task executed for host: " + self.host)
|
||||
pass
|
||||
|
||||
def handle_call(self):
|
||||
|
|
|
|||
31
lib/tasks/jabber.py
Normal file
31
lib/tasks/jabber.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
The Jabber task.
|
||||
|
||||
Uses: http://xmpppy.sourceforge.net/
|
||||
"""
|
||||
|
||||
import xmpp
|
||||
from lib.tasks.task import Task
|
||||
|
||||
|
||||
class JabberTask(Task):
|
||||
def __init__(self, **kwargs):
|
||||
if not "type" in kwargs:
|
||||
raise Exception("'type' not in typeDict " + str(kwargs))
|
||||
if not "args" in kwargs:
|
||||
raise Exception("typeDict " + str(kwargs) + " has nor arguments!")
|
||||
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')
|
||||
client.sendInitPresence()
|
||||
message = xmpp.Message('hanez@systemchaos.org', msg)
|
||||
message.setAttr('type', 'chat')
|
||||
client.send(message)
|
||||
|
||||
|
||||
def create(taskDict):
|
||||
return JabberTask(**taskDict)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
"""
|
||||
The xmpp task.
|
||||
"""
|
||||
|
||||
from lib.tasks.task import Task
|
||||
|
||||
|
||||
class XmppTask(Task):
|
||||
def __init__(self, **kwargs):
|
||||
if not "type" in kwargs:
|
||||
raise Exception("'type' not in typeDict " + str(kwargs))
|
||||
if not "args" in kwargs:
|
||||
raise Exception("typeDict " + str(kwargs) + " has nor arguments!")
|
||||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
def execute_task(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
def create(taskDict):
|
||||
return XmppTask(**taskDict)
|
||||
Loading…
Add table
Add a link
Reference in a new issue