@@ -40,6 +40,43 @@ Maybe as another IEP?
40
40
41
41
## Specification
42
42
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
+
43
80
## Examples
44
81
45
82
### A
@@ -49,15 +86,14 @@ EXAMPLE_REPORT = {"feed.url": "http://www.example.com/",
49
86
" raw" : utils.base64_encode(RAW ),
50
87
" __type" : " Report" ,
51
88
" feed.name" : " Example" }
52
- input_message = MessageFactory.from_dict(EXAMPLE_REPORT )
53
89
54
90
bot = test_parser_bot.DummyParserBot(' dummy-bot' , settings = {' global' : {' logging_path' : None ,
55
91
' source_pipeline_broker' : ' Pythonlistsimple' ,
56
92
' destination_pipeline_broker' : ' Pythonlistsimple' },
57
93
' dummy-bot' : {' parameters' : {' destination_queues' : {' _default' : ' output' ,
58
94
' _on_error' : ' error' }}}})
59
95
60
- sent_messages = bot.process_call(input_message )
96
+ sent_messages = bot.process_message( EXAMPLE_REPORT )
61
97
# sent_messages is now a dict with all queues. queue names below are examples
62
98
63
99
# this is the output queue
@@ -75,7 +111,6 @@ EXAMPLE_REPORT = {"feed.url": "http://www.example.com/",
75
111
" raw" : utils.base64_encode(RAW ),
76
112
" __type" : " Report" ,
77
113
" feed.name" : " Example" }
78
- input_message = MessageFactory.from_dict(EXAMPLE_REPORT )
79
114
80
115
bot = test_parser_bot.DummyParserBot(' dummy-bot' , settings = {' global' : {' logging_path' : None ,
81
116
' source_pipeline_broker' : ' Pythonlistsimple' ,
@@ -85,7 +120,7 @@ bot = test_parser_bot.DummyParserBot('dummy-bot', settings={'global': {'logging_
85
120
86
121
try :
87
122
# bot.process_call being a generator
88
- sent_messages = list (bot.process_call(input_message ))
123
+ sent_messages = list (bot.process_message( EXAMPLE_REPORT ))
89
124
# sent_messages is now a list of sent messages
90
125
except IntelMQException as exc:
91
126
sys.exit(' Processing exception' )
0 commit comments