2013-04-13 20:33:06 +00:00
|
|
|
"""
|
|
|
|
This plugin retrieves the uptime of a server.
|
|
|
|
|
|
|
|
Command
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/uptime
|
|
|
|
**Usage:** ``/uptime <jid>``
|
|
|
|
|
|
|
|
Retrieve the uptime of the server of ``jid``.
|
|
|
|
"""
|
2012-02-24 01:14:54 +00:00
|
|
|
from plugin import BasePlugin
|
2013-03-08 21:53:35 +00:00
|
|
|
from common import parse_secs_to_str, safeJID
|
2014-07-24 00:07:08 +00:00
|
|
|
from slixmpp.xmlstream import ET
|
2012-02-24 01:14:54 +00:00
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_command('uptime', self.command_uptime,
|
2013-03-01 18:25:31 +00:00
|
|
|
usage='<jid>',
|
|
|
|
help='Ask for the uptime of a server or component (see XEP-0012).',
|
|
|
|
short='Get the uptime')
|
2012-02-24 01:14:54 +00:00
|
|
|
|
|
|
|
def command_uptime(self, arg):
|
|
|
|
def callback(iq):
|
|
|
|
for query in iq.xml.getiterator('{jabber:iq:last}query'):
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.information('Server %s online since %s' % (iq['from'], parse_secs_to_str(int(query.attrib['seconds']))), 'Info')
|
2012-02-24 01:14:54 +00:00
|
|
|
return
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.information('Could not retrieve uptime', 'Error')
|
|
|
|
jid = safeJID(arg)
|
2012-02-24 01:14:54 +00:00
|
|
|
if not jid.server:
|
|
|
|
return
|
2015-02-18 21:33:17 +00:00
|
|
|
iq = self.core.xmpp.make_iq_get(ito=jid.server)
|
2012-02-24 01:14:54 +00:00
|
|
|
iq.append(ET.Element('{jabber:iq:last}query'))
|
2014-08-01 13:01:25 +00:00
|
|
|
iq.send(callback=callback)
|