-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into shadowserver-dynamic-config
- Loading branch information
Showing
21 changed files
with
250 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
*.profile | ||
.vscode/ | ||
.profile | ||
intelmq.egg-info | ||
*.egg-info | ||
build | ||
dist | ||
*.old | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions
24
contrib/example-extension-package/mybots/bots/collectors/custom/collector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
SPDX-FileCopyrightText: 2023 CERT.at GmbH <https://cert.at/> | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
""" | ||
|
||
# Use your package as usual | ||
from mybots.lib import common | ||
|
||
from intelmq.lib.bot import CollectorBot | ||
|
||
|
||
class ExampleAdditionalCollectorBot(CollectorBot): | ||
""" | ||
This is an example bot provided by an extension package | ||
""" | ||
|
||
def process(self): | ||
report = self.new_report() | ||
if self.raw: # noqa: Set as parameter | ||
report['raw'] = common.return_value('example') | ||
self.send_message(report) | ||
|
||
|
||
BOT = ExampleAdditionalCollectorBot |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
SPDX-FileCopyrightText: 2023 CERT.at GmbH <https://cert.at/> | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
""" | ||
|
||
|
||
def return_value(value): | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Example IntelMQ extension package | ||
SPDX-FileCopyrightText: 2023 CERT.at GmbH <https://cert.at/> | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
""" | ||
|
||
from pathlib import Path | ||
from setuptools import find_packages, setup | ||
|
||
|
||
# Instead of the bot-autodiscovery below, you can also just manually declare entrypoints | ||
# (regardless of packaging solution, even in pyproject.toml etc.), e.g.: | ||
# | ||
# 'intelmq.bots.collectors.custom.collector = mybots.bots.collectors.custom.collector:BOT.run' | ||
# | ||
# Important is: | ||
# - entry point has to start with `intelmq.bots.{type}` (type: collectors, experts, parsers, outputs) | ||
# - target has to end with `:BOT.run` | ||
# - entry points have to be in `console_scripts` group | ||
|
||
|
||
BOTS = [] | ||
|
||
base_path = Path(__file__).parent / 'mybots/bots' | ||
botfiles = [botfile for botfile in Path(base_path).glob('**/*.py') if botfile.is_file() and not botfile.name.startswith('_')] | ||
for file in botfiles: | ||
file = Path(str(file).replace(str(base_path), 'intelmq/bots')) | ||
entry_point = '.'.join(file.with_suffix('').parts) | ||
file = Path(str(file).replace('intelmq/bots', 'mybots/bots')) | ||
module = '.'.join(file.with_suffix('').parts) | ||
BOTS.append('{0} = {1}:BOT.run'.format(entry_point, module)) | ||
|
||
setup( | ||
name='intelmq-example-extension', | ||
version='1.0.0', # noqa: F821 | ||
maintainer='Your Name', | ||
maintainer_email='[email protected]', | ||
packages=find_packages(), | ||
license='AGPLv3', | ||
description='This is an example package to demonstrate how ones can extend IntelMQ.', | ||
entry_points={ | ||
'console_scripts': BOTS | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- comment | ||
SPDX-FileCopyrightText: 2023 CERT.at GmbH | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
# Creating extensions packages | ||
|
||
IntelMQ supports adding additional bots using your own independent packages. You can use this to | ||
add a new integration that is special to you, or cannot be integrated | ||
into the main IntelMQ repository for some reason. | ||
|
||
## Building an extension package | ||
|
||
A simple example of the package can be found in ``contrib/example-extension-package``. To make your custom | ||
bots work with IntelMQ, you need to ensure that | ||
|
||
- your bot's module exposes a ``BOT`` object of the class inherited from ``intelmq.lib.bot.Bot`` | ||
or its subclasses, | ||
- your package registers an [entry point](https://packaging.python.org/en/latest/specifications/entry-points/) | ||
in the ``console_scripts`` group with a name starting with ``intelmq.bots.`` followed by | ||
the name of the group (collectors, experts, outputs, parsers), and then your original name. | ||
The entry point must point to the ``BOT.run`` method, | ||
- the module in which the bot resides must be importable by IntelMQ (e.g. installed in the same | ||
virtualenv, if you use them). | ||
|
||
Apart from these requirements, your package can use any of the usual package features. We strongly | ||
recommend following the same principles and main guidelines as the official bots. This will ensure | ||
the same experience when using official and additional bots. | ||
|
||
## Naming convention | ||
|
||
Building your own extensions gives you a lot of freedom, but it's important to know that if your | ||
bot's entry point uses the same name as another bot, it may not be possible to use it, or to | ||
determine which one is being used. For this reason, we recommend that you start the name of your | ||
bot with an with an organization identifier and then the bot name. | ||
|
||
For example, if I create a collector bot for feed source ``Special`` and run it on behalf of the | ||
organization ``Awesome``, the suggested entry point might be ``intelmq.bots.collectors.awesome.special``. | ||
Note that the structure of your package doesn't matter, as long as it can be imported properly. | ||
|
||
For example, I could create a package called ``awesome-bots`` with the following file structure | ||
|
||
```text | ||
awesome_bots | ||
├── pyproject.toml | ||
└── awesome_bots | ||
├── __init__.py | ||
└── special.py | ||
``` | ||
|
||
The [pyproject.toml](https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#entry-points) | ||
file would then have the following section: | ||
|
||
```ini | ||
[project.scripts] | ||
intelmq.bots.collectors.awesome.special = "awesome_bots.special:BOT.run" | ||
``` | ||
|
||
Once you have installed your package, you can run ``intelmqctl list bots`` to check if your bot was | ||
properly registered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.