Skip to content

Commit 701d75f

Browse files
007: more detailed specification
1 parent fda8081 commit 701d75f

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

007/README.md

+39-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,43 @@ Maybe as another IEP?
4040

4141
## Specification
4242

43+
Only changes in the `intelmq.lib.bot.Bot` class are needed.
44+
No changes in the bots' code are required.
45+
46+
### Bot constructor
47+
48+
The operator constructs the bot by initializing the bot's class.
49+
Global and bot configuration parameters are provided as paramter to the constructor in the same format as IntelMQ runtime configuration.
50+
51+
```python
52+
class Bot:
53+
def __init__(bot_id: str,
54+
*args, **kwargs, # any other paramters left out for clarity
55+
settings: Optional[dict] = None)
56+
```
57+
The constructor applies all values of the `settings` parameter after reading the runtime configuration file.
58+
59+
### Method call
60+
61+
The `intelmq.lib.bot.Bot` class gets a new method `process_message`.
62+
The definition:
63+
```python
64+
class Bot:
65+
def process_message(message: Optional[intelmq.lib.message.Message] = None):
66+
```
67+
For collectors:
68+
It takes *no* messages as input and returns a list of messages.
69+
For parsers, experts and outputs:
70+
It takes exactly one message as input and returns a list of messages.
71+
The messages are neither serialized nor encoded in any form, but are objects
72+
of the `intelmq.lib.message.Message` class. If the message is of instance a dict
73+
(with or without `__type` item), it will be automatically converted to the appropriate
74+
Message object (`Report` or `Event`, depending on the Bot type).
75+
76+
Return value is a list of messages sent by the bot.
77+
No exceptions of the bot are caught, the caller should handle them according to their needs.
78+
The bot does not dump any messages to files on errors, irrelevant of the bot's dumping configuration.
79+
4380
## Examples
4481

4582
### A
@@ -49,15 +86,14 @@ EXAMPLE_REPORT = {"feed.url": "http://www.example.com/",
4986
"raw": utils.base64_encode(RAW),
5087
"__type": "Report",
5188
"feed.name": "Example"}
52-
input_message = MessageFactory.from_dict(EXAMPLE_REPORT)
5389

5490
bot = test_parser_bot.DummyParserBot('dummy-bot', settings={'global': {'logging_path': None,
5591
'source_pipeline_broker': 'Pythonlistsimple',
5692
'destination_pipeline_broker': 'Pythonlistsimple'},
5793
'dummy-bot': {'parameters': {'destination_queues': {'_default': 'output',
5894
'_on_error': 'error'}}}})
5995

60-
sent_messages = bot.process_call(input_message)
96+
sent_messages = bot.process_message(EXAMPLE_REPORT)
6197
# sent_messages is now a dict with all queues. queue names below are examples
6298

6399
# this is the output queue
@@ -75,7 +111,6 @@ EXAMPLE_REPORT = {"feed.url": "http://www.example.com/",
75111
"raw": utils.base64_encode(RAW),
76112
"__type": "Report",
77113
"feed.name": "Example"}
78-
input_message = MessageFactory.from_dict(EXAMPLE_REPORT)
79114

80115
bot = test_parser_bot.DummyParserBot('dummy-bot', settings={'global': {'logging_path': None,
81116
'source_pipeline_broker': 'Pythonlistsimple',
@@ -85,7 +120,7 @@ bot = test_parser_bot.DummyParserBot('dummy-bot', settings={'global': {'logging_
85120

86121
try:
87122
# bot.process_call being a generator
88-
sent_messages = list(bot.process_call(input_message))
123+
sent_messages = list(bot.process_message(EXAMPLE_REPORT))
89124
# sent_messages is now a list of sent messages
90125
except IntelMQException as exc:
91126
sys.exit('Processing exception')

0 commit comments

Comments
 (0)