Skip to content

Commit 5b551f3

Browse files
authored
Merge pull request #2358 from wagner-intevation/bot-library
IEP007 implementation: Library mode
2 parents ded0adf + 7c1baed commit 5b551f3

File tree

13 files changed

+510
-79
lines changed

13 files changed

+510
-79
lines changed

.github/workflows/unittests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
name: "Unit tests"
77
on:
88
push:
9-
branches: [develop, maintenance, master]
109
pull_request:
1110
branches: [develop, maintenance]
1211
paths-ignore:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CHANGELOG
2020
- `intelmq.lib.harmonization`:
2121
- Changes signature and names of `DateTime` conversion functions for consistency, backwards compatible (PR#2329 by Filip Pokorný).
2222
- Ensure rejecting URLs with leading whitespaces after changes in CPython (fixes [#2377](https://github.com/certtools/intelmq/issues/2377))
23+
- `intelmq.lib.bot.Bot`: Allow setting the parameters via parameter on bot initialization.
2324

2425
### Development
2526
- CI: pin the Codespell version to omit troubles caused by its new releases (PR #2379).

debian/control

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Build-Depends: debhelper (>= 4.1.16),
2222
python3-tz,
2323
quilt,
2424
rsync,
25-
safe-rm
25+
safe-rm,
26+
python3-pytest-cov
2627
X-Python3-Version: >= 3.7
2728
Standards-Version: 3.9.6
2829
Homepage: https://github.com/certtools/intelmq/

docs/dev/library.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
..
2+
SPDX-FileCopyrightText: 2023 Bundesamt für Sicherheit in der Informationstechnik (BSI)
3+
SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
##########################
6+
Running IntelMQ as Library
7+
##########################
8+
9+
.. contents::
10+
11+
************
12+
Introduction
13+
************
14+
15+
The feature is specified in `IEP007 <https://github.com/certtools/ieps/tree/iep-007/007/>`_.
16+
17+
**********
18+
Quickstart
19+
**********
20+
21+
First, import the Python module and a helper. More about the ``BotLibSettings`` later.
22+
23+
.. code-block:: python
24+
25+
from intelmq.lib.bot import BotLibSettings
26+
from intelmq.bots.experts.domain_suffix.expert import DomainSuffixExpertBot
27+
28+
Then we need to initialize the bot's instance.
29+
We pass two parameters:
30+
* ``bot_id``: The id of the bot
31+
* ``settings``: A Python dictionary of runtime configuration parameters, see :ref:`runtime-configuration`.
32+
The bot first loads the runtime configuration file if it exists.
33+
Then we update them with the ``BotLibSettings`` which are some accumulated settings disabling the logging to files and configure the pipeline so that we can send and receive messages directly to/from the bot.
34+
Last by not least, the actual bot parameters, taking the highest priority.
35+
36+
.. code-block:: python
37+
38+
domain_suffix = DomainSuffixExpertBot('domain-suffix', # bot id
39+
settings=BotLibSettings | {
40+
'field': 'fqdn',
41+
'suffix_file': '/usr/share/publicsuffix/public_suffix_list.dat'}
42+
43+
As the bot is not fully initialized, we can process messages now.
44+
Inserting a message as dictionary:
45+
46+
.. code-block:: python
47+
48+
queues = domain_suffix.process_message({'source.fqdn': 'www.example.com'})
49+
50+
The return value is a dictionary of queues, e.g. the output queue and the error queue.
51+
More details below.
52+
53+
The methods accepts multiple messages as positional argument:
54+
55+
.. code-block:: python
56+
57+
domain_suffix.process_message({'source.fqdn': 'www.example.com'}, {'source.fqdn': 'www.example.net'})
58+
domain_suffix.process_message(*[{'source.fqdn': 'www.example.com'}, {'source.fqdn': 'www.example.net'}])
59+
60+
61+
Select the output queue (as defined in `destination_queues`), first message, access the field 'source.domain_suffix':
62+
63+
.. code-block:: python
64+
65+
>>> output['output'][0]['source.domain_suffix']
66+
'com'
67+
68+
*************
69+
Configuration
70+
*************
71+
72+
Configuration files are not required to run IntelMQ as library.
73+
Contrary to IntelMQ normal behavior, if the files ``runtime.yaml`` and ``harmonization.conf`` do not exist, IntelMQ won't raise any errors.
74+
For the harmonization configuration, internal defaults are loaded.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Getting involved
7474
:maxdepth: 1
7575

7676
dev/guide
77+
dev/library
7778
dev/data-format
7879
dev/harmonization-fields
7980
dev/release-procedure

0 commit comments

Comments
 (0)