diff --git a/CHANGELOG.md b/CHANGELOG.md index 35d1370c70..ec164d0d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Please refer to the [NEWS](NEWS.md) for a list of changes which have an affect o ### Tests ### Tools +- `intelmq.lib.bot_debugger`: Optionally read input messages from stdin instead of parameter value (PR#2678 by Sebastian Wager). ### Contrib diff --git a/docs/admin/management/intelmq.md b/docs/admin/management/intelmq.md index 43837d6745..162debeeb3 100644 --- a/docs/admin/management/intelmq.md +++ b/docs/admin/management/intelmq.md @@ -349,9 +349,20 @@ file-output: * Message from cli will be used when processing. ... ``` +You can also read the message from stdin (one line): + +```bash +> intelmqctl run file-output process -m - +... +Reading message from stdin (one line): +{"source.ip":"10.2.3.4"} +file-output: * Message from cli will be used when processing. +... +``` + If you wish to display the processed message as well, you the **--show-sent|-s** flag. Then, if sent through (either with -`--dryrun` or without), the message gets displayed as well. +`--dryrun` or without), the resulting message gets displayed as well. ### disable diff --git a/intelmq/bin/intelmqctl.py b/intelmq/bin/intelmqctl.py index 75cbafc720..234d848774 100644 --- a/intelmq/bin/intelmqctl.py +++ b/intelmq/bin/intelmqctl.py @@ -143,7 +143,7 @@ def __init__(self, interactive: bool = False, returntype: ReturnType = ReturnTyp intelmqctl list [bots|queues|queues-and-status] intelmqctl log bot-id [number-of-lines [log-level]] intelmqctl run bot-id message [get|pop|send] - intelmqctl run bot-id process [--msg|--dryrun] + intelmqctl run bot-id process [--msg|--dryrun|--show-sent] intelmqctl run bot-id console intelmqctl clear queue-id intelmqctl check @@ -280,8 +280,8 @@ def __init__(self, interactive: bool = False, returntype: ReturnType = ReturnTyp help='Never really pop the message from the input pipeline ' 'nor send to output pipeline.') parser_run_process.add_argument('--msg', '-m', - help='Trick the bot to process this JSON ' - 'instead of the Message in its pipeline.') + help='Trick the bot to process this JSON message from the parameter ' + "instead of the Message in its pipeline. Read from stdin (one line) with '-'.") parser_run_process.set_defaults(run_subcommand="process") parser_run.set_defaults(func=self.bot_run) diff --git a/intelmq/lib/bot_debugger.py b/intelmq/lib/bot_debugger.py index 03ed8c9cd9..308ab4db5d 100644 --- a/intelmq/lib/bot_debugger.py +++ b/intelmq/lib/bot_debugger.py @@ -173,6 +173,10 @@ def outputappend(self, msg): def arg2msg(self, msg): default_type = "Report" if (self.runtime_configuration.get("group", None) == "Parser" or isinstance(self.instance, ParserBot)) else "Event" + if msg == '-': + print('Reading message from stdin (one line):') + msg = input() + try: msg = MessageFactory.unserialize(msg, default_type=default_type) except (Exception, KeyError, TypeError, ValueError) as exc: