diff options
Diffstat (limited to 'pykolab/cli/telemetry')
-rw-r--r-- | pykolab/cli/telemetry/__init__.py | 0 | ||||
-rw-r--r-- | pykolab/cli/telemetry/cmd_examine_command_issue.py | 126 | ||||
-rw-r--r-- | pykolab/cli/telemetry/cmd_examine_session.py | 144 | ||||
-rw-r--r-- | pykolab/cli/telemetry/cmd_expire_sessions.py | 39 | ||||
-rw-r--r-- | pykolab/cli/telemetry/cmd_list_sessions.py | 66 |
5 files changed, 375 insertions, 0 deletions
diff --git a/pykolab/cli/telemetry/__init__.py b/pykolab/cli/telemetry/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pykolab/cli/telemetry/__init__.py diff --git a/pykolab/cli/telemetry/cmd_examine_command_issue.py b/pykolab/cli/telemetry/cmd_examine_command_issue.py new file mode 100644 index 0000000..cceb5fe --- /dev/null +++ b/pykolab/cli/telemetry/cmd_examine_command_issue.py @@ -0,0 +1,126 @@ + +# -*- coding: utf-8 -*- +# Copyright 2010-2011 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 or, at your option, any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import pykolab + +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +auth = pykolab.auth +imap = pykolab.imap + +from pykolab import telemetry +from pykolab.cli import commands + +def __init__(): + commands.register('examine_command_issue', execute, group='telemetry', description="Examine a particular telemetry command issue.") + +def execute(*args, **kw): + db = telemetry.init_db() + + try: + wanted = conf.cli_args.pop(0) + except: + log.error(_("Unspecified command issue identifier")) + sys.exit(1) + + command_issue = db.query( + telemetry.TelemetryCommandIssue + ).filter_by( + id=wanted + ).first() + + if command_issue == None: + log.error(_("Invalid command issue identifier")) + sys.exit(1) + + session = db.query( + telemetry.TelemetrySession + ).filter_by( + id=command_issue.session_id + ).first() + + if session == None: + log.error(_("Invalid session identifier")) + sys.exit(1) + + user = db.query( + telemetry.TelemetryUser + ).filter_by( + id=session.user_id + ).first() + + server = db.query( + telemetry.TelemetryServer + ).filter_by( + id=session.server_id + ).first() + + print _("Session by %s on server %s") %(user.sasl_username,server.fqdn) + + command_issues = db.query( + telemetry.TelemetryCommandIssue + ).filter_by( + session_id=session.id + ) + + for _command_issue in command_issues: + command = db.query( + telemetry.TelemetryCommand + ).filter_by( + id=_command_issue.command_id + ).first() + + command_arg = db.query( + telemetry.TelemetryCommandArg + ).filter_by( + id=_command_issue.command_arg_id + ).first() + + if command_issue.id == _command_issue.id: + print "=========" + + print "Client(%d): %s %s %s" %( + _command_issue.id, + _command_issue.command_tag, + command.command, + command_arg.command_arg + ) + + server_responses = db.query( + telemetry.TelemetryServerResponse + ).filter_by( + command_issue_id=_command_issue.id + ) + + for server_response in server_responses: + server_response_lines = server_response.response.split('\n'); + + for server_response_line in server_response_lines: + print "Server(%d): %s" %( + server_response.id, + server_response_line + ) + + if command_issue.id == _command_issue.id: + print "=========" + diff --git a/pykolab/cli/telemetry/cmd_examine_session.py b/pykolab/cli/telemetry/cmd_examine_session.py new file mode 100644 index 0000000..f36c0a9 --- /dev/null +++ b/pykolab/cli/telemetry/cmd_examine_session.py @@ -0,0 +1,144 @@ + +# -*- coding: utf-8 -*- +# Copyright 2010-2011 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 or, at your option, any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import pykolab + +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +auth = pykolab.auth +imap = pykolab.imap + +from pykolab import telemetry +from pykolab.cli import commands + +def __init__(): + commands.register('examine_session', execute, group='telemetry', description="Examine a Telemetry session.") + +def execute(*args, **kw): + db = telemetry.init_db() + + wanted = False + + if session_id == None: + try: + wanted = conf.cli_args.pop(0) + except: + log.error(_("Unspecified session identifier")) + sys.exit(1) + + if not wanted: + wanted = session_id + + session_wanted = None + + try: + _wanted = (int)(wanted) + session_wanted = _wanted + except: + user_wanted = wanted + + if not session_wanted == None: + session = db.query( + telemetry.TelemetrySession + ).filter_by( + id=session_wanted + ).first() + + if session == None: + log.error(_("Invalid session identifier")) + sys.exit(1) + + user = db.query( + telemetry.TelemetryUser + ).filter_by( + id=session.user_id + ).first() + + server = db.query( + telemetry.TelemetryServer + ).filter_by( + id=session.server_id + ).first() + + else: + user = db.query( + telemetry.TelemetryUser + ).filter_by( + sasl_username=user_wanted + ).first() + + sessions = db.query( + telemetry.TelemetrySession + ).filter_by( + user_id=user.id + ).order_by( + telemetry.telemetry_session_table.c.start + ) + + for session in sessions: + self.action_telemetry_examine_session(session_id=session.id) + + return + + print _("Session by %s on server %s") %(user.sasl_username,server.fqdn) + + command_issues = db.query( + telemetry.TelemetryCommandIssue + ).filter_by( + session_id=session.id + ) + + for command_issue in command_issues: + command = db.query( + telemetry.TelemetryCommand + ).filter_by( + id=command_issue.command_id + ).first() + + command_arg = db.query( + telemetry.TelemetryCommandArg + ).filter_by( + id=command_issue.command_arg_id + ).first() + + print "Client(%d): %s %s %s" %( + command_issue.id, + command_issue.command_tag, + command.command, + command_arg.command_arg + ) + + server_responses = db.query( + telemetry.TelemetryServerResponse + ).filter_by( + command_issue_id=command_issue.id + ) + + for server_response in server_responses: + server_response_lines = server_response.response.split('\n'); + for server_response_line in server_response_lines: + print "Server(%d): %s" %( + server_response.id, + server_response_line + ) + diff --git a/pykolab/cli/telemetry/cmd_expire_sessions.py b/pykolab/cli/telemetry/cmd_expire_sessions.py new file mode 100644 index 0000000..2da1d3f --- /dev/null +++ b/pykolab/cli/telemetry/cmd_expire_sessions.py @@ -0,0 +1,39 @@ + +# -*- coding: utf-8 -*- +# Copyright 2010-2011 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 or, at your option, any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import pykolab + +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +auth = pykolab.auth +imap = pykolab.imap + +from pykolab import telemetry +from pykolab.cli import commands + +def __init__(): + commands.register('expire_sessions', execute, group='telemetry', description="Expire Telemetry sessions.") + +def execute(*args, **kw): + telemetry.expire_sessions() + diff --git a/pykolab/cli/telemetry/cmd_list_sessions.py b/pykolab/cli/telemetry/cmd_list_sessions.py new file mode 100644 index 0000000..d2c5293 --- /dev/null +++ b/pykolab/cli/telemetry/cmd_list_sessions.py @@ -0,0 +1,66 @@ + +# -*- coding: utf-8 -*- +# Copyright 2010-2011 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 or, at your option, any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import pykolab + +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +auth = pykolab.auth +imap = pykolab.imap + +from pykolab import telemetry +from pykolab.cli import commands + +def __init__(): + commands.register('list_sessions', execute, group='telemetry', description="List IMAP sessions using Telemetry.") + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("List Options")) + my_option_group.add_option( '--since', + dest = "since", + action = "store", + default = 0, + help = _("Display sessions since ...")) + +def execute(*args, **kw): + db = telemetry.init_db() + + sessions = db.query( + telemetry.TelemetrySession + ).order_by( + telemetry.telemetry_session_table.c.start + ) + + for session in sessions: + user = db.query( + telemetry.TelemetryUser + ).filter_by( + id=session.user_id + ).first() + + print _("Session for user %s started at %s with ID %s") %( + user.sasl_username, + session.start, + session.id + ) + |