Skip to content
Permalink
Browse files

ENH: ctl: add new debug command

  • Loading branch information
wagner-certat committed Mar 16, 2020
1 parent 677be05 commit 3f06a543dc6d4f51013f8e2225664132f468fdda
Showing with 54 additions and 3 deletions.
  1. +3 −0 CHANGELOG.md
  2. +1 −1 contrib/bash-completion/intelmqctl
  3. +50 −2 intelmq/bin/intelmqctl.py
@@ -64,6 +64,9 @@ CHANGELOG
- `intelmqctl`:
- `upgrade-config`: Allow setting the state file location with the `--state-file` parameter.
- Only require `psutil` for the `IntelMQProcessManager`, not for process manager independent calls like `upgrade-config` or `check`.
- Add new command `debug` to ouput some information for debugging. Currently implemented:
- paths
- environment variables
- `intelmqsetup`: Add argument parsing and an option to skip setting file ownership, possibly not requiring root permissions.
- `intelmq_generate_misp_objects_templates.py`: Tool to create a MISP object template (#1470).

@@ -18,7 +18,7 @@ _intelmqctl ()
#echo "posice: $COMP_CWORD $COMP_WORDS";
case $COMP_CWORD in
1)
opts="start stop restart reload run status log clear list check enable disable upgrade-config";
opts="start stop restart reload run status log clear list check enable disable upgrade-config debug";
COMPREPLY=($(compgen -W "${opts} ${generic_pre} ${generic_post}" -- ${cur}));
return 0
;;
@@ -27,7 +27,8 @@
from intelmq import (BOTS_FILE, DEFAULT_LOGGING_LEVEL, DEFAULTS_CONF_FILE,
HARMONIZATION_CONF_FILE, PIPELINE_CONF_FILE,
RUNTIME_CONF_FILE, VAR_RUN_PATH, STATE_FILE_PATH,
DEFAULT_LOGGING_PATH, __version_info__)
DEFAULT_LOGGING_PATH, __version_info__,
CONFIG_DIR, ROOT_DIR)
from intelmq.lib import utils
from intelmq.lib.bot_debugger import BotDebugger
from intelmq.lib.exceptions import MissingDependencyError
@@ -711,6 +712,7 @@ def __init__(self, interactive: bool = False, return_type: str = "python", quiet
intelmqctl clear queue-id
intelmqctl check
intelmqctl upgrade-config
intelmqctl debug
Starting a bot:
intelmqctl start bot-id
@@ -763,7 +765,12 @@ def __init__(self, interactive: bool = False, return_type: str = "python", quiet
Upgrade from a previous version:
intelmqctl upgrade-config
Make a backup of your configuration first, also including bot's configuration files.'''
Make a backup of your configuration first, also including bot's configuration files.
Get some debugging output on the settings and the enviroment (to be extended):
intelmqctl debug --get-paths
intelmqctl debug --get-environment-variables
'''

# stolen functions from the bot file
# this will not work with various instances of REDIS
@@ -940,6 +947,16 @@ def __init__(self, interactive: bool = False, return_type: str = "python", quiet
default=STATE_FILE_PATH)
parser_upgrade_conf.set_defaults(func=self.upgrade_conf)

parser_debug = subparsers.add_parser('debug', help='Get debugging output.')
parser_debug.add_argument('--get-paths', help='Give all paths',
action='append_const', dest='sections',
const='paths')
parser_debug.add_argument('--get-environment-variables',
help='Give environment variables',
action='append_const', dest='sections',
const='environment_variables')
parser_debug.set_defaults(func=self.debug)

self.parser = parser

def load_defaults_configuration(self, silent=False):
@@ -1761,6 +1778,37 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
else:
return 0, 'success'

def debug(self, sections=None):
"""
Give debugging output
get_paths:
print path information
"""

output = {}
if sections is None or 'paths' in sections:
output['paths'] = []
variables = globals()
if RETURN_TYPE == 'text':
print('Paths:')
for path in ('BOTS_FILE', 'DEFAULTS_CONF_FILE',
'HARMONIZATION_CONF_FILE', 'PIPELINE_CONF_FILE',
'RUNTIME_CONF_FILE', 'VAR_RUN_PATH', 'STATE_FILE_PATH',
'DEFAULT_LOGGING_PATH', '__file__',
'CONFIG_DIR', 'ROOT_DIR'):
output['paths'].append((path, variables[path]))
if RETURN_TYPE == 'text':
print('%s: %r' % output['paths'][-1])
if sections is None or 'environment_variables' in sections:
output['environment_variables'] = []
if RETURN_TYPE == 'text':
print('Environment variables:')
for variable in ('INTELMQ_ROOT_DIR', 'INTELMQ_PATHS_NO_OPT',
'INTELMQ_PATHS_OPT', 'INTELMQ_MANGER_CONTROLLER_CMD'):
output['environment_variables'].append((variable, os.getenv(variable)))
if RETURN_TYPE == 'text':
print('%s: %r' % output['environment_variables'][-1])
return 0, output

def main(): # pragma: no cover
x = IntelMQController(interactive=True)

0 comments on commit 3f06a54

Please sign in to comment.
You can’t perform that action at this time.