Commit 7d1898f1 authored by ale's avatar ale
Browse files

Add an XMPP probe

parent c651c009
Pipeline #7962 passed with stage
in 1 minute and 12 seconds
......@@ -8,6 +8,7 @@ from ai_diagnostics.probes.webmail import probe_webmail
from ai_diagnostics.probes.imap import probe_imap
from ai_diagnostics.probes.smtp import *
from ai_diagnostics.probes.webdav import probe_webdav
from ai_diagnostics.probes.xmpp import probe_xmpp
class Credentials(dict):
......
from ai_diagnostics import xmpp
def probe_xmpp(ctx):
bot = xmpp.SendMsgBot(ctx['credentials']['username'],
ctx['credentials']['password'])
bot.register_plugin('xep_0030')
bot.register_plugin('xep_0199')
ctx.log('connecting to %s:5222', ctx['server'])
if bot.connect((ctx['server'], 5222), reattempt=False):
ctx.log('connection successful, setting presence')
bot.process(block=True)
ctx.log('disconnected successfully')
else:
ctx.log('unable to connect')
from sleekxmpp import ClientXMPP
class SendMsgBot(ClientXMPP):
"""XMPP bot that gets online and optionally sends a message."""
def __init__(self, jid, password, recipient=None, msg=None):
super(SendMsgBot, self).__init__(jid, password)
self.reconnect_max_attempts = 0
self.session_timeout = 5
self.recipient = recipient
self.msg = msg
self.add_event_handler('session_start', self.start)
def start(self, event):
self.send_presence()
self.get_roster()
if self.recipient:
self.send_message(mto=self.recipient, mbody=self.msg)
self.disconnect()
......@@ -9,7 +9,8 @@ setup(
author="Autistici/Inventati",
author_email="info@autistici.org",
url="https://git.autistici.org/ai3/diagnostics",
install_requires=["cheroot", "Flask", "Mechanicalsoup", "prometheus_client"],
install_requires=["cheroot", "Flask", "Mechanicalsoup", "sleekxmpp",
"prometheus_client"],
packages=find_packages(),
package_data={
"ai_diagnostics": [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment